org.apache.ojb.broker.accesslayer.sql
Class SqlQueryStatement

java.lang.Object
  extended byorg.apache.ojb.broker.accesslayer.sql.SqlQueryStatement
All Implemented Interfaces:
JoinSyntaxTypes, SqlStatement
Direct Known Subclasses:
SqlDeleteByQuery, SqlSelectStatement

public abstract class SqlQueryStatement
extends java.lang.Object
implements SqlStatement, JoinSyntaxTypes

Model a Statement based on Query.

Version:
$Id: SqlQueryStatement.java,v 1.65 2004/02/21 21:41:45 brj Exp $
Author:
Jakob Braeuchi

Nested Class Summary
(package private) static class SqlQueryStatement.AttributeInfo
          This class is a helper to return TableAlias and PathInfo
(package private)  class SqlQueryStatement.Join
          This class represents join between two TableAliases
(package private) static class SqlQueryStatement.TableAlias
          This class represents one table (possibly with alias) in the SQL query
 
Field Summary
(package private)  Logger m_logger
          the logger
 
Fields inherited from interface org.apache.ojb.broker.accesslayer.JoinSyntaxTypes
ORACLE_JOIN_SYNTAX, SQL92_JOIN_SYNTAX, SQL92_NOPAREN_JOIN_SYNTAX, SYBASE_JOIN_SYNTAX
 
Constructor Summary
SqlQueryStatement(Platform pf, ClassDescriptor cld, Query query, Logger logger)
          Constructor for SqlCriteriaStatement.
SqlQueryStatement(SqlQueryStatement parent, Platform pf, ClassDescriptor cld, Query query, Logger logger)
          Constructor for SqlCriteriaStatement.
 
Method Summary
protected  void appendClause(java.lang.StringBuffer clause, Criteria crit, java.lang.StringBuffer stmt)
          appends a WHERE/HAVING-clause to the Statement
protected  boolean appendColName(SqlQueryStatement.TableAlias aTableAlias, SqlHelper.PathInfo aPathInfo, boolean translate, java.lang.StringBuffer buf)
          Add the Column to the StringBuffer
protected  boolean appendColName(java.lang.String attr, boolean useOuterJoins, java.lang.String aUserAlias, java.lang.StringBuffer buf)
          Append the appropriate ColumnName to the buffer
if a FIELDDESCRIPTOR is found for the Criteria the colName is taken from there otherwise its taken from Criteria.
protected  boolean appendColName(java.lang.String attr, java.lang.String attrAlias, boolean useOuterJoins, java.lang.String aUserAlias, java.lang.StringBuffer buf)
          Append the appropriate ColumnName to the buffer
if a FIELDDESCRIPTOR is found for the Criteria the colName is taken from there otherwise its taken from Criteria.
protected  void appendCriteria(SqlQueryStatement.TableAlias alias, SqlHelper.PathInfo pathInfo, SelectionCriteria c, java.lang.StringBuffer buf)
          Answer the SQL-Clause for a SelectionCriteria
protected  void appendGroupByClause(java.util.List groupByFields, java.lang.StringBuffer buf)
          Appends to the statement the GROUP BY clause for the Query
protected  void appendHavingClause(java.lang.StringBuffer having, Criteria crit, java.lang.StringBuffer stmt)
          appends a HAVING-clause to the Statement
protected  void appendOrderByClause(java.util.List orderByFields, int[] orderByColumnNumbers, java.lang.StringBuffer buf)
          Appends to the statement the ORDER BY clause for the Query
protected  void appendSQLClause(SelectionCriteria c, java.lang.StringBuffer buf)
          Answer the SQL-Clause for a SelectionCriteria If the Criteria references a class with extents an OR-Clause is added for each extent
protected  void appendTableWithJoins(SqlQueryStatement.TableAlias alias, java.lang.StringBuffer where, java.lang.StringBuffer buf)
          Appends to the statement table and all tables joined to it.
protected  void appendWhereClause(java.lang.StringBuffer where, Criteria crit, java.lang.StringBuffer stmt)
          appends a WHERE-clause to the Statement
protected  void buildSuperJoinTree(SqlQueryStatement.TableAlias left, ClassDescriptor cld, java.lang.String name)
          build the Join-Information if a super reference exists
protected  int[] ensureColumns(java.util.List columns, java.util.List existingColumns, java.lang.StringBuffer buf)
          Appends to the statement columns if they are not found among the existingColumns.
protected  SqlQueryStatement.AttributeInfo getAttributeInfo(java.lang.String attr, boolean useOuterJoins, java.lang.String aUserAlias)
          Return the TableAlias and the PathInfo for an Attribute name
field names in functions (ie: sum(name) ) are tried to resolve ie: name from FIELDDESCRIPTOR , UPPER(name_test) from Criteria
also resolve pathExpression adress.city or owner.konti.saldo
protected  ClassDescriptor getBaseClassDescriptor()
           
protected  java.lang.String getColName(SqlQueryStatement.TableAlias aTableAlias, SqlHelper.PathInfo aPathInfo, boolean translate)
          Answer the column name for alias and path info
if translate try to convert attribute name into column name otherwise use attribute name
if a FieldDescriptor is found for the attribute name the column name is taken from there prefixed with the alias (firstname -> A0.F_NAME).
protected  FieldDescriptor getFieldDescriptor(SqlQueryStatement.TableAlias aTableAlias, SqlHelper.PathInfo aPathInfo)
          Get the FieldDescriptor for the PathInfo
protected  byte getJoinSyntaxType()
          Returns the joinSyntaxType.
protected  java.util.HashMap getJoinTreeToCriteria()
          Gets the joinTreeToCriteria.
protected  Logger getLogger()
          Returns the logger.
protected  QueryByCriteria getQuery()
          Gets the query.
protected  SqlQueryStatement.TableAlias getRoot()
          Gets the root.
protected  ClassDescriptor getSearchClassDescriptor()
           
protected  SqlQueryStatement.TableAlias getSearchTable()
          Gets the search table of this query.
protected  void setRoot(SqlQueryStatement.TableAlias root)
          Sets the root.
protected  void splitCriteria()
          First reduce the Criteria to the normal disjunctive form, then calculate the necessary tree of joined tables for each item, then group items with the same tree of joined tables.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.ojb.broker.accesslayer.sql.SqlStatement
getStatement
 

Field Detail

m_logger

Logger m_logger
the logger

Constructor Detail

SqlQueryStatement

public SqlQueryStatement(Platform pf,
                         ClassDescriptor cld,
                         Query query,
                         Logger logger)
Constructor for SqlCriteriaStatement.


SqlQueryStatement

public SqlQueryStatement(SqlQueryStatement parent,
                         Platform pf,
                         ClassDescriptor cld,
                         Query query,
                         Logger logger)
Constructor for SqlCriteriaStatement.

Method Detail

getBaseClassDescriptor

protected ClassDescriptor getBaseClassDescriptor()

getSearchClassDescriptor

protected ClassDescriptor getSearchClassDescriptor()

getAttributeInfo

protected SqlQueryStatement.AttributeInfo getAttributeInfo(java.lang.String attr,
                                                           boolean useOuterJoins,
                                                           java.lang.String aUserAlias)
Return the TableAlias and the PathInfo for an Attribute name
field names in functions (ie: sum(name) ) are tried to resolve ie: name from FIELDDESCRIPTOR , UPPER(name_test) from Criteria
also resolve pathExpression adress.city or owner.konti.saldo

Parameters:
attr -
useOuterJoins -
aUserAlias -
Returns:
ColumnInfo

getColName

protected java.lang.String getColName(SqlQueryStatement.TableAlias aTableAlias,
                                      SqlHelper.PathInfo aPathInfo,
                                      boolean translate)
Answer the column name for alias and path info
if translate try to convert attribute name into column name otherwise use attribute name
if a FieldDescriptor is found for the attribute name the column name is taken from there prefixed with the alias (firstname -> A0.F_NAME).

Parameters:
aTableAlias -
aPathInfo -
translate -
Returns:

appendColName

protected boolean appendColName(SqlQueryStatement.TableAlias aTableAlias,
                                SqlHelper.PathInfo aPathInfo,
                                boolean translate,
                                java.lang.StringBuffer buf)
Add the Column to the StringBuffer

Parameters:
aTableAlias -
aPathInfo -
buf -
Returns:
true if appended

getFieldDescriptor

protected FieldDescriptor getFieldDescriptor(SqlQueryStatement.TableAlias aTableAlias,
                                             SqlHelper.PathInfo aPathInfo)
Get the FieldDescriptor for the PathInfo

Parameters:
aTableAlias -
aPathInfo -
Returns:
FieldDescriptor

appendColName

protected boolean appendColName(java.lang.String attr,
                                boolean useOuterJoins,
                                java.lang.String aUserAlias,
                                java.lang.StringBuffer buf)
Append the appropriate ColumnName to the buffer
if a FIELDDESCRIPTOR is found for the Criteria the colName is taken from there otherwise its taken from Criteria.
field names in functions (ie: sum(name) ) are tried to resolve ie: name from FIELDDESCRIPTOR , UPPER(name_test) from Criteria
also resolve pathExpression adress.city or owner.konti.saldo

Parameters:
attr -
useOuterJoins -
aUserAlias -
buf -
Returns:

appendColName

protected boolean appendColName(java.lang.String attr,
                                java.lang.String attrAlias,
                                boolean useOuterJoins,
                                java.lang.String aUserAlias,
                                java.lang.StringBuffer buf)
Append the appropriate ColumnName to the buffer
if a FIELDDESCRIPTOR is found for the Criteria the colName is taken from there otherwise its taken from Criteria.
field names in functions (ie: sum(name) ) are tried to resolve ie: name from FIELDDESCRIPTOR , UPPER(name_test) from Criteria
also resolve pathExpression adress.city or owner.konti.saldo

Parameters:
attr -
useOuterJoins -
aUserAlias -
buf -
Returns:

appendWhereClause

protected void appendWhereClause(java.lang.StringBuffer where,
                                 Criteria crit,
                                 java.lang.StringBuffer stmt)
appends a WHERE-clause to the Statement

Parameters:
where -
crit -
stmt -

appendHavingClause

protected void appendHavingClause(java.lang.StringBuffer having,
                                  Criteria crit,
                                  java.lang.StringBuffer stmt)
appends a HAVING-clause to the Statement

Parameters:
having -
crit -
stmt -

appendClause

protected void appendClause(java.lang.StringBuffer clause,
                            Criteria crit,
                            java.lang.StringBuffer stmt)
appends a WHERE/HAVING-clause to the Statement

Parameters:
clause -
crit -
stmt -

appendCriteria

protected void appendCriteria(SqlQueryStatement.TableAlias alias,
                              SqlHelper.PathInfo pathInfo,
                              SelectionCriteria c,
                              java.lang.StringBuffer buf)
Answer the SQL-Clause for a SelectionCriteria

Parameters:
alias -
pathInfo -
c - SelectionCriteria
buf -

appendSQLClause

protected void appendSQLClause(SelectionCriteria c,
                               java.lang.StringBuffer buf)
Answer the SQL-Clause for a SelectionCriteria If the Criteria references a class with extents an OR-Clause is added for each extent

Parameters:
c - SelectionCriteria

appendOrderByClause

protected void appendOrderByClause(java.util.List orderByFields,
                                   int[] orderByColumnNumbers,
                                   java.lang.StringBuffer buf)
Appends to the statement the ORDER BY clause for the Query


appendGroupByClause

protected void appendGroupByClause(java.util.List groupByFields,
                                   java.lang.StringBuffer buf)
Appends to the statement the GROUP BY clause for the Query


appendTableWithJoins

protected void appendTableWithJoins(SqlQueryStatement.TableAlias alias,
                                    java.lang.StringBuffer where,
                                    java.lang.StringBuffer buf)
Appends to the statement table and all tables joined to it.

Parameters:
alias - the table alias
where - append conditions for WHERE clause here

ensureColumns

protected int[] ensureColumns(java.util.List columns,
                              java.util.List existingColumns,
                              java.lang.StringBuffer buf)
Appends to the statement columns if they are not found among the existingColumns. Columns added here use a column-alias "ojb_col_x", x being the number of existing columns

Parameters:
columns - the list of columns represented by Criteria.Field to ensure
existingColumns - the list of column names (String) that are already appended
Returns:
the array of column numbers (base 1)

buildSuperJoinTree

protected void buildSuperJoinTree(SqlQueryStatement.TableAlias left,
                                  ClassDescriptor cld,
                                  java.lang.String name)
build the Join-Information if a super reference exists

Parameters:
left -
cld -
name -

splitCriteria

protected void splitCriteria()
First reduce the Criteria to the normal disjunctive form, then calculate the necessary tree of joined tables for each item, then group items with the same tree of joined tables.


getQuery

protected QueryByCriteria getQuery()
Gets the query.

Returns:
Returns a Query

getRoot

protected SqlQueryStatement.TableAlias getRoot()
Gets the root.

Returns:
Returns a TableAlias

setRoot

protected void setRoot(SqlQueryStatement.TableAlias root)
Sets the root.

Parameters:
root - The root to set

getSearchTable

protected SqlQueryStatement.TableAlias getSearchTable()
Gets the search table of this query.

Returns:
Returns a TableAlias

getJoinTreeToCriteria

protected java.util.HashMap getJoinTreeToCriteria()
Gets the joinTreeToCriteria.

Returns:
Returns a HashMap

getJoinSyntaxType

protected byte getJoinSyntaxType()
Returns the joinSyntaxType.

Returns:
byte

getLogger

protected Logger getLogger()
Returns the logger.

Returns:
Logger


Authors: Thomas Mahler and others. (C) 2000 - 2003 Apache Software Foundation
All rights reserved. Published under the Apache License.
http://db.apache.org/ojb
Version: 1.0.rc5, 2003-12-14