org.castor.cpa.persistence.sql.driver
Class JDBCQueryExpression

java.lang.Object
  extended by 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: 8994 $ $Date: 2011-08-02 01:40:59 +0200 (Di, 02 Aug 2011) $
Author:
Assaf Arkin

Nested Class Summary
(package private) static class JDBCQueryExpression.Join
           
 
Field Summary
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
JDBCQueryExpression(PersistenceFactory factory)
           
 
Method Summary
 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 of QueryExpression.isLimitClauseSupported().
 boolean isOffsetClauseSupported()
          Provides a default implementation of QueryExpression.isOffsetClauseSupported().
 void setDbMetaInfo(DbMetaInfo dbInfo)
          Store database meta information.
 void setDistinct(boolean distinct)
          Set the query to be distinct.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

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 interface QueryExpression
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 interface QueryExpression
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 interface QueryExpression
Parameters:
tableName - The table name
columnName - 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 interface QueryExpression
Parameters:
tableName - The name of the table to add to the select clause
tableAlias - 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 interface QueryExpression
Parameters:
tableName - The table name
columnName - The column name
condOp - 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 interface QueryExpression
Parameters:
tableName - The table name
columnName - The column name
condOp - The conditional operation
value - 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 interface QueryExpression
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 interface QueryExpression
Parameters:
leftTable - The table name on the left side
leftColumn - The column names on the left side
leftTableAlias - The alias name to use for the table on the left side
rightTable - The table name on the right side
rightColumn - The column names on the right side
rightTableAlias - 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 interface QueryExpression
Parameters:
leftTable - The table name on the left side
leftColumn - The column name on the left side
rightTable - The table name on the right side
rightColumn - The column name on the right side
rightTableAlias - 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 interface QueryExpression
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 interface QueryExpression
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 interface QueryExpression
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 interface QueryExpression
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 interface QueryExpression
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 a SyntaxNotSupportedException.

Specified by:
getStatement in interface QueryExpression
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 tables
oj - true in the first case above, false in the second case.

toString

public final java.lang.String toString()
Overrides:
toString in class java.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 interface QueryExpression
Overrides:
clone in class java.lang.Object

isLimitClauseSupported

public boolean isLimitClauseSupported()
Provides a default implementation of QueryExpression.isLimitClauseSupported().

Specified by:
isLimitClauseSupported in interface QueryExpression
Returns:
false to indicate that this feature is not supported by default.
See Also:
QueryExpression.isLimitClauseSupported()

isOffsetClauseSupported

public boolean isOffsetClauseSupported()
Provides a default implementation of QueryExpression.isOffsetClauseSupported().

Specified by:
isOffsetClauseSupported in interface QueryExpression
Returns:
false to indicate that this feature is not supported by default.
See Also:
QueryExpression.isOffsetClauseSupported()


Intalio Inc. (C) 1999-2008. All rights reserved http://www.intalio.com