public class SQLSelectStatement extends SQLStatement
Purpose: Print SELECT statement.
Responsibilities:
Modifier and Type | Field and Description |
---|---|
protected Expression |
connectByExpression |
protected DatabaseTable |
currentAlias |
protected int |
currentAliasNumber |
protected java.util.List |
descriptorsForMultitableInheritanceOnly |
protected short |
distinctState
Used for "Select Distinct" option.
|
protected java.util.Vector |
fields
Fields being selected (can include expressions).
|
protected ForUpdateClause |
forUpdateClause
Used for pessimistic locking ie.
|
protected java.util.Vector |
groupByExpressions
Group by clause for report queries.
|
protected Expression |
havingExpression
Having clause for report queries.
|
protected boolean |
isAggregateSelect
Used for report query or counts so we know how to treat distincts.
|
protected DatabaseTable |
lastTable |
protected java.util.Vector |
nonSelectFields
Fields not being selected (can include expressions).
|
protected java.util.Vector |
orderByExpressions
Order by clause for read all queries.
|
protected java.util.Vector |
orderSiblingsByExpressions |
protected java.util.Vector |
outerJoinedAdditionalJoinCriteria |
protected java.util.Vector |
outerJoinedExpressions
Used for DB2 style from clause outer joins.
|
protected java.util.Vector |
outerJoinedMappingCriteria |
protected SQLSelectStatement |
parentStatement
Used for subselects.
|
protected boolean |
requiresAliases
Variables used for aliasing and normalizing.
|
protected Expression |
startWithExpression
Used for Oracle Hierarchical Queries
|
protected java.util.Hashtable |
tableAliases |
protected java.util.Vector |
tables
Tables being selected from.
|
builder, translationRow, whereClause
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.
|
protected void |
addOrderByExpressionToSelectForDistinct()
When distinct is used with order by the ordered fields must be in the select clause.
|
void |
addTable(DatabaseTable table)
Add a table to the statement.
|
void |
appendFromClauseForInformixOuterJoin(ExpressionSQLPrinter printer,
java.util.Vector outerJoinedAliases)
ADVANCED:
If a platform is Informix, then the outer join must be in the FROM clause.
|
void |
appendFromClauseForOuterJoin(ExpressionSQLPrinter printer,
java.util.Vector outerJoinedAliases)
ADVANCED:
If a platform is DB2 or MySQL, then the outer join must be in the FROM clause.
|
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 |
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.
|
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.
|
protected boolean |
fieldsContainField(java.util.Vector fields,
Expression expression)
Check if the field from the field expression is already contained in the select clause of the statement.
|
Expression |
getConnectByExpression()
INTERNAL:
Return the CONNECT BY expression
|
int |
getCurrentAliasNumber()
Gets a unique id that will be used to alias the next table.
|
java.util.List |
getDescriptorsForMultitableInheritanceOnly() |
java.util.Vector |
getFields()
INTERNAL:
Return all the fields
|
protected ForUpdateClause |
getForUpdateClause() |
java.util.Vector |
getGroupByExpressions()
INTERNAL:
Return the group bys.
|
Expression |
getHavingExpression()
INTERNAL:
Return the having expression.
|
java.util.Vector |
getNonSelectFields()
Return the fields we don't want to select but want to join on.
|
java.util.Vector |
getOrderByExpressions()
INTERNAL:
Return the order expressions for the query.
|
java.util.Vector |
getOrderSiblingsByExpressions()
INTERNAL:
Return the ORDER SIBLINGS BY expression
|
java.util.Vector |
getOuterJoinedAdditionalJoinCriteria()
INTERNAL:
Each Vector's element is a map of tables join expressions keyed by the tables
|
java.util.Vector |
getOuterJoinedMappingCriteria() |
java.util.Vector |
getOuterJoinExpressions() |
SQLSelectStatement |
getParentStatement()
Return the parent statement if using subselects.
|
Expression |
getStartWithExpression()
INTERNAL:
Return the StartWith expression
|
java.util.Hashtable |
getTableAliases()
INTERNAL:
Return the aliases used.
|
java.util.Vector |
getTables()
INTERNAL:
Return all the tables.
|
protected boolean |
hasAliasForTable(DatabaseTable table) |
boolean |
hasConnectByExpression() |
boolean |
hasGroupByExpressions() |
boolean |
hasHavingExpression() |
boolean |
hasHierarchicalQueryExpressions() |
boolean |
hasNonSelectFields() |
boolean |
hasOrderByExpressions() |
boolean |
hasOrderSiblingsByExpressions() |
boolean |
hasOuterJoinedAdditionalJoinCriteria() |
boolean |
hasOuterJoinExpressions() |
boolean |
hasStartWithExpression() |
boolean |
isAggregateSelect()
INTERNAL:
|
boolean |
isDistinctComputed()
INTERNAL:
return true if this query has computed its distinct value already
|
boolean |
isSubSelect() |
protected static java.util.SortedSet |
mapTableIndexToExpression(Expression expression,
java.util.SortedMap map,
java.util.Vector 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.Dictionary clonedExpressions)
INTERNAL:
Normalize an expression into a printable structure.
|
void |
normalizeForView(AbstractSession theSession,
ClassDescriptor theDescriptor,
java.util.Dictionary clonedExpressions)
INTERNAL:
Normalize an expression mapping all of the descriptor's tables to the view.
|
protected void |
printAdditionalJoins(ExpressionSQLPrinter printer,
java.util.Vector outerJoinedAliases,
ClassDescriptor desc,
java.util.Map tablesJoinExpressions) |
java.util.Vector |
printSQL(ExpressionSQLPrinter printer)
Print the SQL representation of the statement on a stream.
|
void |
rebuildAndAddExpressions(java.util.Map expressions,
java.util.Vector allExpressions,
ExpressionBuilder primaryBuilder,
java.util.Dictionary clonedExpressions)
Rebuild the expressions with the correct expression builder if using a different one.
|
void |
rebuildAndAddExpressions(java.util.Vector expressions,
java.util.Vector allExpressions,
ExpressionBuilder primaryBuilder,
java.util.Dictionary clonedExpressions)
Rebuild the expressions with the correct expression builder if using a different one.
|
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 |
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.
|
protected void |
setForUpdateClause(ForUpdateClause clause) |
void |
setGroupByExpressions(java.util.Vector expressions) |
void |
setHavingExpression(Expression expressions) |
void |
setHierarchicalQueryExpressions(Expression startWith,
Expression connectBy,
java.util.Vector 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 |
setIsAggregateSelect(boolean isAggregateSelect) |
void |
setLockingClause(ForUpdateClause lockingClause) |
void |
setNonSelectFields(java.util.Vector nonSelectFields)
Set the non select fields.
|
void |
setNormalizedWhereClause(Expression whereClause)
Set the where clause expression.
|
void |
setOrderByExpressions(java.util.Vector orderByExpressions) |
void |
setOuterJoinedAdditionalJoinCriteria(java.util.Vector outerJoinedAdditionalJoinCriteria) |
void |
setOuterJoinedMappingCriteria(java.util.Vector outerJoinedMappingCriteria) |
void |
setOuterJoinExpressions(java.util.Vector outerJoinedExpressions) |
void |
setParentStatement(SQLSelectStatement parentStatement)
Set the parent statement if using subselects.
|
void |
setRequiresAliases(boolean requiresAliases) |
protected void |
setTableAliases(java.util.Hashtable theTableAliases) |
void |
setTables(java.util.Vector theTables) |
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.
|
protected void |
writeField(ExpressionSQLPrinter printer,
DatabaseField field)
INTERNAL:
|
protected void |
writeFieldsFromExpression(ExpressionSQLPrinter printer,
Expression expression,
java.util.Vector newFields)
INTERNAL:
|
protected java.util.Vector |
writeFieldsIn(ExpressionSQLPrinter printer)
INTERNAL:
|
clone, getBuilder, getExpressionBuilder, getTranslationRow, getWhereClause, setBuilder, setTranslationRow, setWhereClause, toString
protected java.util.Vector fields
protected java.util.Vector nonSelectFields
protected java.util.Vector tables
protected short distinctState
protected java.util.Vector orderByExpressions
protected java.util.Vector groupByExpressions
protected Expression havingExpression
protected ForUpdateClause forUpdateClause
protected boolean isAggregateSelect
protected java.util.Vector outerJoinedExpressions
protected java.util.Vector outerJoinedMappingCriteria
protected java.util.Vector outerJoinedAdditionalJoinCriteria
protected java.util.List descriptorsForMultitableInheritanceOnly
protected Expression startWithExpression
protected Expression connectByExpression
protected java.util.Vector orderSiblingsByExpressions
protected boolean requiresAliases
protected java.util.Hashtable tableAliases
protected DatabaseTable lastTable
protected DatabaseTable currentAlias
protected int currentAliasNumber
protected SQLSelectStatement parentStatement
public void addField(DatabaseField field)
public void addField(Expression expression)
protected void addOrderByExpressionToSelectForDistinct()
public void addTable(DatabaseTable table)
public void appendFromClauseForInformixOuterJoin(ExpressionSQLPrinter printer, java.util.Vector outerJoinedAliases) throws java.io.IOException
java.io.IOException
public void appendFromClauseForOuterJoin(ExpressionSQLPrinter printer, java.util.Vector outerJoinedAliases) throws java.io.IOException
java.io.IOException
protected void printAdditionalJoins(ExpressionSQLPrinter printer, java.util.Vector outerJoinedAliases, ClassDescriptor desc, java.util.Map tablesJoinExpressions) 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 assignAliases(java.util.Vector allExpressions)
public DatabaseCall buildCall(AbstractSession session)
buildCall
in class SQLStatement
public void computeDistinct()
public boolean isSubSelect()
public void computeTables()
public void computeTablesFromTables()
public void dontUseDistinct()
protected boolean fieldsContainField(java.util.Vector fields, Expression expression)
public int getCurrentAliasNumber()
public java.util.Vector getFields()
protected ForUpdateClause getForUpdateClause()
public java.util.Vector getGroupByExpressions()
public Expression getHavingExpression()
public Expression getStartWithExpression()
public Expression getConnectByExpression()
public java.util.Vector getOrderSiblingsByExpressions()
public java.util.Vector getNonSelectFields()
public java.util.Vector getOrderByExpressions()
public java.util.Vector getOuterJoinedAdditionalJoinCriteria()
public java.util.Vector getOuterJoinedMappingCriteria()
public java.util.Vector getOuterJoinExpressions()
public java.util.List getDescriptorsForMultitableInheritanceOnly()
public SQLSelectStatement getParentStatement()
public java.util.Hashtable getTableAliases()
public java.util.Vector getTables()
protected boolean hasAliasForTable(DatabaseTable table)
public boolean hasGroupByExpressions()
public boolean hasHavingExpression()
public boolean hasStartWithExpression()
public boolean hasConnectByExpression()
public boolean hasOrderSiblingsByExpressions()
public boolean hasHierarchicalQueryExpressions()
public boolean hasOrderByExpressions()
public boolean hasNonSelectFields()
public boolean hasOuterJoinedAdditionalJoinCriteria()
public boolean hasOuterJoinExpressions()
public boolean isAggregateSelect()
public boolean isDistinctComputed()
public final void normalize(AbstractSession session, ClassDescriptor descriptor)
clonedExpressions
- public void normalize(AbstractSession session, ClassDescriptor descriptor, java.util.Dictionary 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.Dictionary clonedExpressions)
public java.util.Vector printSQL(ExpressionSQLPrinter printer)
public void rebuildAndAddExpressions(java.util.Vector expressions, java.util.Vector allExpressions, ExpressionBuilder primaryBuilder, java.util.Dictionary clonedExpressions)
public void rebuildAndAddExpressions(java.util.Map expressions, java.util.Vector allExpressions, ExpressionBuilder primaryBuilder, java.util.Dictionary clonedExpressions)
public void removeField(DatabaseField field)
public void removeTable(DatabaseTable table)
public boolean requiresAliases()
public void resetDistinct()
public void setCurrentAliasNumber(int currentAliasNumber)
public void setNonSelectFields(java.util.Vector nonSelectFields)
public void setNormalizedWhereClause(Expression whereClause)
public void setDistinctState(short distinctState)
public void setFields(java.util.Vector fields)
public void setGroupByExpressions(java.util.Vector expressions)
public void setHavingExpression(Expression expressions)
public void setHierarchicalQueryExpressions(Expression startWith, Expression connectBy, java.util.Vector orderSiblingsExpressions)
public void setIsAggregateSelect(boolean isAggregateSelect)
protected void setForUpdateClause(ForUpdateClause clause)
public void setLockingClause(ForUpdateClause lockingClause)
public void setOrderByExpressions(java.util.Vector orderByExpressions)
public void setOuterJoinedAdditionalJoinCriteria(java.util.Vector outerJoinedAdditionalJoinCriteria)
public void setOuterJoinedMappingCriteria(java.util.Vector outerJoinedMappingCriteria)
public void setOuterJoinExpressions(java.util.Vector outerJoinedExpressions)
public void setParentStatement(SQLSelectStatement parentStatement)
public void setRequiresAliases(boolean requiresAliases)
protected void setTableAliases(java.util.Hashtable theTableAliases)
public void setTables(java.util.Vector theTables)
public boolean shouldDistinctBeUsed()
public void useDistinct()
protected void writeField(ExpressionSQLPrinter printer, DatabaseField field)
protected void writeFieldsFromExpression(ExpressionSQLPrinter printer, Expression expression, java.util.Vector newFields)
protected java.util.Vector writeFieldsIn(ExpressionSQLPrinter printer)
protected static java.util.SortedSet mapTableIndexToExpression(Expression expression, java.util.SortedMap map, java.util.Vector tablesInOrder)
public static java.util.Map mapTableToExpression(Expression expression, java.util.Vector tablesInOrder)