public class SQLSelectStatement extends SQLStatement
Purpose: Print SELECT statement.
Responsibilities:
Constructor and Description |
---|
SQLSelectStatement() |
Modifier and Type | Method and Description |
---|---|
void |
addField(DatabaseField field) |
void |
addField(Expression expression)
INTERNAL: adds an expression to the fields.
|
void |
addOptimizedClonedExpressions(Expression originalKey,
Expression optimizedValue)
INTERNAL:
It is used by subqueries to avoid duplicate joins.
|
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
|
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.
|
void |
addTable(DatabaseTable table)
Add a table to the statement.
|
void |
appendForUpdateClause(ExpressionSQLPrinter printer)
This method will append the for update clause to the end of the
select statement.
|
void |
appendFromClauseForInformixOuterJoin(ExpressionSQLPrinter printer,
java.util.List<DatabaseTable> outerJoinedAliases)
ADVANCED:
If a platform is Informix, then the outer join must be in the FROM clause.
|
void |
appendFromClauseForOuterJoin(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.
|
void |
appendFromClauseToWriter(ExpressionSQLPrinter printer)
Print the from clause.
|
void |
appendGroupByClauseToWriter(ExpressionSQLPrinter printer)
This method will append the group by clause to the end of the
select statement.
|
void |
appendHierarchicalQueryClauseToWriter(ExpressionSQLPrinter printer)
This method will append the Hierarchical Query Clause to the end of the
select statement
|
void |
appendOrderClauseToWriter(ExpressionSQLPrinter printer)
This method will append the order clause to the end of the
select statement.
|
void |
appendUnionClauseToWriter(ExpressionSQLPrinter printer)
This method will append the union clause to the end of the
select statement.
|
void |
assignAliases(java.util.Vector allExpressions)
INTERNAL: Alias the tables in all of our nodes.
|
DatabaseCall |
buildCall(AbstractSession session)
Print the SQL representation of the statement on a stream.
|
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.
|
void |
computeDistinct()
INTERNAL:
This is used by cursored stream to determine if an expression used distinct as the size must account for this.
|
void |
computeTables()
INTERNAL:
Computes all aliases which will appear in the FROM clause.
|
void |
computeTablesFromTables()
If there is no where clause, alias the tables from the tables list directly.
|
void |
dontUseDistinct()
ADVANCED:
If a distinct has been set the DISTINCT clause will be printed.
|
java.lang.String |
generatedAlias(java.lang.String fieldName)
Returns a generated alias based on the column name.
|
Expression |
getConnectByExpression()
INTERNAL:
Return the CONNECT BY expression
|
int |
getCurrentAliasNumber()
Gets a unique id that will be used to alias the next table.
|
ReadAllQuery.Direction |
getDirection()
INTERNAL:
|
java.util.Vector |
getFields()
INTERNAL:
Return all the fields
|
java.util.List<Expression> |
getGroupByExpressions()
INTERNAL:
Return the group bys.
|
Expression |
getHavingExpression()
INTERNAL:
Return the having expression.
|
int |
getNextFieldCounterValue()
INTERNAL:
Return the next value of fieldCounter
|
java.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 expression
|
java.util.List<OuterJoinExpressionHolder> |
getOuterJoinExpressionsHolders()
INTERNAL:
returns outerJoinExpressionHolders representing outerjoin expressions.
|
SQLSelectStatement |
getParentStatement()
Return the parent statement if using subselects.
|
ReadQuery |
getQuery()
INTERNAL:
Query held as it may store properties needed to generate the SQL
|
Expression |
getStartWithExpression()
INTERNAL:
Return the StartWith expression
|
java.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() |
boolean |
getUseUniqueFieldAliases()
INTERNAL:
Return True if unique field aliases will be generated of the form
"fieldname AS fieldnameX", False otherwise.
|
boolean |
hasConnectByExpression() |
boolean |
hasGroupByExpressions() |
boolean |
hasHavingExpression() |
boolean |
hasHierarchicalQueryExpressions() |
boolean |
hasNonSelectFields() |
boolean |
hasOrderByExpressions() |
boolean |
hasOrderSiblingsByExpressions() |
boolean |
hasOuterJoinExpressions() |
boolean |
hasStartWithExpression() |
boolean |
hasUnionExpressions() |
boolean |
isAggregateSelect()
INTERNAL:
|
boolean |
isDistinctComputed()
INTERNAL:
return true if this query has computed its distinct value already
|
boolean |
isSubSelect() |
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.
|
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.
|
void |
normalize(AbstractSession session,
ClassDescriptor descriptor)
INTERNAL:
Normalize an expression into a printable structure.
|
void |
normalize(AbstractSession session,
ClassDescriptor descriptor,
java.util.Map clonedExpressions)
INTERNAL:
Normalize an expression into a printable structure.
|
void |
normalizeForView(AbstractSession theSession,
ClassDescriptor theDescriptor,
java.util.Map clonedExpressions)
INTERNAL:
Normalize an expression mapping all of the descriptor's tables to the view.
|
java.util.Vector |
printSQL(ExpressionSQLPrinter printer)
Print the SQL representation of the statement on a stream.
|
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.
|
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.
|
Expression |
rebuildExpression(Expression expression,
Expression primaryBuilder,
java.util.Map<Expression,Expression> clonedExpressions)
Rebuild the expression if required.
|
void |
removeField(DatabaseField field)
INTERNAL:
|
void |
removeTable(DatabaseTable table)
Remove a table from the statement.
|
boolean |
requiresAliases()
INTERNAL: Returns true if aliases are required, false otherwise.
|
void |
resetDistinct()
ADVANCED:
If a distinct has been set the DISTINCT clause will be printed.
|
void |
setBuilder(ExpressionBuilder builder) |
void |
setCurrentAliasNumber(int currentAliasNumber)
Sets a unique id that will be used to alias the next table.
|
void |
setDistinctState(short distinctState)
ADVANCED:
If a distinct has been set the DISTINCT clause will be printed.
|
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.
|
void |
setGroupByExpressions(java.util.List<Expression> expressions) |
void |
setHavingExpression(Expression expressions) |
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
|
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
|
void |
setIsAggregateSelect(boolean isAggregateSelect) |
void |
setLockingClause(ForUpdateClause lockingClause) |
void |
setNonSelectFields(java.util.List nonSelectFields)
Set the non select fields.
|
void |
setNormalizedWhereClause(Expression whereClause)
Set the where clause expression.
|
void |
setOrderByExpressions(java.util.List<Expression> orderByExpressions) |
void |
setParentStatement(SQLSelectStatement parentStatement)
Set the parent statement if using subselects.
|
void |
setQuery(ReadQuery query)
Query held as it may store properties needed to generate the SQL
|
void |
setRequiresAliases(boolean requiresAliases) |
void |
setTables(java.util.List<DatabaseTable> theTables) |
void |
setUnionExpressions(java.util.List<Expression> unionExpressions) |
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
|
boolean |
shouldDistinctBeUsed()
INTERNAL:
If a distinct has been set the DISTINCT clause will be printed.
|
void |
useDistinct()
ADVANCED:
If a distinct has been set the DISTINCT clause will be printed.
|
clone, getBuilder, getExpressionBuilder, getHintString, getTranslationRow, getWhereClause, setHintString, setTranslationRow, setWhereClause, toString
public void addField(DatabaseField field)
public void addField(Expression expression)
public void addTable(DatabaseTable table)
public void appendFromClauseForInformixOuterJoin(ExpressionSQLPrinter printer, java.util.List<DatabaseTable> outerJoinedAliases) throws java.io.IOException
java.io.IOException
public void appendFromClauseForOuterJoin(ExpressionSQLPrinter printer, java.util.List<DatabaseTable> outerJoinedAliases, java.util.Collection aliasesOfTablesToBeLocked, boolean shouldPrintUpdateClauseForAllTables) throws java.io.IOException
java.io.IOException
public void appendFromClauseToWriter(ExpressionSQLPrinter printer) throws java.io.IOException
java.io.IOException
public void appendGroupByClauseToWriter(ExpressionSQLPrinter printer) throws java.io.IOException
java.io.IOException
public void appendHierarchicalQueryClauseToWriter(ExpressionSQLPrinter printer) throws java.io.IOException
java.io.IOException
public void appendOrderClauseToWriter(ExpressionSQLPrinter printer) throws java.io.IOException
java.io.IOException
public void appendUnionClauseToWriter(ExpressionSQLPrinter printer) throws java.io.IOException
java.io.IOException
public void appendForUpdateClause(ExpressionSQLPrinter printer)
public void assignAliases(java.util.Vector allExpressions)
public DatabaseCall buildCall(AbstractSession session, DatabaseQuery query)
public DatabaseCall buildCall(AbstractSession session)
buildCall
in class SQLStatement
public void computeDistinct()
public boolean isSubSelect()
public java.util.Map<Expression,Expression> getOptimizedClonedExpressions()
public void addOptimizedClonedExpressions(Expression originalKey, Expression optimizedValue)
public void computeTables()
public void computeTablesFromTables()
public void dontUseDistinct()
public int getCurrentAliasNumber()
public java.util.Vector getFields()
public java.util.List<Expression> getGroupByExpressions()
public Expression getHavingExpression()
public ReadQuery getQuery()
public Expression getStartWithExpression()
public Expression getConnectByExpression()
public java.util.List<Expression> getOrderSiblingsByExpressions()
public ReadAllQuery.Direction getDirection()
public int getNextFieldCounterValue()
public java.util.List<java.lang.Object> getNonSelectFields()
public java.util.List<Expression> getOrderByExpressions()
public java.util.List<Expression> getUnionExpressions()
public void setUnionExpressions(java.util.List<Expression> unionExpressions)
public java.util.List<OuterJoinExpressionHolder> getOuterJoinExpressionsHolders()
public java.lang.Integer addOuterJoinExpressionsHolders(ObjectExpression joinExpression, Expression outerJoinedMappingCriteria, java.util.Map<DatabaseTable,Expression> outerJoinedAdditionalJoinCriteria, ClassDescriptor descriptor)
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.public java.lang.Integer addOuterJoinExpressionsHolders(java.util.Map<DatabaseTable,Expression> outerJoinedAdditionalJoinCriteria, ClassDescriptor descriptor)
public SQLSelectStatement getParentStatement()
public java.util.Map<DatabaseTable,DatabaseTable> getTableAliases()
public java.util.List<DatabaseTable> getTables()
public boolean getUseUniqueFieldAliases()
public boolean hasGroupByExpressions()
public boolean hasHavingExpression()
public boolean hasStartWithExpression()
public boolean hasConnectByExpression()
public boolean hasOrderSiblingsByExpressions()
public boolean hasHierarchicalQueryExpressions()
public boolean hasOrderByExpressions()
public boolean hasUnionExpressions()
public boolean hasNonSelectFields()
public boolean hasOuterJoinExpressions()
public boolean isAggregateSelect()
public boolean isDistinctComputed()
public final void normalize(AbstractSession session, ClassDescriptor descriptor)
public void normalize(AbstractSession session, ClassDescriptor descriptor, java.util.Map clonedExpressions)
clonedExpressions
- With 2612185 allows additional expressions
from multiple bases to be rebuilt on the correct cloned base.public void normalizeForView(AbstractSession theSession, ClassDescriptor theDescriptor, java.util.Map clonedExpressions)
public java.util.Vector printSQL(ExpressionSQLPrinter printer)
public void rebuildAndAddExpressions(java.util.List expressions, java.util.List allExpressions, ExpressionBuilder primaryBuilder, java.util.Map clonedExpressions)
public Expression rebuildExpression(Expression expression, Expression primaryBuilder, java.util.Map<Expression,Expression> clonedExpressions)
public void rebuildAndAddExpressions(java.util.Map expressions, java.util.Vector allExpressions, ExpressionBuilder primaryBuilder, java.util.Map clonedExpressions)
public void removeField(DatabaseField field)
public void removeTable(DatabaseTable table)
public boolean requiresAliases()
public void resetDistinct()
public void setBuilder(ExpressionBuilder builder)
public void setCurrentAliasNumber(int currentAliasNumber)
public void setNonSelectFields(java.util.List nonSelectFields)
public void setNormalizedWhereClause(Expression whereClause)
public void setDistinctState(short distinctState)
public void setFields(java.util.Vector fields)
public void setGroupByExpressions(java.util.List<Expression> expressions)
public void setHavingExpression(Expression expressions)
public void setHierarchicalQueryExpressions(Expression startWith, Expression connectBy, java.util.List<Expression> orderSiblingsExpressions)
public void setHierarchicalQueryExpressions(Expression startWith, Expression connectBy, java.util.List<Expression> orderSiblingsExpressions, ReadAllQuery.Direction direction)
public void setIsAggregateSelect(boolean isAggregateSelect)
public void setLockingClause(ForUpdateClause lockingClause)
public void setOrderByExpressions(java.util.List<Expression> orderByExpressions)
public void setParentStatement(SQLSelectStatement parentStatement)
public void setQuery(ReadQuery query)
public void setRequiresAliases(boolean requiresAliases)
public void setTables(java.util.List<DatabaseTable> theTables)
public void setUseUniqueFieldAliases(boolean useUniqueFieldAliases)
public boolean shouldDistinctBeUsed()
public void useDistinct()
public java.lang.String generatedAlias(java.lang.String fieldName)
public static java.util.SortedSet mapTableIndexToExpression(Expression expression, java.util.TreeMap map, java.util.List<DatabaseTable> tablesInOrder)
public static java.util.Map mapTableToExpression(Expression expression, java.util.Vector tablesInOrder)
EclipseLink 2.6.3, "build v20160428-59c81c5" API Reference