Class SQLSelectStatement
- java.lang.Object
-
- org.eclipse.persistence.internal.expressions.SQLStatement
-
- org.eclipse.persistence.internal.expressions.SQLSelectStatement
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable
public class SQLSelectStatement extends SQLStatement
Purpose: Print SELECT statement.
Responsibilities:
- Print SELECT statement.
- Since:
- TOPLink/Java 1.0
- Author:
- Dorin Sandu
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected ExpressionconnectByExpressionprotected DatabaseTablecurrentAliasprotected intcurrentAliasNumberprotected ReadAllQuery.Directiondirectionprotected shortdistinctStateUsed for "Select Distinct" option.protected java.util.Map<DatabaseField,java.lang.String>fieldAliasesUsed for caching the field alias written to the queryprotected intfieldCounterCounter to generate unique alias namesprotected java.util.VectorfieldsFields being selected (can include expressions).protected ForUpdateClauseforUpdateClauseUsed for pessimistic locking ie.protected java.util.List<Expression>groupByExpressionsGroup by clause for report queries.protected ExpressionhavingExpressionHaving clause for report queries.protected booleanisAggregateSelectUsed for report query or counts so we know how to treat distincts.protected DatabaseTablelastTableprotected java.util.List<java.lang.Object>nonSelectFieldsFields not being selected (can include expressions).protected java.util.Map<Expression,Expression>optimizedClonedExpressionsIt is used by subselect to re-normalize joinsprotected java.util.List<Expression>orderByExpressionsOrder by clause for read all queries.protected java.util.List<Expression>orderSiblingsByExpressionsprotected java.util.List<OuterJoinExpressionHolder>outerJoinExpressionHoldersUsed for DB2 style from clause outer joins.protected SQLSelectStatementparentStatementUsed for subselects.protected ReadQueryqueryQuery this statement is associated to (used for SQL query options).protected booleanrequiresAliasesVariables used for aliasing and normalizing.protected booleanshouldCacheFieldAliasesprotected ExpressionstartWithExpressionUsed for Oracle Hierarchical Queriesprotected java.util.Map<DatabaseTable,DatabaseTable>tableAliasesprotected java.util.List<DatabaseTable>tablesTables being selected from.protected java.util.List<Expression>unionExpressionsUnion clause.protected booleanuseUniqueFieldAliasesFlag used to indicate field names should use unique aliases-
Fields inherited from class org.eclipse.persistence.internal.expressions.SQLStatement
builder, hintString, translationRow, whereClause
-
-
Constructor Summary
Constructors Constructor Description SQLSelectStatement()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddField(Expression expression)INTERNAL: adds an expression to the fields.voidaddField(DatabaseField field)voidaddOptimizedClonedExpressions(Expression originalKey, Expression optimizedValue)INTERNAL: It is used by subqueries to avoid duplicate joins.protected voidaddOrderByExpressionToSelectForDistinct()When distinct is used with order by the ordered fields must be in the select clause.java.lang.IntegeraddOuterJoinExpressionsHolders(java.util.Map<DatabaseTable,Expression> outerJoinedAdditionalJoinCriteria, ClassDescriptor descriptor)INTERNAL: used by TREAT to add in a join from the parent table to the child tables when the parent expression did not add an outer join of its ownjava.lang.IntegeraddOuterJoinExpressionsHolders(ObjectExpression joinExpression, Expression outerJoinedMappingCriteria, java.util.Map<DatabaseTable,Expression> outerJoinedAdditionalJoinCriteria, ClassDescriptor descriptor)INTERNAL: Used by ExpressionBuilder and QueryKeyExpression normalization to create a standard outerjoin.voidaddTable(DatabaseTable table)Add a table to the statement.voidappendForUpdateClause(ExpressionSQLPrinter printer)This method will append the for update clause to the end of the select statement.voidappendFromClauseForInformixOuterJoin(ExpressionSQLPrinter printer, java.util.List<DatabaseTable> outerJoinedAliases)ADVANCED: If a platform is Informix, then the outer join must be in the FROM clause.voidappendFromClauseForOuterJoin(ExpressionSQLPrinter printer, java.util.List<DatabaseTable> outerJoinedAliases, java.util.Collection aliasesOfTablesToBeLocked, boolean shouldPrintUpdateClauseForAllTables)ADVANCED: Appends the SQL standard outer join clause, and some variation per platform.voidappendFromClauseToWriter(ExpressionSQLPrinter printer)Print the from clause.voidappendGroupByClauseToWriter(ExpressionSQLPrinter printer)This method will append the group by clause to the end of the select statement.voidappendHierarchicalQueryClauseToWriter(ExpressionSQLPrinter printer)This method will append the Hierarchical Query Clause to the end of the select statementvoidappendOrderClauseToWriter(ExpressionSQLPrinter printer)This method will append the order clause to the end of the select statement.voidappendUnionClauseToWriter(ExpressionSQLPrinter printer)This method will append the union clause to the end of the select statement.voidassignAliases(java.util.Vector allExpressions)INTERNAL: Alias the tables in all of our nodes.DatabaseCallbuildCall(AbstractSession session)Print the SQL representation of the statement on a stream.DatabaseCallbuildCall(AbstractSession session, DatabaseQuery query)Build the call, setting the query first, this is required in some cases when the query info is required to print the SQL.voidcomputeDistinct()INTERNAL: This is used by cursored stream to determine if an expression used distinct as the size must account for this.voidcomputeTables()INTERNAL: Computes all aliases which will appear in the FROM clause.voidcomputeTablesFromTables()If there is no where clause, alias the tables from the tables list directly.voiddontUseDistinct()ADVANCED: If a distinct has been set the DISTINCT clause will be printed.voidenableFieldAliasesCaching()protected booleanfieldsContainField(java.util.List fields, Expression expression)Check if the field from the field expression is already contained in the select clause of the statement.java.lang.StringgeneratedAlias(java.lang.String fieldName)Returns a generated alias based on the column name.java.lang.StringgetAliasFor(DatabaseField field)ExpressiongetConnectByExpression()INTERNAL: Return the CONNECT BY expressionintgetCurrentAliasNumber()Gets a unique id that will be used to alias the next table.ReadAllQuery.DirectiongetDirection()INTERNAL:java.util.VectorgetFields()INTERNAL: Return all the fieldsprotected ForUpdateClausegetForUpdateClause()java.util.List<Expression>getGroupByExpressions()INTERNAL: Return the group bys.ExpressiongetHavingExpression()INTERNAL: Return the having expression.intgetNextFieldCounterValue()INTERNAL: Return the next value of fieldCounterjava.util.List<java.lang.Object>getNonSelectFields()Return the fields we don't want to select but want to join on.java.util.Map<Expression,Expression>getOptimizedClonedExpressions()INTERNAL: It is used by subqueries to avoid duplicate joins.java.util.List<Expression>getOrderByExpressions()INTERNAL: Return the order expressions for the query.java.util.List<Expression>getOrderSiblingsByExpressions()INTERNAL: Return the ORDER SIBLINGS BY expressionjava.util.List<OuterJoinExpressionHolder>getOuterJoinExpressionsHolders()INTERNAL: returns outerJoinExpressionHolders representing outerjoin expressions.SQLSelectStatementgetParentStatement()Return the parent statement if using subselects.ReadQuerygetQuery()INTERNAL: Query held as it may store properties needed to generate the SQLExpressiongetStartWithExpression()INTERNAL: Return the StartWith expressionjava.util.Map<DatabaseTable,DatabaseTable>getTableAliases()INTERNAL: Return the aliases used.java.util.List<DatabaseTable>getTables()INTERNAL: Return all the tables.java.util.List<Expression>getUnionExpressions()booleangetUseUniqueFieldAliases()INTERNAL: Return True if unique field aliases will be generated of the form "fieldname AS fieldnameX", False otherwise.protected booleanhasAliasForTable(DatabaseTable table)booleanhasConnectByExpression()booleanhasGroupByExpressions()booleanhasHavingExpression()booleanhasHierarchicalQueryExpressions()booleanhasNonSelectFields()booleanhasOrderByExpressions()booleanhasOrderSiblingsByExpressions()booleanhasOuterJoinExpressions()booleanhasStartWithExpression()booleanhasUnionExpressions()booleanisAggregateSelect()INTERNAL:booleanisDistinctComputed()INTERNAL: return true if this query has computed its distinct value alreadybooleanisSubSelect()static java.util.SortedSetmapTableIndexToExpression(Expression expression, java.util.TreeMap map, java.util.List<DatabaseTable> tablesInOrder)INTERNAL: The method searches for expressions that join two tables each in a given expression.static java.util.MapmapTableToExpression(Expression expression, java.util.Vector tablesInOrder)INTERNAL: The method searches for expressions that join two tables each in a given expression.voidnormalize(AbstractSession session, ClassDescriptor descriptor)INTERNAL: Normalize an expression into a printable structure.voidnormalize(AbstractSession session, ClassDescriptor descriptor, java.util.Map clonedExpressions)INTERNAL: Normalize an expression into a printable structure.voidnormalizeForView(AbstractSession theSession, ClassDescriptor theDescriptor, java.util.Map clonedExpressions)INTERNAL: Normalize an expression mapping all of the descriptor's tables to the view.protected voidnormalizeOrderBy(Expression builder, java.util.List<Expression> allExpressions, java.util.Map<Expression,Expression> clonedExpressions, AbstractSession session)Check the order by for object expressions.protected voidprintForUpdateClauseOnJoin(DatabaseTable alias, ExpressionSQLPrinter printer, boolean shouldPrintUpdateClauseForAllTables, java.util.Collection aliasesOfTablesToBeLocked, DatabasePlatform platform)Print the FOR UPDATE clause after each join if required.protected voidprintOnClause(Expression onClause, ExpressionSQLPrinter printer, DatabasePlatform platform)Print the outer join ON clause.java.util.Vector<DatabaseField>printSQL(ExpressionSQLPrinter printer)Print the SQL representation of the statement on a stream.voidprintSQLForUpdateClause(ExpressionSQLPrinter printer)voidprintSQLGroupByClause(ExpressionSQLPrinter printer)voidprintSQLHavingClause(ExpressionSQLPrinter printer)voidprintSQLHierarchicalQueryClause(ExpressionSQLPrinter printer)voidprintSQLOrderByClause(ExpressionSQLPrinter printer)java.util.Vector<DatabaseField>printSQLSelect(ExpressionSQLPrinter printer)voidprintSQLUnionClause(ExpressionSQLPrinter printer)voidprintSQLWhereClause(ExpressionSQLPrinter printer)voidprintSQLWhereKeyWord(ExpressionSQLPrinter printer)voidrebuildAndAddExpressions(java.util.List expressions, java.util.List allExpressions, ExpressionBuilder primaryBuilder, java.util.Map clonedExpressions)Rebuild the expressions with the correct expression builder if using a different one.voidrebuildAndAddExpressions(java.util.Map expressions, java.util.Vector allExpressions, ExpressionBuilder primaryBuilder, java.util.Map clonedExpressions)Rebuild the expressions with the correct expression builder if using a different one.ExpressionrebuildExpression(Expression expression, Expression primaryBuilder, java.util.Map<Expression,Expression> clonedExpressions)Rebuild the expression if required.voidremoveField(DatabaseField field)INTERNAL:voidremoveTable(DatabaseTable table)Remove a table from the statement.booleanrequiresAliases()INTERNAL: Returns true if aliases are required, false otherwise.voidresetDistinct()ADVANCED: If a distinct has been set the DISTINCT clause will be printed.voidsetBuilder(ExpressionBuilder builder)voidsetCurrentAliasNumber(int currentAliasNumber)Sets a unique id that will be used to alias the next table.voidsetDistinctState(short distinctState)ADVANCED: If a distinct has been set the DISTINCT clause will be printed.voidsetFields(java.util.Vector fields)INTERNAL: Set the fields, if any are aggregate selects then record this so that the distinct is not printed through anyOfs.protected voidsetForUpdateClause(ForUpdateClause clause)voidsetGroupByExpressions(java.util.List<Expression> expressions)voidsetHavingExpression(Expression expressions)voidsetHierarchicalQueryExpressions(Expression startWith, Expression connectBy, java.util.List<Expression> orderSiblingsExpressions)INTERNAL: takes the hierarchical query expression which have been set on the query and sets them here used to generate the Hierarchical Query Clause in the SQLvoidsetHierarchicalQueryExpressions(Expression startWith, Expression connectBy, java.util.List<Expression> orderSiblingsExpressions, ReadAllQuery.Direction direction)INTERNAL: takes the hierarchical query expression which have been set on the query and sets them here used to generate the Hierarchical Query Clause in the SQLvoidsetIsAggregateSelect(boolean isAggregateSelect)voidsetLockingClause(ForUpdateClause lockingClause)voidsetNonSelectFields(java.util.List nonSelectFields)Set the non select fields.voidsetNormalizedWhereClause(Expression whereClause)Set the where clause expression.voidsetOrderByExpressions(java.util.List<Expression> orderByExpressions)voidsetParentStatement(SQLSelectStatement parentStatement)Set the parent statement if using subselects.voidsetQuery(ReadQuery query)Query held as it may store properties needed to generate the SQLvoidsetRequiresAliases(boolean requiresAliases)protected voidsetTableAliases(java.util.Map<DatabaseTable,DatabaseTable> theTableAliases)voidsetTables(java.util.List<DatabaseTable> theTables)voidsetUnionExpressions(java.util.List<Expression> unionExpressions)voidsetUseUniqueFieldAliases(boolean useUniqueFieldAliases)INTERNAL: If set unique field aliases will be generated of the form "fieldname AS fieldnameX" Where fieldname is the column name and X is an incremental value ensuring uniquenessbooleanshouldDistinctBeUsed()INTERNAL: If a distinct has been set the DISTINCT clause will be printed.protected voidsortOuterJoinExpressionHolders(java.util.List<OuterJoinExpressionHolder> holders)voiduseDistinct()ADVANCED: If a distinct has been set the DISTINCT clause will be printed.protected voidwriteField(ExpressionSQLPrinter printer, DatabaseField field)INTERNAL:protected voidwriteFieldsFromExpression(ExpressionSQLPrinter printer, Expression expression, java.util.Vector newFields)INTERNAL:protected java.util.VectorwriteFieldsIn(ExpressionSQLPrinter printer)INTERNAL:-
Methods inherited from class org.eclipse.persistence.internal.expressions.SQLStatement
clone, getBuilder, getExpressionBuilder, getHintString, getTranslationRow, getWhereClause, setHintString, setTranslationRow, setWhereClause, toString
-
-
-
-
Field Detail
-
query
protected ReadQuery query
Query this statement is associated to (used for SQL query options).
-
useUniqueFieldAliases
protected boolean useUniqueFieldAliases
Flag used to indicate field names should use unique aliases
-
fieldCounter
protected int fieldCounter
Counter to generate unique alias names
-
fields
protected java.util.Vector fields
Fields being selected (can include expressions).
-
nonSelectFields
protected java.util.List<java.lang.Object> nonSelectFields
Fields not being selected (can include expressions).
-
tables
protected java.util.List<DatabaseTable> tables
Tables being selected from.
-
distinctState
protected short distinctState
Used for "Select Distinct" option.
-
orderByExpressions
protected java.util.List<Expression> orderByExpressions
Order by clause for read all queries.
-
groupByExpressions
protected java.util.List<Expression> groupByExpressions
Group by clause for report queries.
-
unionExpressions
protected java.util.List<Expression> unionExpressions
Union clause.
-
havingExpression
protected Expression havingExpression
Having clause for report queries.
-
forUpdateClause
protected ForUpdateClause forUpdateClause
Used for pessimistic locking ie. "For Update".
-
isAggregateSelect
protected boolean isAggregateSelect
Used for report query or counts so we know how to treat distincts.
-
outerJoinExpressionHolders
protected java.util.List<OuterJoinExpressionHolder> outerJoinExpressionHolders
Used for DB2 style from clause outer joins.
-
startWithExpression
protected Expression startWithExpression
Used for Oracle Hierarchical Queries
-
connectByExpression
protected Expression connectByExpression
-
orderSiblingsByExpressions
protected java.util.List<Expression> orderSiblingsByExpressions
-
direction
protected ReadAllQuery.Direction direction
-
requiresAliases
protected boolean requiresAliases
Variables used for aliasing and normalizing.
-
tableAliases
protected java.util.Map<DatabaseTable,DatabaseTable> tableAliases
-
lastTable
protected DatabaseTable lastTable
-
currentAlias
protected DatabaseTable currentAlias
-
currentAliasNumber
protected int currentAliasNumber
-
parentStatement
protected SQLSelectStatement parentStatement
Used for subselects.
-
optimizedClonedExpressions
protected java.util.Map<Expression,Expression> optimizedClonedExpressions
It is used by subselect to re-normalize joins
-
fieldAliases
protected java.util.Map<DatabaseField,java.lang.String> fieldAliases
Used for caching the field alias written to the query
-
shouldCacheFieldAliases
protected boolean shouldCacheFieldAliases
-
-
Method Detail
-
addField
public void addField(DatabaseField field)
-
addField
public void addField(Expression expression)
INTERNAL: adds an expression to the fields. set a flag if the expression is for and aggregate function.
-
addOrderByExpressionToSelectForDistinct
protected void addOrderByExpressionToSelectForDistinct()
When distinct is used with order by the ordered fields must be in the select clause.
-
addTable
public void addTable(DatabaseTable table)
Add a table to the statement. The table will be used in the FROM part of the SQL statement.
-
appendFromClauseForInformixOuterJoin
public void appendFromClauseForInformixOuterJoin(ExpressionSQLPrinter printer, java.util.List<DatabaseTable> outerJoinedAliases) throws java.io.IOException
ADVANCED: If a platform is Informix, then the outer join must be in the FROM clause. This is used internally by EclipseLink for building Informix outer join syntax which differs from other platforms (Oracle,Sybase) that print the outer join in the WHERE clause and from DB2 which prints the OuterJoinedAliases passed in to keep track of tables used for outer join so no normal join is given. This syntax is old for Informix, so should probably be removed.- Throws:
java.io.IOException
-
appendFromClauseForOuterJoin
public void appendFromClauseForOuterJoin(ExpressionSQLPrinter printer, java.util.List<DatabaseTable> outerJoinedAliases, java.util.Collection aliasesOfTablesToBeLocked, boolean shouldPrintUpdateClauseForAllTables) throws java.io.IOException
ADVANCED: Appends the SQL standard outer join clause, and some variation per platform. Most platforms use this syntax, support is also offered for Oracle to join in the where clause (although it should use the FROM clause as the WHERE clause is obsolete). This is also used for inner joins when configured in the platform.- Throws:
java.io.IOException
-
printOnClause
protected void printOnClause(Expression onClause, ExpressionSQLPrinter printer, DatabasePlatform platform) throws java.io.IOException
Print the outer join ON clause. Some databases do not allow brackets.- Throws:
java.io.IOException
-
printForUpdateClauseOnJoin
protected void printForUpdateClauseOnJoin(DatabaseTable alias, ExpressionSQLPrinter printer, boolean shouldPrintUpdateClauseForAllTables, java.util.Collection aliasesOfTablesToBeLocked, DatabasePlatform platform)
Print the FOR UPDATE clause after each join if required.
-
appendFromClauseToWriter
public void appendFromClauseToWriter(ExpressionSQLPrinter printer) throws java.io.IOException
Print the from clause. This includes outer joins, these must be printed before the normal join to ensure that the source tables are not joined again. Outer joins are not printed in the FROM clause on Oracle or Sybase.- Throws:
java.io.IOException
-
appendGroupByClauseToWriter
public void appendGroupByClauseToWriter(ExpressionSQLPrinter printer) throws java.io.IOException
This method will append the group by clause to the end of the select statement.- Throws:
java.io.IOException
-
appendHierarchicalQueryClauseToWriter
public void appendHierarchicalQueryClauseToWriter(ExpressionSQLPrinter printer) throws java.io.IOException
This method will append the Hierarchical Query Clause to the end of the select statement- Throws:
java.io.IOException
-
appendOrderClauseToWriter
public void appendOrderClauseToWriter(ExpressionSQLPrinter printer) throws java.io.IOException
This method will append the order clause to the end of the select statement.- Throws:
java.io.IOException
-
appendUnionClauseToWriter
public void appendUnionClauseToWriter(ExpressionSQLPrinter printer) throws java.io.IOException
This method will append the union clause to the end of the select statement.- Throws:
java.io.IOException
-
appendForUpdateClause
public void appendForUpdateClause(ExpressionSQLPrinter printer)
This method will append the for update clause to the end of the select statement.
-
assignAliases
public void assignAliases(java.util.Vector allExpressions)
INTERNAL: Alias the tables in all of our nodes.
-
buildCall
public DatabaseCall buildCall(AbstractSession session, DatabaseQuery query)
Build the call, setting the query first, this is required in some cases when the query info is required to print the SQL.
-
buildCall
public DatabaseCall buildCall(AbstractSession session)
Print the SQL representation of the statement on a stream.- Specified by:
buildCallin classSQLStatement
-
computeDistinct
public void computeDistinct()
INTERNAL: This is used by cursored stream to determine if an expression used distinct as the size must account for this.
-
isSubSelect
public boolean isSubSelect()
-
getOptimizedClonedExpressions
public java.util.Map<Expression,Expression> getOptimizedClonedExpressions()
INTERNAL: It is used by subqueries to avoid duplicate joins.
-
addOptimizedClonedExpressions
public void addOptimizedClonedExpressions(Expression originalKey, Expression optimizedValue)
INTERNAL: It is used by subqueries to avoid duplicate joins.
-
computeTables
public void computeTables()
INTERNAL: Computes all aliases which will appear in the FROM clause.
-
computeTablesFromTables
public void computeTablesFromTables()
If there is no where clause, alias the tables from the tables list directly. Assume there's no ambiguity
-
dontUseDistinct
public void dontUseDistinct()
ADVANCED: If a distinct has been set the DISTINCT clause will be printed. This is used internally by TopLink for batch reading but may also be used directly for advanced queries or report queries.
-
fieldsContainField
protected boolean fieldsContainField(java.util.List fields, Expression expression)Check if the field from the field expression is already contained in the select clause of the statement. This is used on order by expression when the field being ordered by must be in the select, but cannot be in the select twice.
-
getCurrentAliasNumber
public int getCurrentAliasNumber()
Gets a unique id that will be used to alias the next table. For sub-selects all must use this same aliasing information, maintained in the root enclosing statement. For CR#2627019
-
getFields
public java.util.Vector getFields()
INTERNAL: Return all the fields
-
getForUpdateClause
protected ForUpdateClause getForUpdateClause()
-
getGroupByExpressions
public java.util.List<Expression> getGroupByExpressions()
INTERNAL: Return the group bys.
-
getHavingExpression
public Expression getHavingExpression()
INTERNAL: Return the having expression.
-
getQuery
public ReadQuery getQuery()
INTERNAL: Query held as it may store properties needed to generate the SQL
-
getStartWithExpression
public Expression getStartWithExpression()
INTERNAL: Return the StartWith expression
-
getConnectByExpression
public Expression getConnectByExpression()
INTERNAL: Return the CONNECT BY expression
-
getOrderSiblingsByExpressions
public java.util.List<Expression> getOrderSiblingsByExpressions()
INTERNAL: Return the ORDER SIBLINGS BY expression
-
getDirection
public ReadAllQuery.Direction getDirection()
INTERNAL:- Returns:
- the position of the PRIOR keyword
-
getNextFieldCounterValue
public int getNextFieldCounterValue()
INTERNAL: Return the next value of fieldCounter
-
getNonSelectFields
public java.util.List<java.lang.Object> getNonSelectFields()
Return the fields we don't want to select but want to join on.
-
getOrderByExpressions
public java.util.List<Expression> getOrderByExpressions()
INTERNAL: Return the order expressions for the query.
-
getUnionExpressions
public java.util.List<Expression> getUnionExpressions()
-
setUnionExpressions
public void setUnionExpressions(java.util.List<Expression> unionExpressions)
-
getOuterJoinExpressionsHolders
public java.util.List<OuterJoinExpressionHolder> getOuterJoinExpressionsHolders()
INTERNAL: returns outerJoinExpressionHolders representing outerjoin expressions.- Returns:
-
addOuterJoinExpressionsHolders
public java.lang.Integer addOuterJoinExpressionsHolders(ObjectExpression joinExpression, Expression outerJoinedMappingCriteria, java.util.Map<DatabaseTable,Expression> outerJoinedAdditionalJoinCriteria, ClassDescriptor descriptor)
INTERNAL: Used by ExpressionBuilder and QueryKeyExpression normalization to create a standard outerjoin.- Parameters:
joinExpression- - expression resulting in the outerjoin. Null if it is for inheritance reading of subclassesouterJoinedMappingCriteria- - used for querykey mapping expressionsouterJoinedAdditionalJoinCriteria- - additional tables/expressions to join. Usually for multitableInheritance join expressionsdescriptor- - descriptor to use if this is for reading in subclasses in one query.- Returns:
-
addOuterJoinExpressionsHolders
public java.lang.Integer addOuterJoinExpressionsHolders(java.util.Map<DatabaseTable,Expression> outerJoinedAdditionalJoinCriteria, ClassDescriptor descriptor)
INTERNAL: used by TREAT to add in a join from the parent table to the child tables when the parent expression did not add an outer join of its own
-
getParentStatement
public SQLSelectStatement getParentStatement()
Return the parent statement if using subselects. This is used to normalize correctly with subselects.
-
getTableAliases
public java.util.Map<DatabaseTable,DatabaseTable> getTableAliases()
INTERNAL: Return the aliases used.
-
getTables
public java.util.List<DatabaseTable> getTables()
INTERNAL: Return all the tables.
-
getUseUniqueFieldAliases
public boolean getUseUniqueFieldAliases()
INTERNAL: Return True if unique field aliases will be generated of the form "fieldname AS fieldnameX", False otherwise.
-
hasAliasForTable
protected boolean hasAliasForTable(DatabaseTable table)
-
hasGroupByExpressions
public boolean hasGroupByExpressions()
-
hasHavingExpression
public boolean hasHavingExpression()
-
hasStartWithExpression
public boolean hasStartWithExpression()
-
hasConnectByExpression
public boolean hasConnectByExpression()
-
hasOrderSiblingsByExpressions
public boolean hasOrderSiblingsByExpressions()
-
hasHierarchicalQueryExpressions
public boolean hasHierarchicalQueryExpressions()
-
hasOrderByExpressions
public boolean hasOrderByExpressions()
-
hasUnionExpressions
public boolean hasUnionExpressions()
-
hasNonSelectFields
public boolean hasNonSelectFields()
-
hasOuterJoinExpressions
public boolean hasOuterJoinExpressions()
-
isAggregateSelect
public boolean isAggregateSelect()
INTERNAL:
-
isDistinctComputed
public boolean isDistinctComputed()
INTERNAL: return true if this query has computed its distinct value already
-
normalize
public final void normalize(AbstractSession session, ClassDescriptor descriptor)
INTERNAL: Normalize an expression into a printable structure. i.e. merge the expression with the join expressions. Also replace table names with corresponding aliases.
-
normalize
public void normalize(AbstractSession session, ClassDescriptor descriptor, java.util.Map clonedExpressions)
INTERNAL: Normalize an expression into a printable structure. i.e. merge the expression with the join expressions. Also replace table names with corresponding aliases.- Parameters:
clonedExpressions- With 2612185 allows additional expressions from multiple bases to be rebuilt on the correct cloned base.
-
normalizeForView
public void normalizeForView(AbstractSession theSession, ClassDescriptor theDescriptor, java.util.Map clonedExpressions)
INTERNAL: Normalize an expression mapping all of the descriptor's tables to the view. This is used to allow a descriptor to read from a view, but write to tables. This is used in the multiple table and subclasses read so all of the descriptor's possible tables must be mapped to the view.
-
normalizeOrderBy
protected void normalizeOrderBy(Expression builder, java.util.List<Expression> allExpressions, java.util.Map<Expression,Expression> clonedExpressions, AbstractSession session)
Check the order by for object expressions. Order by the objects primary key or all fields for aggregates.
-
printSQL
public java.util.Vector<DatabaseField> printSQL(ExpressionSQLPrinter printer)
Print the SQL representation of the statement on a stream.
-
printSQLSelect
public java.util.Vector<DatabaseField> printSQLSelect(ExpressionSQLPrinter printer) throws java.io.IOException
- Throws:
java.io.IOException
-
printSQLWhereKeyWord
public void printSQLWhereKeyWord(ExpressionSQLPrinter printer) throws java.io.IOException
- Throws:
java.io.IOException
-
printSQLWhereClause
public void printSQLWhereClause(ExpressionSQLPrinter printer) throws java.io.IOException
- Throws:
java.io.IOException
-
printSQLHierarchicalQueryClause
public void printSQLHierarchicalQueryClause(ExpressionSQLPrinter printer) throws java.io.IOException
- Throws:
java.io.IOException
-
printSQLGroupByClause
public void printSQLGroupByClause(ExpressionSQLPrinter printer) throws java.io.IOException
- Throws:
java.io.IOException
-
printSQLHavingClause
public void printSQLHavingClause(ExpressionSQLPrinter printer) throws java.io.IOException
- Throws:
java.io.IOException
-
printSQLOrderByClause
public void printSQLOrderByClause(ExpressionSQLPrinter printer) throws java.io.IOException
- Throws:
java.io.IOException
-
printSQLForUpdateClause
public void printSQLForUpdateClause(ExpressionSQLPrinter printer) throws java.io.IOException
- Throws:
java.io.IOException
-
printSQLUnionClause
public void printSQLUnionClause(ExpressionSQLPrinter printer) throws java.io.IOException
- Throws:
java.io.IOException
-
rebuildAndAddExpressions
public void rebuildAndAddExpressions(java.util.List expressions, java.util.List allExpressions, ExpressionBuilder primaryBuilder, java.util.Map clonedExpressions)Rebuild the expressions with the correct expression builder if using a different one.
-
rebuildExpression
public Expression rebuildExpression(Expression expression, Expression primaryBuilder, java.util.Map<Expression,Expression> clonedExpressions)
Rebuild the expression if required.
-
rebuildAndAddExpressions
public void rebuildAndAddExpressions(java.util.Map expressions, java.util.Vector allExpressions, ExpressionBuilder primaryBuilder, java.util.Map clonedExpressions)Rebuild the expressions with the correct expression builder if using a different one. Exact copy of the another rebuildAndAddExpressions adopted to a Map with Expression values as the first parameter (instead of Vector in the original method)
-
removeField
public void removeField(DatabaseField field)
INTERNAL:
-
removeTable
public void removeTable(DatabaseTable table)
Remove a table from the statement. The table will be dropped from the FROM part of the SQL statement.
-
requiresAliases
public boolean requiresAliases()
INTERNAL: Returns true if aliases are required, false otherwise. If requiresAliases is set then force aliasing, this is required for object-rel.
-
resetDistinct
public void resetDistinct()
ADVANCED: If a distinct has been set the DISTINCT clause will be printed. This is used internally by TopLink for batch reading but may also be used directly for advanced queries or report queries.
-
setBuilder
public void setBuilder(ExpressionBuilder builder)
- Overrides:
setBuilderin classSQLStatement
-
setCurrentAliasNumber
public void setCurrentAliasNumber(int currentAliasNumber)
Sets a unique id that will be used to alias the next table. For sub-selects all must use this same aliasing information, maintained in the root enclosing statement. For CR#2627019
-
setNonSelectFields
public void setNonSelectFields(java.util.List nonSelectFields)
Set the non select fields. The fields are used only on joining.
-
setNormalizedWhereClause
public void setNormalizedWhereClause(Expression whereClause)
Set the where clause expression. This must be used during normalization as the normal setWhereClause has the side effect of setting the builder, which must not occur during normalize.
-
setDistinctState
public void setDistinctState(short distinctState)
ADVANCED: If a distinct has been set the DISTINCT clause will be printed. This is used internally by TopLink for batch reading but may also be used directly for advanced queries or report queries.
-
setFields
public void setFields(java.util.Vector fields)
INTERNAL: Set the fields, if any are aggregate selects then record this so that the distinct is not printed through anyOfs.
-
setGroupByExpressions
public void setGroupByExpressions(java.util.List<Expression> expressions)
-
setHavingExpression
public void setHavingExpression(Expression expressions)
-
setHierarchicalQueryExpressions
public void setHierarchicalQueryExpressions(Expression startWith, Expression connectBy, java.util.List<Expression> orderSiblingsExpressions)
INTERNAL: takes the hierarchical query expression which have been set on the query and sets them here used to generate the Hierarchical Query Clause in the SQL
-
setHierarchicalQueryExpressions
public void setHierarchicalQueryExpressions(Expression startWith, Expression connectBy, java.util.List<Expression> orderSiblingsExpressions, ReadAllQuery.Direction direction)
INTERNAL: takes the hierarchical query expression which have been set on the query and sets them here used to generate the Hierarchical Query Clause in the SQL
-
setIsAggregateSelect
public void setIsAggregateSelect(boolean isAggregateSelect)
-
setForUpdateClause
protected void setForUpdateClause(ForUpdateClause clause)
-
setLockingClause
public void setLockingClause(ForUpdateClause lockingClause)
-
setOrderByExpressions
public void setOrderByExpressions(java.util.List<Expression> orderByExpressions)
-
setParentStatement
public void setParentStatement(SQLSelectStatement parentStatement)
Set the parent statement if using subselects. This is used to normalize correctly with subselects.
-
setQuery
public void setQuery(ReadQuery query)
Query held as it may store properties needed to generate the SQL
-
setRequiresAliases
public void setRequiresAliases(boolean requiresAliases)
-
setTableAliases
protected void setTableAliases(java.util.Map<DatabaseTable,DatabaseTable> theTableAliases)
-
setTables
public void setTables(java.util.List<DatabaseTable> theTables)
-
setUseUniqueFieldAliases
public void setUseUniqueFieldAliases(boolean useUniqueFieldAliases)
INTERNAL: If set unique field aliases will be generated of the form "fieldname AS fieldnameX" Where fieldname is the column name and X is an incremental value ensuring uniqueness
-
shouldDistinctBeUsed
public boolean shouldDistinctBeUsed()
INTERNAL: If a distinct has been set the DISTINCT clause will be printed. This is required for batch reading.
-
useDistinct
public void useDistinct()
ADVANCED: If a distinct has been set the DISTINCT clause will be printed. This is used internally by TopLink for batch reading but may also be used directly for advanced queries or report queries.
-
writeField
protected void writeField(ExpressionSQLPrinter printer, DatabaseField field)
INTERNAL:
-
enableFieldAliasesCaching
public void enableFieldAliasesCaching()
-
getAliasFor
public java.lang.String getAliasFor(DatabaseField field)
-
generatedAlias
public java.lang.String generatedAlias(java.lang.String fieldName)
Returns a generated alias based on the column name. If the new alias will be too long The alias is automatically truncated
-
writeFieldsFromExpression
protected void writeFieldsFromExpression(ExpressionSQLPrinter printer, Expression expression, java.util.Vector newFields)
INTERNAL:
-
writeFieldsIn
protected java.util.Vector writeFieldsIn(ExpressionSQLPrinter printer)
INTERNAL:
-
mapTableIndexToExpression
public static java.util.SortedSet mapTableIndexToExpression(Expression expression, java.util.TreeMap map, java.util.List<DatabaseTable> tablesInOrder)
INTERNAL: The method searches for expressions that join two tables each in a given expression. Given expression and tablesInOrder and an empty SortedMap (TreeMap with no Comparator), this method populates the map with expressions corresponding to two tables keyed by an index (in tablesInOrder) of the table with the highest (of two) index; returns all the participating in at least one of the expressions. Example: expression (joining Employee to Project through m-m mapping "projects"): (employee.emp_id = proj_emp.emp_id) and (proj_emp.proj_id = project.proj_id) tablesInOrder: employee, proj_emp, project results: map: 1 -> (employee.emp_id = proj_emp.emp_id) 2 -> (proj_emp.proj_id = project.proj_id) returned SortedSet: {0, 1, 2}. Note that tablesInOrder must contain all tables used by expression
-
mapTableToExpression
public static java.util.Map mapTableToExpression(Expression expression, java.util.Vector tablesInOrder)
INTERNAL: The method searches for expressions that join two tables each in a given expression. Given expression and tablesInOrder, this method returns the map with expressions corresponding to two tables keyed by tables (from tablesInOrder) with the highest (of two) index; Example: expression (joining Employee to Project through m-m mapping "projects"): (employee.emp_id = proj_emp.emp_id) and (proj_emp.proj_id = project.proj_id) tablesInOrder: employee, proj_emp, project results: returned map: proj_emp -> (employee.emp_id = proj_emp.emp_id) project -> (proj_emp.proj_id = project.proj_id) Note that tablesInOrder must contain all tables used by expression
-
sortOuterJoinExpressionHolders
protected void sortOuterJoinExpressionHolders(java.util.List<OuterJoinExpressionHolder> holders)
-
-