Class JDBCQueryExpression
- java.lang.Object
-
- org.castor.cpa.persistence.sql.driver.JDBCQueryExpression
-
- All Implemented Interfaces:
QueryExpression
- Direct Known Subclasses:
DB2QueryExpression,DerbyQueryExpression,HsqlQueryExpression,InformixQueryExpression,InstantDBQueryExpression,InterbaseQueryExpression,MySQLQueryExpression,OracleQueryExpression,PointbaseQueryExpression,PostgreSQLQueryExpression,ProgressQueryExpression,SapDbQueryExpression,SQLServerQueryExpression,SybaseQueryExpression
public class JDBCQueryExpression extends java.lang.Object implements QueryExpression
- Version:
- $Revision: 8459 $ $Date: 2006-04-10 16:39:24 -0600 (Mon, 10 Apr 2006) $
- Author:
- Assaf Arkin
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classJDBCQueryExpression.Join
-
Field Summary
Fields Modifier and Type Field Description protected DbMetaInfo_dbInfoMetaInfo as acquired from the RDBMS.protected boolean_distinctprotected PersistenceFactory_factoryprotected java.util.Vector<JDBCQueryExpression.Join>_joinsprotected java.lang.String_limitprotected java.lang.String_offsetprotected java.lang.String_orderprotected java.lang.String_selectprotected java.util.Hashtable<java.lang.String,java.lang.String>_tables-
Fields inherited from interface org.exolab.castor.persist.spi.QueryExpression
OP_BETWEEN, OP_BETWEEN_AND, OP_EQUALS, OP_GREATER, OP_GREATER_EQUALS, OP_LESS, OP_LESS_EQUALS, OP_LIKE, OP_NOT_EQUALS, OP_NOT_LIKE
-
-
Constructor Summary
Constructors Constructor Description JDBCQueryExpression(PersistenceFactory factory)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddColumn(java.lang.String tableName, java.lang.String columnName)Add a column used in the query.voidaddCondition(java.lang.String tableName, java.lang.String columnName, java.lang.String condOp, java.lang.String value)Add a condition.voidaddInnerJoin(java.lang.String leftTable, java.lang.String[] leftColumn, java.lang.String leftTableAlias, java.lang.String rightTable, java.lang.String[] rightColumn, java.lang.String rightTableAlias)Add an inner join with an aliases for the tables.voidaddLimitClause(java.lang.String limit)Adds an limit clause.voidaddOffsetClause(java.lang.String offset)Adds an offset clause.voidaddOrderClause(java.lang.String order)Adds an order by clause.voidaddOuterJoin(java.lang.String leftTable, java.lang.String[] leftColumn, java.lang.String rightTable, java.lang.String[] rightColumn, java.lang.String rightTableAlias)Add an outer join.voidaddParameter(java.lang.String tableName, java.lang.String columnName, java.lang.String condOp)Add a query paramater.voidaddSelect(java.lang.String selectClause)Add an entire select clause to the query with one call.voidaddTable(java.lang.String tableName, java.lang.String tableAlias)Add a table with an alias to the from clause.voidaddWhereClause(java.lang.String where)Adds a where clause.protected booleanaddWhereClause(java.lang.StringBuffer sql, boolean first)java.lang.Objectclone()Returns a clone of the query expression that can be further modified.java.lang.StringencodeColumn(java.lang.String tableName, java.lang.String columnName)Encode a TableColumn for use in expressions.protected java.lang.StringgetColumnList()protected java.lang.StringBuffergetStandardStatement(boolean lock, boolean oj)Helper method.java.lang.StringgetStatement(boolean lock)Creates a SQL statement.booleanisLimitClauseSupported()Provides a default implementation ofQueryExpression.isLimitClauseSupported().booleanisOffsetClauseSupported()Provides a default implementation ofQueryExpression.isOffsetClauseSupported().voidsetDbMetaInfo(DbMetaInfo dbInfo)Store database meta information.voidsetDistinct(boolean distinct)Set the query to be distinct.java.lang.StringtoString()
-
-
-
Field Detail
-
_tables
protected java.util.Hashtable<java.lang.String,java.lang.String> _tables
-
_joins
protected java.util.Vector<JDBCQueryExpression.Join> _joins
-
_select
protected java.lang.String _select
-
_order
protected java.lang.String _order
-
_limit
protected java.lang.String _limit
-
_offset
protected java.lang.String _offset
-
_distinct
protected boolean _distinct
-
_factory
protected PersistenceFactory _factory
-
_dbInfo
protected DbMetaInfo _dbInfo
MetaInfo as acquired from the RDBMS.
-
-
Constructor Detail
-
JDBCQueryExpression
public JDBCQueryExpression(PersistenceFactory factory)
-
-
Method Detail
-
setDbMetaInfo
public final void setDbMetaInfo(DbMetaInfo dbInfo)
Store database meta information.- Specified by:
setDbMetaInfoin interfaceQueryExpression- Parameters:
dbInfo- DbMetaInfo instance.
-
setDistinct
public final void setDistinct(boolean distinct)
Description copied from interface:QueryExpressionSet the query to be distinct. No two rows which are the same will be returned.- Specified by:
setDistinctin interfaceQueryExpression- Parameters:
distinct- If the query should include DISTINCT in the SQL select.
-
addColumn
public final void addColumn(java.lang.String tableName, java.lang.String columnName)Description copied from interface:QueryExpressionAdd a column used in the query. Columns must be retrieved in the same order in which they were added to the query.- Specified by:
addColumnin interfaceQueryExpression- Parameters:
tableName- The table namecolumnName- The column name
-
addTable
public final void addTable(java.lang.String tableName, java.lang.String tableAlias)Description copied from interface:QueryExpressionAdd a table with an alias to the from clause.- Specified by:
addTablein interfaceQueryExpression- Parameters:
tableName- The name of the table to add to the select clausetableAlias- The name of the alias under which the where clauses will access it
-
addParameter
public final void addParameter(java.lang.String tableName, java.lang.String columnName, java.lang.String condOp)Description copied from interface:QueryExpressionAdd a query paramater.- Specified by:
addParameterin interfaceQueryExpression- Parameters:
tableName- The table namecolumnName- The column namecondOp- The conditional operation
-
addCondition
public final void addCondition(java.lang.String tableName, java.lang.String columnName, java.lang.String condOp, java.lang.String value)Description copied from interface:QueryExpressionAdd a condition.- Specified by:
addConditionin interfaceQueryExpression- Parameters:
tableName- The table namecolumnName- The column namecondOp- The conditional operationvalue- The conditional value
-
encodeColumn
public final java.lang.String encodeColumn(java.lang.String tableName, java.lang.String columnName)Description copied from interface:QueryExpressionEncode a TableColumn for use in expressions.- Specified by:
encodeColumnin interfaceQueryExpression- Parameters:
tableName- The table name.columnName- The column name.
-
addInnerJoin
public final void addInnerJoin(java.lang.String leftTable, java.lang.String[] leftColumn, java.lang.String leftTableAlias, java.lang.String rightTable, java.lang.String[] rightColumn, java.lang.String rightTableAlias)Description copied from interface:QueryExpressionAdd an inner join with an aliases for the tables.- Specified by:
addInnerJoinin interfaceQueryExpression- Parameters:
leftTable- The table name on the left sideleftColumn- The column names on the left sideleftTableAlias- The alias name to use for the table on the left siderightTable- The table name on the right siderightColumn- The column names on the right siderightTableAlias- The alias name to use for the table on the right side
-
addOuterJoin
public final void addOuterJoin(java.lang.String leftTable, java.lang.String[] leftColumn, java.lang.String rightTable, java.lang.String[] rightColumn, java.lang.String rightTableAlias)Description copied from interface:QueryExpressionAdd an outer join. May use an inner join if outer joins are not supported.- Specified by:
addOuterJoinin interfaceQueryExpression- Parameters:
leftTable- The table name on the left sideleftColumn- The column name on the left siderightTable- The table name on the right siderightColumn- The column name on the right siderightTableAlias- The alias name to use for the table on the right side
-
addSelect
public final void addSelect(java.lang.String selectClause)
Description copied from interface:QueryExpressionAdd an entire select clause to the query with one call. The caller is responsible for making sure that all mentioned tables are included in the from clause.- Specified by:
addSelectin interfaceQueryExpression- Parameters:
selectClause- The entire sql select clause without the word SELECT
-
addWhereClause
public final void addWhereClause(java.lang.String where)
Description copied from interface:QueryExpressionAdds a where clause. Caller is responsible for making sure all tables mentioned in the where clause are included in the fromClause.- Specified by:
addWhereClausein interfaceQueryExpression- Parameters:
where- The WHERE clause to add (without the word WHERE).
-
addOrderClause
public final void addOrderClause(java.lang.String order)
Description copied from interface:QueryExpressionAdds an order by clause. Caller is responsible for making sure all tables mentioned in the order by clause are included in the fromClause.- Specified by:
addOrderClausein interfaceQueryExpression- Parameters:
order- The ORDER BY clause to add (without the words ORDER BY).
-
addLimitClause
public final void addLimitClause(java.lang.String limit) throws SyntaxNotSupportedExceptionDescription copied from interface:QueryExpressionAdds an limit clause.- Specified by:
addLimitClausein interfaceQueryExpression- Parameters:
limit- The LIMIT clause to add (without the word LIMIT).- Throws:
SyntaxNotSupportedException- If the LIMIT clause is not supported by the RDBMS.
-
addOffsetClause
public final void addOffsetClause(java.lang.String offset) throws SyntaxNotSupportedExceptionDescription copied from interface:QueryExpressionAdds an offset clause.- Specified by:
addOffsetClausein interfaceQueryExpression- Parameters:
offset- The OFFSET clause to add (without the word OFFSET).- Throws:
SyntaxNotSupportedException- If the OFFSET clause is not supported by the RDBMS.
-
getColumnList
protected final java.lang.String getColumnList()
-
addWhereClause
protected final boolean addWhereClause(java.lang.StringBuffer sql, boolean first)
-
getStatement
public java.lang.String getStatement(boolean lock) throws SyntaxNotSupportedExceptionCreates a SQL statement. In general, for a RDBMS/JDBC driver with a full support of the SQL standard/JDBC specification, this will return a valid SQL statement. For some features, a particular RDBMS might indicate that it does not support this feature by throwing aSyntaxNotSupportedException.- Specified by:
getStatementin interfaceQueryExpression- Parameters:
lock- True if a write lock is required- Returns:
- The SQL statement
- Throws:
SyntaxNotSupportedException- If the RDBMS does not support a particular feature.
-
getStandardStatement
protected final java.lang.StringBuffer getStandardStatement(boolean lock, boolean oj)Helper method. Can be used in two cases: 1) for JDBC drivers which support "{oj ...OUTER JOIN ...}" notation (in accordance with JDBC specification); 2) for the databases which support "... OUTER JOIN ..." notation (in accordance with SQL-92 standard); .- Parameters:
lock- whether to lock selected tablesoj- true in the first case above, false in the second case.
-
toString
public final java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
clone
public final java.lang.Object clone()
Description copied from interface:QueryExpressionReturns a clone of the query expression that can be further modified.- Specified by:
clonein interfaceQueryExpression- Overrides:
clonein classjava.lang.Object
-
isLimitClauseSupported
public boolean isLimitClauseSupported()
Provides a default implementation ofQueryExpression.isLimitClauseSupported().- Specified by:
isLimitClauseSupportedin interfaceQueryExpression- Returns:
- false to indicate that this feature is not supported by default.
- See Also:
QueryExpression.isLimitClauseSupported()
-
isOffsetClauseSupported
public boolean isOffsetClauseSupported()
Provides a default implementation ofQueryExpression.isOffsetClauseSupported().- Specified by:
isOffsetClauseSupportedin interfaceQueryExpression- Returns:
- false to indicate that this feature is not supported by default.
- See Also:
QueryExpression.isOffsetClauseSupported()
-
-