Top Description Fields Constructors Methods
org.eclipse.persistence.internal.expressions

public Class SQLSelectStatement

extends SQLStatement
Class Inheritance
Static Imports
org.eclipse.persistence.queries.ReadAllQuery.Direction.CHILD_TO_PARENT

Purpose: Print SELECT statement.

Responsibilities:

Author
Dorin Sandu
Since
TOPLink/Java 1.0

Field Summary

Modifier and TypeField and Description
protected Expression
protected DatabaseTable
protected int
protected ReadAllQuery.Direction
protected short
distinctState

Used for "Select Distinct" option.

protected Map<DatabaseField, String>
fieldAliases

Used for caching the field alias written to the query

protected int
fieldCounter

Counter to generate unique alias names

protected Vector<E>
fields

Fields being selected (can include expressions).

protected ForUpdateClause
forUpdateClause

Used for pessimistic locking ie.

protected List<Expression>
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
protected List<Object>
nonSelectFields

Fields not being selected (can include expressions).

protected Map<Expression, Expression>
optimizedClonedExpressions

It is used by subselect to re-normalize joins

protected List<Expression>
orderByExpressions

Order by clause for read all queries.

protected List<Expression>
protected List<OuterJoinExpressionHolder>
outerJoinExpressionHolders

Used for DB2 style from clause outer joins.

protected SQLSelectStatement
parentStatement

Used for subselects.

protected ReadQuery
query

Query this statement is associated to (used for SQL query options).

protected boolean
requiresAliases

Variables used for aliasing and normalizing.

protected boolean
protected Expression
startWithExpression

Used for Oracle Hierarchical Queries

protected Map<DatabaseTable, DatabaseTable>
protected List<DatabaseTable>
tables

Tables being selected from.

protected List<Expression>
unionExpressions

Union clause.

protected boolean
useUniqueFieldAliases

Flag used to indicate field names should use unique aliases

Inherited from org.eclipse.persistence.internal.expressions.SQLStatement:
builderhintStringtranslationRowwhereClause

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
public void
addField(Expression expression)

INTERNAL: adds an expression to the fields.

public void
addOptimizedClonedExpressions(Expression originalKey, Expression optimizedValue)

INTERNAL: It is used by subqueries to avoid duplicate joins.

protected void
addOrderByExpressionToSelectForDistinct()

When distinct is used with order by the ordered fields must be in the select clause.

public Integer
addOuterJoinExpressionsHolders(ObjectExpression
- expression resulting in the outerjoin. Null if it is for inheritance reading of subclasses
joinExpression
,
Expression
- used for querykey mapping expressions
outerJoinedMappingCriteria
,
Map<DatabaseTable, Expression>
- additional tables/expressions to join. Usually for multitableInheritance join expressions
outerJoinedAdditionalJoinCriteria
,
ClassDescriptor
- descriptor to use if this is for reading in subclasses in one query.
descriptor
)

INTERNAL: Used by ExpressionBuilder and QueryKeyExpression normalization to create a standard outerjoin.

public Integer
addOuterJoinExpressionsHolders(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

public void
addTable(DatabaseTable table)

Add a table to the statement.

public void
appendForUpdateClause(ExpressionSQLPrinter printer)

This method will append the for update clause to the end of the select statement.

public void
appendFromClauseForInformixOuterJoin(ExpressionSQLPrinter printer, List<DatabaseTable> outerJoinedAliases)

ADVANCED: If a platform is Informix, then the outer join must be in the FROM clause.

public void
appendFromClauseForOuterJoin(ExpressionSQLPrinter printer, List<DatabaseTable> outerJoinedAliases, Collection<E> aliasesOfTablesToBeLocked, boolean shouldPrintUpdateClauseForAllTables)

ADVANCED: Appends the SQL standard outer join clause, and some variation per platform.

public void
appendFromClauseToWriter(ExpressionSQLPrinter printer)

Print the from clause.

public void
appendGroupByClauseToWriter(ExpressionSQLPrinter printer)

This method will append the group by clause to the end of the select statement.

public void
appendHierarchicalQueryClauseToWriter(ExpressionSQLPrinter printer)

This method will append the Hierarchical Query Clause to the end of the select statement

public void
appendOrderClauseToWriter(ExpressionSQLPrinter printer)

This method will append the order clause to the end of the select statement.

public void
appendUnionClauseToWriter(ExpressionSQLPrinter printer)

This method will append the union clause to the end of the select statement.

public void
assignAliases(Vector<E> allExpressions)

INTERNAL: Alias the tables in all of our nodes.

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.

public DatabaseCall
buildCall(AbstractSession session)

Implements abstract org.eclipse.persistence.internal.expressions.SQLStatement.buildCall.

Print the SQL representation of the statement on a stream.
public void
computeDistinct()

INTERNAL: This is used by cursored stream to determine if an expression used distinct as the size must account for this.

public void
computeTables()

INTERNAL: Computes all aliases which will appear in the FROM clause.

public void
computeTablesFromTables()

If there is no where clause, alias the tables from the tables list directly.

public void
dontUseDistinct()

ADVANCED: If a distinct has been set the DISTINCT clause will be printed.

public void
protected boolean
fieldsContainField(List<E> fields, Expression expression)

Check if the field from the field expression is already contained in the select clause of the statement.

public String
generatedAlias(String fieldName)

Returns a generated alias based on the column name.

public String
public Expression
getConnectByExpression()

INTERNAL: Return the CONNECT BY expression

public int
getCurrentAliasNumber()

Gets a unique id that will be used to alias the next table.

public ReadAllQuery.Direction

Returns:

the position of the PRIOR keyword
getDirection
()

INTERNAL:

public Vector<E>
getFields()

INTERNAL: Return all the fields

protected ForUpdateClause
public List<Expression>
getGroupByExpressions()

INTERNAL: Return the group bys.

public Expression
getHavingExpression()

INTERNAL: Return the having expression.

public int
getNextFieldCounterValue()

INTERNAL: Return the next value of fieldCounter

public List<Object>
getNonSelectFields()

Return the fields we don't want to select but want to join on.

public Map<Expression, Expression>
getOptimizedClonedExpressions()

INTERNAL: It is used by subqueries to avoid duplicate joins.

public List<Expression>
getOrderByExpressions()

INTERNAL: Return the order expressions for the query.

public List<Expression>
getOrderSiblingsByExpressions()

INTERNAL: Return the ORDER SIBLINGS BY expression

public List<OuterJoinExpressionHolder>
getOuterJoinExpressionsHolders()

INTERNAL: returns outerJoinExpressionHolders representing outerjoin expressions.

public SQLSelectStatement
getParentStatement()

Return the parent statement if using subselects.

public ReadQuery
getQuery()

INTERNAL: Query held as it may store properties needed to generate the SQL

public Expression
getStartWithExpression()

INTERNAL: Return the StartWith expression

public Map<DatabaseTable, DatabaseTable>
getTableAliases()

INTERNAL: Return the aliases used.

public List<DatabaseTable>
getTables()

INTERNAL: Return all the tables.

public List<Expression>
public boolean
getUseUniqueFieldAliases()

INTERNAL: Return True if unique field aliases will be generated of the form "fieldname AS fieldnameX", False otherwise.

protected boolean
public boolean
public boolean
public boolean
public boolean
public boolean
public boolean
public boolean
public boolean
public boolean
public boolean
public boolean
isAggregateSelect()

INTERNAL:

public boolean
isDistinctComputed()

INTERNAL: return true if this query has computed its distinct value already

public boolean
public static SortedSet<E>
mapTableIndexToExpression(Expression expression, TreeMap<K, V> map, List<DatabaseTable> tablesInOrder)

INTERNAL: The method searches for expressions that join two tables each in a given expression.

public static Map<K, V>
mapTableToExpression(Expression expression, Vector<E> tablesInOrder)

INTERNAL: The method searches for expressions that join two tables each in a given expression.

public final void
normalize(AbstractSession session, ClassDescriptor descriptor)

INTERNAL: Normalize an expression into a printable structure.

public void
normalize(AbstractSession session, ClassDescriptor descriptor, Map<K, V>
With 2612185 allows additional expressions from multiple bases to be rebuilt on the correct cloned base.
clonedExpressions
)

INTERNAL: Normalize an expression into a printable structure.

public void
normalizeForView(AbstractSession theSession, ClassDescriptor theDescriptor, Map<K, V> clonedExpressions)

INTERNAL: Normalize an expression mapping all of the descriptor's tables to the view.

protected void
normalizeOrderBy(Expression builder, List<Expression> allExpressions, Map<Expression, Expression> clonedExpressions, AbstractSession session)

Check the order by for object expressions.

protected void
printForUpdateClauseOnJoin(DatabaseTable alias, ExpressionSQLPrinter printer, boolean shouldPrintUpdateClauseForAllTables, Collection<E> aliasesOfTablesToBeLocked, DatabasePlatform platform)

Print the FOR UPDATE clause after each join if required.

protected void
printOnClause(Expression onClause, ExpressionSQLPrinter printer, DatabasePlatform platform)

Print the outer join ON clause.

public Vector<DatabaseField>
printSQL(ExpressionSQLPrinter printer)

Print the SQL representation of the statement on a stream.

public void
public void
public void
public void
public void
public Vector<DatabaseField>
public void
public void
public void
public void
rebuildAndAddExpressions(List<E> expressions, List<E> allExpressions, ExpressionBuilder primaryBuilder, Map<K, V> clonedExpressions)

Rebuild the expressions with the correct expression builder if using a different one.

public void
rebuildAndAddExpressions(Map<K, V> expressions, Vector<E> allExpressions, ExpressionBuilder primaryBuilder, Map<K, V> clonedExpressions)

Rebuild the expressions with the correct expression builder if using a different one.

public Expression
rebuildExpression(Expression expression, Expression primaryBuilder, Map<Expression, Expression> clonedExpressions)

Rebuild the expression if required.

public void
removeField(DatabaseField field)

INTERNAL:

public void
removeTable(DatabaseTable table)

Remove a table from the statement.

public boolean
requiresAliases()

INTERNAL: Returns true if aliases are required, false otherwise.

public void
resetDistinct()

ADVANCED: If a distinct has been set the DISTINCT clause will be printed.

public void
public void
setCurrentAliasNumber(int currentAliasNumber)

Sets a unique id that will be used to alias the next table.

public void
setDistinctState(short distinctState)

ADVANCED: If a distinct has been set the DISTINCT clause will be printed.

public void
setFields(Vector<E> fields)

INTERNAL: Set the fields, if any are aggregate selects then record this so that the distinct is not printed through anyOfs.

protected void
public void
public void
public void
setHierarchicalQueryExpressions(Expression startWith, Expression connectBy, 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

public void
setHierarchicalQueryExpressions(Expression startWith, Expression connectBy, 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

public void
setIsAggregateSelect(boolean isAggregateSelect)

public void
public void
setNonSelectFields(List<E> nonSelectFields)

Set the non select fields.

public void
setNormalizedWhereClause(Expression whereClause)

Set the where clause expression.

public void
setOrderByExpressions(List<Expression> orderByExpressions)

public void
setParentStatement(SQLSelectStatement parentStatement)

Set the parent statement if using subselects.

public void
setQuery(ReadQuery query)

Query held as it may store properties needed to generate the SQL

public void
setRequiresAliases(boolean requiresAliases)

protected void
public void
public void
setUnionExpressions(List<Expression> unionExpressions)

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

private boolean
public boolean
shouldDistinctBeUsed()

INTERNAL: If a distinct has been set the DISTINCT clause will be printed.

protected void
public void
useDistinct()

ADVANCED: If a distinct has been set the DISTINCT clause will be printed.

protected void
protected void
protected Vector<DatabaseField>
Inherited from org.eclipse.persistence.internal.expressions.SQLStatement:
clonegetBuildergetExpressionBuildergetHintStringgetTranslationRowgetWhereClausesetHintStringsetTranslationRowsetWhereClausetoString