EclipseLink 2.2.0, build 'v20110202-r8913' API Reference

org.eclipse.persistence.expressions
Class ExpressionBuilder

java.lang.Object
  extended by org.eclipse.persistence.expressions.Expression
      extended by org.eclipse.persistence.internal.expressions.BaseExpression
          extended by org.eclipse.persistence.internal.expressions.DataExpression
              extended by org.eclipse.persistence.internal.expressions.ObjectExpression
                  extended by org.eclipse.persistence.expressions.ExpressionBuilder
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public class ExpressionBuilder
extends org.eclipse.persistence.internal.expressions.ObjectExpression

Purpose: Allow for instances of expression to be created. Expressions are Java object-level representations of SQL "where" clauses. The expressions attempt to mirror Java code as closely as possible.

Example:

ExpressionBuilder employee = new ExpressionBuilder(); employee.get("firstName").equal("Bob").and(employee.get("lastName").equal("Smith")) >> equivalent Java code: (employee.getFirstName().equals("Bob")) && (employee.getLastName().equals("Smith")) >> equivalent SQL: (F_NAME = 'Bob') AND (L_NAME = 'Smith')

See Also:
Expression, Serialized Form

Field Summary
protected  org.eclipse.persistence.internal.helper.DatabaseTable aliasedViewTable
           
protected  java.lang.Class queryClass
           
protected  org.eclipse.persistence.internal.sessions.AbstractSession session
           
protected  org.eclipse.persistence.internal.expressions.SQLSelectStatement statement
           
protected  org.eclipse.persistence.internal.helper.DatabaseTable viewTable
           
protected  boolean wasAdditionJoinCriteriaUsed
           
protected  boolean wasQueryClassSetInternally
           
 
Fields inherited from class org.eclipse.persistence.internal.expressions.ObjectExpression
castClass, derivedExpressions, descriptor, shouldUseOuterJoin, shouldUseOuterJoinForMultitableInheritance
 
Fields inherited from class org.eclipse.persistence.internal.expressions.DataExpression
asOfClause, derivedFields, derivedTables, hasBeenNormalized, tableAliases
 
Fields inherited from class org.eclipse.persistence.internal.expressions.BaseExpression
baseExpression, builder
 
Fields inherited from class org.eclipse.persistence.expressions.Expression
currentAlias, hashCode, lastTable, selectIfOrderedBy
 
Constructor Summary
ExpressionBuilder()
          PUBLIC: Create a new ExpressionBuilder.
ExpressionBuilder(java.lang.Class queryClass)
          ADVANCED: Create a new ExpressionBuilder representing instances of the argument class.
 
Method Summary
 org.eclipse.persistence.internal.helper.DatabaseTable aliasForTable(org.eclipse.persistence.internal.helper.DatabaseTable table)
          INTERNAL: Find the alias for a given table.
 int assignTableAliasesStartingAt(int initialValue)
          INTERNAL: Assign aliases to any tables which I own.
 java.lang.String descriptionOfNodeType()
          INTERNAL: Used for debug printing.
 boolean doesNotRepresentAnObjectInTheQuery()
          INTERNAL: There are cases (which we might want to eliminate?)
 boolean equals(java.lang.Object expression)
          INTERNAL: Return if the expression is equal to the other.
 org.eclipse.persistence.internal.helper.DatabaseTable getAliasedViewTable()
          INTERNAL:
 ExpressionBuilder getBuilder()
          INTERNAL: Return the expression builder which is the ultimate base of this expression, or null if there isn't one (shouldn't happen if we start from a root)
 ClassDescriptor getDescriptor()
          INTERNAL: Only usable after the session and class have been set.
 java.lang.Class getQueryClass()
          INTERNAL:
 org.eclipse.persistence.internal.sessions.AbstractSession getSession()
          INTERNAL:
 org.eclipse.persistence.internal.expressions.SQLSelectStatement getStatement()
          INTERNAL: Return the statement that expression is for.
 org.eclipse.persistence.internal.helper.DatabaseTable getViewTable()
          INTERNAL:
 boolean hasViewTable()
          INTERNAL:
 boolean isExpressionBuilder()
          INTERNAL:
 Expression normalize(org.eclipse.persistence.internal.expressions.ExpressionNormalizer normalizer)
          INTERNAL: Normalize the expression into a printable structure.
 void printJava(org.eclipse.persistence.internal.expressions.ExpressionJavaPrinter printer)
          INTERNAL: Print java
 Expression rebuildOn(Expression newBase)
          INTERNAL: This expression is built on a different base than the one we want.
protected  Expression registerIn(java.util.Map alreadyDone)
          INTERNAL: Override Expression.registerIn to check if the new base expression has already been provided for the clone.
 void resetPlaceHolderBuilder(ExpressionBuilder queryBuilder)
          INTERNAL: Search the tree for any expressions (like SubSelectExpressions) that have been built using a builder that is not attached to the query.
 void setQueryClass(java.lang.Class queryClass)
          INTERNAL: Set the class which this node represents.
 void setQueryClassAndDescriptor(java.lang.Class queryClass, ClassDescriptor descriptor)
          INTERNAL: Set the class and descriptor which this node represents.
 void setSession(org.eclipse.persistence.internal.sessions.AbstractSession session)
          INTERNAL: Set the session in which we expect this expression to be translated.
 void setStatement(org.eclipse.persistence.internal.expressions.SQLSelectStatement statement)
          INTERNAL: Set the statement that expression is for.
 void setViewTable(org.eclipse.persistence.internal.helper.DatabaseTable theTable)
          INTERNAL: This expression represents something read through a view table.
 void setWasAdditionJoinCriteriaUsed(boolean joinCriteriaUsed)
          INTERNAL: If the additional Join Criteria for the class this builder represents has been added to the statement then mark this as true.
 Expression twistedForBaseAndContext(Expression newBase, Expression context)
          INTERNAL: Rebuild myself against the base, with the values of parameters supplied by the context expression.
 java.lang.Object valueFromObject(java.lang.Object object, org.eclipse.persistence.internal.sessions.AbstractSession session, org.eclipse.persistence.internal.sessions.AbstractRecord translationRow, int valueHolderPolicy, boolean isObjectUnregistered)
          INTERNAL: The expression builder represent the entire object, just return it.
 boolean wasAdditionJoinCriteriaUsed()
          INTERNAL: If the additional Join Criteria for the class this builder represents has been added to the statement this method will return true;
 boolean wasQueryClassSetInternally()
          INTERNAL: Returns true if TopLink set the query class as opposed to the customer.
 void writeDescriptionOn(java.io.BufferedWriter writer)
          INTERNAL: For debug printing purposes.
 
Methods inherited from class org.eclipse.persistence.internal.expressions.ObjectExpression
addDerivedExpression, additionalExpressionCriteria, additionalExpressionCriteriaMap, anyOf, anyOfAllowingNone, as, convertToCastDescriptor, derivedExpressionNamed, derivedManualExpressionNamed, doNotUseOuterJoin, doUseOuterJoin, existingDerivedExpressionNamed, get, getAdditionalTables, getAllowingNull, getCastClass, getFields, getForUpdateOfFields, getManualQueryKey, getOwnedTables, hasDerivedExpressions, isObjectExpression, isUsingOuterJoinForMultitableInheritance, newDerivedExpressionNamed, newManualDerivedExpressionNamed, postCopyIn, postCopyIn, setCastClass, setShouldUseOuterJoinForMultitableInheritance, shouldUseOuterJoin, shouldUseOuterJoinForMultitableInheritance, type, writeForUpdateOfFields
 
Methods inherited from class org.eclipse.persistence.internal.expressions.DataExpression
addDerivedField, addDerivedTable, asOf, assignAlias, assignAlias, clearAliases, copyCollection, existingDerivedField, existingDerivedTable, getAliasedField, getAsOfClause, getField, getField, getField, getMapping, getQueryKeyOrNull, getTable, getTable, getTableAliases, hasAsOfClause, hasBeenAliased, hasBeenNormalized, hasDerivedFields, hasDerivedTables, isAttribute, isDataExpression, iterateOn, mappingCriteria, newDerivedField, newDerivedTable, printSQL, setHasBeenNormalized, setTableAliases, tableAliasesDescription, writeSubexpressionsTo
 
Methods inherited from class org.eclipse.persistence.internal.expressions.BaseExpression
getBaseExpression, setBaseExpression, shallowClone
 
Methods inherited from class org.eclipse.persistence.expressions.Expression
addDate, addDate, addMonths, addMonths, all, all, all, all, all, all, all, all, all, all, all, all, allOf, and, any, any, any, any, any, any, any, any, any, any, any, any, ascending, asciiValue, average, between, between, between, between, between, between, between, between, between, caseConditionStatement, caseConditionStatement, caseStatement, caseStatement, clone, cloneUsing, coalesce, coalesce, computeHashCode, concat, containsAllKeyWords, containsAnyKeyWords, containsSubstring, containsSubstring, containsSubstringIgnoringCase, containsSubstringIgnoringCase, convertNodeToUseOuterJoin, convertToUseOuterJoin, copiedVersionFrom, count, create, create, createWithBaseLast, currentDate, currentDateDate, currentTime, currentTimeStamp, dateDifference, dateDifference, dateName, datePart, dateToString, decode, descending, detectExpression, difference, distinct, doesConform, doesConform, equal, equal, equal, equal, equal, equal, equal, equal, equal, equal, equalOuterJoin, equalOuterJoin, equalsIgnoreCase, equalsIgnoreCase, exists, existsNode, extract, extractPrimaryKeyFields, extractPrimaryKeyValues, extractValue, from, fromConstant, fromLiteral, get, getAllowingNull, getAsOfClauseRecursively, getClonedField, getFieldValue, getFunction, getFunction, getFunction, getFunction, getFunctionWithArguments, getName, getNumberVal, getOperator, getOperator, getParameter, getParameter, getParameter, getStringVal, greaterThan, greaterThan, greaterThan, greaterThan, greaterThan, greaterThan, greaterThan, greaterThan, greaterThan, greaterThan, greaterThanEqual, greaterThanEqual, greaterThanEqual, greaterThanEqual, greaterThanEqual, greaterThanEqual, greaterThanEqual, greaterThanEqual, greaterThanEqual, greaterThanEqual, hashCode, hexToRaw, ifNull, in, in, in, in, in, in, in, in, in, in, in, in, index, indexOf, isClassTypeExpression, isCompoundExpression, isConstantExpression, isEmpty, isFieldExpression, isFragment, isFunctionExpression, isLiteralExpression, isLogicalExpression, isMapEntryExpression, isNull, isParameterExpression, isQueryKeyExpression, isRelationExpression, isTableExpression, isValueExpression, lastDay, leftPad, leftPad, leftTrim, leftTrim, length, lessThan, lessThan, lessThan, lessThan, lessThan, lessThan, lessThan, lessThan, lessThan, lessThan, lessThanEqual, lessThanEqual, lessThanEqual, lessThanEqual, lessThanEqual, lessThanEqual, lessThanEqual, lessThanEqual, lessThanEqual, lessThanEqual, like, like, like, like, likeIgnoreCase, likeIgnoreCase, literal, locate, locate, locate, mapEntry, mapKey, maximum, minimum, monthsBetween, newTime, nextDay, noneOf, not, notBetween, notBetween, notBetween, notBetween, notBetween, notBetween, notBetween, notBetween, notBetween, notEmpty, notEqual, notEqual, notEqual, notEqual, notEqual, notEqual, notEqual, notEqual, notEqual, notEqual, notExists, notIn, notIn, notIn, notIn, notIn, notIn, notIn, notIn, notIn, notIn, notIn, notIn, notLike, notLike, notLike, notLike, notNull, nullIf, or, performOperator, postfixSQL, prefixSQL, ref, replace, replicate, replicate, resetCache, reverse, right, right, rightPad, rightPad, rightTrim, rightTrim, roundDate, selectIfOrderedBy, setLocalBase, setSelectIfOrderedBy, size, size, some, some, some, some, some, some, some, some, some, some, some, some, standardDeviation, subQuery, substring, substring, substring, substring, sum, toChar, toChar, toCharacter, toDate, toLowerCase, toNumber, toString, toString, toUpperCase, toUppercaseCasedWords, translate, trim, trim, truncateDate, twist, validateNode, value, value, value, value, value, value, value, value, value, value, valueFromObject, variance, writeAlias, writeField, writeFields
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

session

protected transient org.eclipse.persistence.internal.sessions.AbstractSession session

queryClass

protected java.lang.Class queryClass

statement

protected org.eclipse.persistence.internal.expressions.SQLSelectStatement statement

viewTable

protected org.eclipse.persistence.internal.helper.DatabaseTable viewTable

aliasedViewTable

protected org.eclipse.persistence.internal.helper.DatabaseTable aliasedViewTable

wasQueryClassSetInternally

protected boolean wasQueryClassSetInternally

wasAdditionJoinCriteriaUsed

protected boolean wasAdditionJoinCriteriaUsed
Constructor Detail

ExpressionBuilder

public ExpressionBuilder()
PUBLIC: Create a new ExpressionBuilder.


ExpressionBuilder

public ExpressionBuilder(java.lang.Class queryClass)
ADVANCED: Create a new ExpressionBuilder representing instances of the argument class. This can be used for the purpose of parallel expressions. This is a type of query that searches on the relationship between to un-related objects.

Method Detail

equals

public boolean equals(java.lang.Object expression)
INTERNAL: Return if the expression is equal to the other. This is used to allow dynamic expression's SQL to be cached.

Overrides:
equals in class org.eclipse.persistence.internal.expressions.ObjectExpression

aliasForTable

public org.eclipse.persistence.internal.helper.DatabaseTable aliasForTable(org.eclipse.persistence.internal.helper.DatabaseTable table)
INTERNAL: Find the alias for a given table. Handle the special case where we are bogus and it should be aliased against our derived tables instead.

Overrides:
aliasForTable in class org.eclipse.persistence.internal.expressions.DataExpression

assignTableAliasesStartingAt

public int assignTableAliasesStartingAt(int initialValue)
INTERNAL: Assign aliases to any tables which I own. Start with t(initialValue), and return the new value of the counter , i.e. if initialValue is one and I have tables ADDRESS and EMPLOYEE I will assign them t1 and t2 respectively, and return 3.

Overrides:
assignTableAliasesStartingAt in class Expression

descriptionOfNodeType

public java.lang.String descriptionOfNodeType()
INTERNAL: Used for debug printing.

Overrides:
descriptionOfNodeType in class Expression

doesNotRepresentAnObjectInTheQuery

public boolean doesNotRepresentAnObjectInTheQuery()
INTERNAL: There are cases (which we might want to eliminate?) where the expression builder doesn't actually correspond to an object to be read. Mostly this is the case where it's a data query in terms of tables, and the builder is only there to provide a base. It might be better to make tables able to serve as their own base, but it's very nice to have a known unique, shared base. In the meantime, this is a special case to make sure the builder doesn't get tables assigned.


getAliasedViewTable

public org.eclipse.persistence.internal.helper.DatabaseTable getAliasedViewTable()
INTERNAL:


getBuilder

public ExpressionBuilder getBuilder()
INTERNAL: Return the expression builder which is the ultimate base of this expression, or null if there isn't one (shouldn't happen if we start from a root)

Overrides:
getBuilder in class org.eclipse.persistence.internal.expressions.BaseExpression

getDescriptor

public ClassDescriptor getDescriptor()
INTERNAL: Only usable after the session and class have been set. Return the descriptor for the class this node represents.

Overrides:
getDescriptor in class org.eclipse.persistence.internal.expressions.ObjectExpression

getQueryClass

public java.lang.Class getQueryClass()
INTERNAL:


getSession

public org.eclipse.persistence.internal.sessions.AbstractSession getSession()
INTERNAL:

Overrides:
getSession in class Expression

getStatement

public org.eclipse.persistence.internal.expressions.SQLSelectStatement getStatement()
INTERNAL: Return the statement that expression is for. This is used for the context in subselects.


getViewTable

public org.eclipse.persistence.internal.helper.DatabaseTable getViewTable()
INTERNAL:


hasViewTable

public boolean hasViewTable()
INTERNAL:


isExpressionBuilder

public boolean isExpressionBuilder()
INTERNAL:

Overrides:
isExpressionBuilder in class Expression

normalize

public Expression normalize(org.eclipse.persistence.internal.expressions.ExpressionNormalizer normalizer)
INTERNAL: Normalize the expression into a printable structure. Any joins must be added to form a new root.

Overrides:
normalize in class org.eclipse.persistence.internal.expressions.DataExpression

printJava

public void printJava(org.eclipse.persistence.internal.expressions.ExpressionJavaPrinter printer)
INTERNAL: Print java

Overrides:
printJava in class Expression

rebuildOn

public Expression rebuildOn(Expression newBase)
INTERNAL: This expression is built on a different base than the one we want. Rebuild it and return the root of the new tree This assumes that the original expression has only a single builder.

Specified by:
rebuildOn in class Expression
See Also:
Expression.cloneUsing(Expression newBase)

resetPlaceHolderBuilder

public void resetPlaceHolderBuilder(ExpressionBuilder queryBuilder)
INTERNAL: Search the tree for any expressions (like SubSelectExpressions) that have been built using a builder that is not attached to the query. This happens in case of an Exists call using a new ExpressionBuilder(). This builder needs to be replaced with one from the query.

Overrides:
resetPlaceHolderBuilder in class org.eclipse.persistence.internal.expressions.BaseExpression

registerIn

protected Expression registerIn(java.util.Map alreadyDone)
INTERNAL: Override Expression.registerIn to check if the new base expression has already been provided for the clone.

Overrides:
registerIn in class Expression
See Also:
Expression.cloneUsing(Expression)
Related Bugs:
2637484 INVALID QUERY KEY EXCEPTION THROWN USING BATCH READS AND PARALLEL EXPRESSIONS

setQueryClass

public void setQueryClass(java.lang.Class queryClass)
INTERNAL: Set the class which this node represents.


setQueryClassAndDescriptor

public void setQueryClassAndDescriptor(java.lang.Class queryClass,
                                       ClassDescriptor descriptor)
INTERNAL: Set the class and descriptor which this node represents.


setSession

public void setSession(org.eclipse.persistence.internal.sessions.AbstractSession session)
INTERNAL: Set the session in which we expect this expression to be translated.


setStatement

public void setStatement(org.eclipse.persistence.internal.expressions.SQLSelectStatement statement)
INTERNAL: Set the statement that expression is for. This is used for the context in subselects.


setViewTable

public void setViewTable(org.eclipse.persistence.internal.helper.DatabaseTable theTable)
INTERNAL: This expression represents something read through a view table.


setWasAdditionJoinCriteriaUsed

public void setWasAdditionJoinCriteriaUsed(boolean joinCriteriaUsed)
INTERNAL: If the additional Join Criteria for the class this builder represents has been added to the statement then mark this as true. This will prevent TopLink from adding it again at normalization


twistedForBaseAndContext

public Expression twistedForBaseAndContext(Expression newBase,
                                           Expression context)
INTERNAL: Rebuild myself against the base, with the values of parameters supplied by the context expression. This is used for transforming a standalone expression (e.g. the join criteria of a mapping) into part of some larger expression. You normally would not call this directly, instead calling twist See the comment there for more details"

Overrides:
twistedForBaseAndContext in class Expression
Parameters:
newBase -
context -
Returns:

valueFromObject

public java.lang.Object valueFromObject(java.lang.Object object,
                                        org.eclipse.persistence.internal.sessions.AbstractSession session,
                                        org.eclipse.persistence.internal.sessions.AbstractRecord translationRow,
                                        int valueHolderPolicy,
                                        boolean isObjectUnregistered)
INTERNAL: The expression builder represent the entire object, just return it.

Overrides:
valueFromObject in class Expression
isObjectUnregistered - true if object possibly not a clone, but is being conformed against the unit of work cache.

wasAdditionJoinCriteriaUsed

public boolean wasAdditionJoinCriteriaUsed()
INTERNAL: If the additional Join Criteria for the class this builder represents has been added to the statement this method will return true;


wasQueryClassSetInternally

public boolean wasQueryClassSetInternally()
INTERNAL: Returns true if TopLink set the query class as opposed to the customer. This is important in determining if this Expression should be treated as a parallel expression during normalization


writeDescriptionOn

public void writeDescriptionOn(java.io.BufferedWriter writer)
                        throws java.io.IOException
INTERNAL: For debug printing purposes.

Overrides:
writeDescriptionOn in class Expression
Throws:
java.io.IOException

EclipseLink 2.2.0, build 'v20110202-r8913' API Reference