org.exolab.castor.persist.spi
Interface QueryExpression

All Known Implementing Classes:
DB2QueryExpression, DerbyQueryExpression, HsqlQueryExpression, InformixQueryExpression, InstantDBQueryExpression, InterbaseQueryExpression, JDBCQueryExpression, MySQLQueryExpression, OracleQueryExpression, PointbaseQueryExpression, PostgreSQLQueryExpression, ProgressQueryExpression, SapDbQueryExpression, SQLServerQueryExpression, SybaseQueryExpression

public interface QueryExpression

Defines the interface for a query expression. The query expression object is used to construct queries including parameters, conditions and joins, and generates the SQL statement for the underlying database.

A query experession object is created for each unique query, populated with the query parameters and the SQL statement is obtained from it at the proper time.

A query expression is generated from an instance of PersistenceFactory, see this interface for information on how to configure it. The operators defined in this interface are part of SQL 92 and the supported OQL syntax and are expected to be supported by all query expressions.

Version:
$Revision: 8994 $ $Date: 2011-08-02 01:40:59 +0200 (Di, 02 Aug 2011) $
Author:
Assaf Arkin

Field Summary
static java.lang.String OP_BETWEEN
          Between operator.
static java.lang.String OP_BETWEEN_AND
          Between and operator.
static java.lang.String OP_EQUALS
          Equality operator.
static java.lang.String OP_GREATER
          Greater then operator.
static java.lang.String OP_GREATER_EQUALS
          Greater then or equals operator.
static java.lang.String OP_LESS
          Less then operator.
static java.lang.String OP_LESS_EQUALS
          Less then or equals operator.
static java.lang.String OP_LIKE
          Like operator.
static java.lang.String OP_NOT_EQUALS
          Inequality operator.
static java.lang.String OP_NOT_LIKE
          Not like operator.
 
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 limitClause)
          Adds an limit clause.
 void addOffsetClause(java.lang.String offsetClause)
          Adds an offset clause.
 void addOrderClause(java.lang.String orderClause)
          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 whereClause)
          Adds a where clause.
 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.
 java.lang.String getStatement(boolean writeLock)
          Return the query expression as an SQL statement.
 boolean isLimitClauseSupported()
          Indicates whether a RDBMS supports LIMIT clauses.
 boolean isOffsetClauseSupported()
          Indicates whether a RDBMS supports OFFSET clauses.
 void setDbMetaInfo(DbMetaInfo dbInfo)
          Store database meta information.
 void setDistinct(boolean distinct)
          Set the query to be distinct.
 

Field Detail

OP_EQUALS

static final java.lang.String OP_EQUALS
Equality operator. (=)

See Also:
Constant Field Values

OP_NOT_EQUALS

static final java.lang.String OP_NOT_EQUALS
Inequality operator. (<>)

See Also:
Constant Field Values

OP_GREATER

static final java.lang.String OP_GREATER
Greater then operator. (>)

See Also:
Constant Field Values

OP_GREATER_EQUALS

static final java.lang.String OP_GREATER_EQUALS
Greater then or equals operator. (>=)

See Also:
Constant Field Values

OP_LESS

static final java.lang.String OP_LESS
Less then operator. (<)

See Also:
Constant Field Values

OP_LESS_EQUALS

static final java.lang.String OP_LESS_EQUALS
Less then or equals operator. (<=)

See Also:
Constant Field Values

OP_LIKE

static final java.lang.String OP_LIKE
Like operator. (LIKE)

See Also:
Constant Field Values

OP_NOT_LIKE

static final java.lang.String OP_NOT_LIKE
Not like operator. (NOT LIKE)

See Also:
Constant Field Values

OP_BETWEEN

static final java.lang.String OP_BETWEEN
Between operator. (BETWEEN)

See Also:
Constant Field Values

OP_BETWEEN_AND

static final java.lang.String OP_BETWEEN_AND
Between and operator. (AND)

See Also:
Constant Field Values
Method Detail

addColumn

void addColumn(java.lang.String tableName,
               java.lang.String columnName)
Add a column used in the query. Columns must be retrieved in the same order in which they were added to the query.

Parameters:
tableName - The table name
columnName - The column name

addSelect

void addSelect(java.lang.String selectClause)
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.

Parameters:
selectClause - The entire sql select clause without the word SELECT

setDistinct

void setDistinct(boolean distinct)
Set the query to be distinct. No two rows which are the same will be returned.

Parameters:
distinct - If the query should include DISTINCT in the SQL select.

addTable

void addTable(java.lang.String tableName,
              java.lang.String tableAlias)
Add a table with an alias to the from clause.

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

void addParameter(java.lang.String tableName,
                  java.lang.String columnName,
                  java.lang.String condOp)
Add a query paramater.

Parameters:
tableName - The table name
columnName - The column name
condOp - The conditional operation

addCondition

void addCondition(java.lang.String tableName,
                  java.lang.String columnName,
                  java.lang.String condOp,
                  java.lang.String value)
Add a condition.

Parameters:
tableName - The table name
columnName - The column name
condOp - The conditional operation
value - The conditional value

encodeColumn

java.lang.String encodeColumn(java.lang.String tableName,
                              java.lang.String columnName)
Encode a TableColumn for use in expressions.

Parameters:
tableName - The table name.
columnName - The column name.

addWhereClause

void addWhereClause(java.lang.String whereClause)
Adds a where clause. Caller is responsible for making sure all tables mentioned in the where clause are included in the fromClause.

Parameters:
whereClause - The WHERE clause to add (without the word WHERE).

addOrderClause

void addOrderClause(java.lang.String orderClause)
Adds an order by clause. Caller is responsible for making sure all tables mentioned in the order by clause are included in the fromClause.

Parameters:
orderClause - The ORDER BY clause to add (without the words ORDER BY).

addLimitClause

void addLimitClause(java.lang.String limitClause)
                    throws SyntaxNotSupportedException
Adds an limit clause.

Parameters:
limitClause - The LIMIT clause to add (without the word LIMIT).
Throws:
SyntaxNotSupportedException - If the LIMIT clause is not supported by the RDBMS.

addOffsetClause

void addOffsetClause(java.lang.String offsetClause)
                     throws SyntaxNotSupportedException
Adds an offset clause.

Parameters:
offsetClause - The OFFSET clause to add (without the word OFFSET).
Throws:
SyntaxNotSupportedException - If the OFFSET clause is not supported by the RDBMS.

addInnerJoin

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.

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

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. May use an inner join if outer joins are not supported.

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

getStatement

java.lang.String getStatement(boolean writeLock)
                              throws QueryException
Return the query expression as an SQL statement. The resulting SQL is fed directly to a JDBC statement. writeLock is true if the query must obtain a write lock on the queried table.

Parameters:
writeLock - True if a write lock is required
Returns:
The SQL statement
Throws:
QueryException - The query cannot be constructed for this engine

clone

java.lang.Object clone()
Returns a clone of the query expression that can be further modified.


isLimitClauseSupported

boolean isLimitClauseSupported()
Indicates whether a RDBMS supports LIMIT clauses.

Returns:
True if a LIMIT clause is supported.

isOffsetClauseSupported

boolean isOffsetClauseSupported()
Indicates whether a RDBMS supports OFFSET clauses.

Returns:
True if an OFFSET clause is supported.

setDbMetaInfo

void setDbMetaInfo(DbMetaInfo dbInfo)
Store database meta information.

Parameters:
dbInfo - DbMetaInfo instance


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