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 class
JDBCQueryExpression.Join
-
Field Summary
Fields Modifier and Type Field Description protected DbMetaInfo
_dbInfo
MetaInfo as acquired from the RDBMS.protected boolean
_distinct
protected PersistenceFactory
_factory
protected java.util.Vector<JDBCQueryExpression.Join>
_joins
protected java.lang.String
_limit
protected java.lang.String
_offset
protected java.lang.String
_order
protected java.lang.String
_select
protected 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 void
addColumn(java.lang.String tableName, java.lang.String columnName)
Add a column used in the query.void
addCondition(java.lang.String tableName, java.lang.String columnName, java.lang.String condOp, java.lang.String value)
Add a condition.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)
Add an inner join with an aliases for the tables.void
addLimitClause(java.lang.String limit)
Adds an limit clause.void
addOffsetClause(java.lang.String offset)
Adds an offset clause.void
addOrderClause(java.lang.String order)
Adds an order by clause.void
addOuterJoin(java.lang.String leftTable, java.lang.String[] leftColumn, java.lang.String rightTable, java.lang.String[] rightColumn, java.lang.String rightTableAlias)
Add an outer join.void
addParameter(java.lang.String tableName, java.lang.String columnName, java.lang.String condOp)
Add a query paramater.void
addSelect(java.lang.String selectClause)
Add an entire select clause to the query with one call.void
addTable(java.lang.String tableName, java.lang.String tableAlias)
Add a table with an alias to the from clause.void
addWhereClause(java.lang.String where)
Adds a where clause.protected boolean
addWhereClause(java.lang.StringBuffer sql, boolean first)
java.lang.Object
clone()
Returns a clone of the query expression that can be further modified.java.lang.String
encodeColumn(java.lang.String tableName, java.lang.String columnName)
Encode a TableColumn for use in expressions.protected java.lang.String
getColumnList()
protected java.lang.StringBuffer
getStandardStatement(boolean lock, boolean oj)
Helper method.java.lang.String
getStatement(boolean lock)
Creates a SQL statement.boolean
isLimitClauseSupported()
Provides a default implementation ofQueryExpression.isLimitClauseSupported()
.boolean
isOffsetClauseSupported()
Provides a default implementation ofQueryExpression.isOffsetClauseSupported()
.void
setDbMetaInfo(DbMetaInfo dbInfo)
Store database meta information.void
setDistinct(boolean distinct)
Set the query to be distinct.java.lang.String
toString()
-
-
-
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:
setDbMetaInfo
in interfaceQueryExpression
- Parameters:
dbInfo
- DbMetaInfo instance.
-
setDistinct
public final void setDistinct(boolean distinct)
Description copied from interface:QueryExpression
Set the query to be distinct. No two rows which are the same will be returned.- Specified by:
setDistinct
in 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:QueryExpression
Add a column used in the query. Columns must be retrieved in the same order in which they were added to the query.- Specified by:
addColumn
in 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:QueryExpression
Add a table with an alias to the from clause.- Specified by:
addTable
in 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:QueryExpression
Add a query paramater.- Specified by:
addParameter
in 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:QueryExpression
Add a condition.- Specified by:
addCondition
in 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:QueryExpression
Encode a TableColumn for use in expressions.- Specified by:
encodeColumn
in 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:QueryExpression
Add an inner join with an aliases for the tables.- Specified by:
addInnerJoin
in 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:QueryExpression
Add an outer join. May use an inner join if outer joins are not supported.- Specified by:
addOuterJoin
in 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:QueryExpression
Add 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:
addSelect
in 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:QueryExpression
Adds a where clause. Caller is responsible for making sure all tables mentioned in the where clause are included in the fromClause.- Specified by:
addWhereClause
in 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:QueryExpression
Adds 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:
addOrderClause
in interfaceQueryExpression
- Parameters:
order
- The ORDER BY clause to add (without the words ORDER BY).
-
addLimitClause
public final void addLimitClause(java.lang.String limit) throws SyntaxNotSupportedException
Description copied from interface:QueryExpression
Adds an limit clause.- Specified by:
addLimitClause
in 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 SyntaxNotSupportedException
Description copied from interface:QueryExpression
Adds an offset clause.- Specified by:
addOffsetClause
in 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 SyntaxNotSupportedException
Creates 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:
getStatement
in 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:
toString
in classjava.lang.Object
-
clone
public final java.lang.Object clone()
Description copied from interface:QueryExpression
Returns a clone of the query expression that can be further modified.- Specified by:
clone
in interfaceQueryExpression
- Overrides:
clone
in classjava.lang.Object
-
isLimitClauseSupported
public boolean isLimitClauseSupported()
Provides a default implementation ofQueryExpression.isLimitClauseSupported()
.- Specified by:
isLimitClauseSupported
in 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:
isOffsetClauseSupported
in interfaceQueryExpression
- Returns:
- false to indicate that this feature is not supported by default.
- See Also:
QueryExpression.isOffsetClauseSupported()
-
-