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

public abstract Class CompoundExpression

extends Expression
Class Inheritance
Known Direct Subclasses
org.eclipse.persistence.internal.expressions.LogicalExpression, org.eclipse.persistence.internal.expressions.RelationExpression
Imports
java.io.*, java.util.*, org.eclipse.persistence.exceptions.*, org.eclipse.persistence.history.*, org.eclipse.persistence.internal.helper.*, org.eclipse.persistence.expressions.*, org.eclipse.persistence.internal.databaseaccess.*

Abstract class for expression that have exactly two children, such as and/or and relations.

Field Summary

Modifier and TypeField and Description
protected ExpressionBuilder
protected Expression
protected ExpressionOperator
protected transient ExpressionOperator
protected Expression
Inherited from org.eclipse.persistence.expressions.Expression:
currentAliashashCodelastTableselectIfOrderedByshouldUseUpperCaseForIgnoreCase

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public DatabaseTable
aliasForTable(DatabaseTable table)

Overrides org.eclipse.persistence.expressions.Expression.aliasForTable.

INTERNAL: Find the alias for a given table from the first or second child in the additionalOuterJoinCriteria
public Expression
asOf(AsOfClause
A read only data object used to represent a past time.
clause
)

Overrides org.eclipse.persistence.expressions.Expression.asOf.

Sets all tables represented by this expression to be queried as of a past time.
public int
computeHashCode()

Overrides org.eclipse.persistence.expressions.Expression.computeHashCode.

INTERNAL: Compute a consistent hash-code for the expression.
public Expression
public Expression
public String
public boolean
equals(Object
the reference object with which to compare.
object
)

Overrides org.eclipse.persistence.expressions.Expression.equals.

INTERNAL: Return if the expression is equal to the other.
public ExpressionBuilder
getBuilder()

Implements abstract org.eclipse.persistence.expressions.Expression.getBuilder.

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)
public Expression
public ExpressionOperator
getOperator()

Overrides org.eclipse.persistence.expressions.Expression.getOperator.

INTERNAL: Most expression have operators, so this is just a convenience method.
public ExpressionOperator
public Expression
public void
public boolean
public void
iterateOn(ExpressionIterator iterator)

Overrides org.eclipse.persistence.expressions.Expression.iterateOn.

INTERNAL: For iterating using an inner class
public Expression
normalize(ExpressionNormalizer normalizer)

Overrides org.eclipse.persistence.expressions.Expression.normalize.

INTERNAL: Normalize into a structure that is printable.
protected void
postCopyIn(Map<K, V> alreadyDone)

Overrides org.eclipse.persistence.expressions.Expression.postCopyIn.

INTERNAL: Used for cloning.
public void
printJava(ExpressionJavaPrinter printer)

Overrides org.eclipse.persistence.expressions.Expression.printJava.

INTERNAL: Print java for project class generation
public void
public Expression
rebuildOn(Expression newBase)

Implements abstract org.eclipse.persistence.expressions.Expression.rebuildOn.

INTERNAL: This expression is built on a different base than the one we want.
public void
resetPlaceHolderBuilder(ExpressionBuilder queryBuilder)

Implements abstract org.eclipse.persistence.expressions.Expression.resetPlaceHolderBuilder.

INTERNAL: Search the tree for any expressions (like SubSelectExpressions) that have been built using a builder that is not attached to the query.
protected void
public void
protected void
public Expression
shallowClone()

Overrides org.eclipse.persistence.expressions.Expression.shallowClone.

INTERNAL: Clear the builder when cloning.
public Expression
twistedForBaseAndContext(Expression newBase, Expression context, Expression oldBase)

Overrides org.eclipse.persistence.expressions.Expression.twistedForBaseAndContext.

INTRENAL: Used to change an expression off of one base to an expression off of a different base.
public void
validateNode()

Overrides org.eclipse.persistence.expressions.Expression.validateNode.

Do any required validation for this node.
public void
writeDescriptionOn(BufferedWriter writer)

Overrides org.eclipse.persistence.expressions.Expression.writeDescriptionOn.

INTERNAL: Used to print a debug form of the expression tree.
public void
writeSubexpressionsTo(BufferedWriter writer, int indent)

Overrides org.eclipse.persistence.expressions.Expression.writeSubexpressionsTo.

INTERNAL: Used for toString for debugging only.
Inherited from org.eclipse.persistence.expressions.Expression:
addDateaddDateaddMonthsaddMonthsaliasallallallallallallallallallallallallallOfandanyanyanyanyanyanyanyanyanyanyanyanyanyOfanyOfanyOfAllowingNoneanyOfAllowingNoneasascendingasciiValueassignAliasassignTableAliasesStartingAtaveragebetweenbetweenbetweenbetweenbetweenbetweenbetweenbetweenbetweencaseConditionStatementcaseConditionStatementcaseStatementcaseStatementcastclonecloneUsingcoalescecoalesceconcatcontainsAllKeyWordscontainsAnyKeyWordscontainsSubstringcontainsSubstringcontainsSubstringIgnoringCasecontainsSubstringIgnoringCaseconvertNodeToUseOuterJoinconvertToUseOuterJoincopiedVersionFromcountcreateWithBaseLastcurrentDatecurrentDateDatecurrentTimecurrentTimeStampdateDifferencedateDifferencedateNamedatePartdateToStringdecodedescendingdifferencedistinctdoesConformdoesConformequalequalequalequalequalequalequalequalequalequalequalOuterJoinequalOuterJoinequalsIgnoreCaseequalsIgnoreCaseexceptexceptexceptAllexceptAllexistsexistsNodeextractextractFieldsextractPrimaryKeyValuesextractValueextractValuesextractXmlfromfromConstantfromLiteralgetgetgetAliasgetAllowingNullgetAsOfClausegetAsOfClauseRecursivelygetClonedFieldgetFieldgetFieldgetFieldsgetFieldValuegetFunctiongetFunctiongetFunctiongetFunctiongetFunctionWithArgumentsgetLeafDescriptorgetLeafMappinggetNamegetNumberValgetOperatorgetOwnedTablesgetParametergetParametergetParametergetPropertygetSelectionFieldsgetSelectionFieldsgetSessiongetStringValgetTablegetTablegetTableAliasesgreaterThangreaterThangreaterThangreaterThangreaterThangreaterThangreaterThangreaterThangreaterThangreaterThangreaterThanEqualgreaterThanEqualgreaterThanEqualgreaterThanEqualgreaterThanEqualgreaterThanEqualgreaterThanEqualgreaterThanEqualgreaterThanEqualgreaterThanEqualhasAsOfClausehasBeenAliasedhashCodehexToRawifNullininininininininininininindexindexOfintersectintersectintersectAllintersectAllisClassTypeExpressionisConstantExpressionisDataExpressionisEmptyisExpressionBuilderisFieldExpressionisFragmentisFunctionExpressionisLiteralExpressionisLogicalExpressionisMapEntryExpressionisNullisObjectExpressionisParameterExpressionisQueryKeyExpressionisRelationExpressionisSubSelectExpressionisTableExpressionisTreatExpressionisValueExpressionjoinlastDayleftJoinleftPadleftPadleftTrimleftTrimlengthlessThanlessThanlessThanlessThanlessThanlessThanlessThanlessThanlessThanlessThanlessThanEquallessThanEquallessThanEquallessThanEquallessThanEquallessThanEquallessThanEquallessThanEquallessThanEquallessThanEquallikelikelikelikelikeIgnoreCaselikeIgnoreCaseliterallocalDatelocalDateTimelocalTimelocatelocatelocatemapEntrymapKeymaximumminimummonthsBetweennewTimenextDaynoneOfnotnotBetweennotBetweennotBetweennotBetweennotBetweennotBetweennotBetweennotBetweennotBetweennotEmptynotEqualnotEqualnotEqualnotEqualnotEqualnotEqualnotEqualnotEqualnotEqualnotEqualnotExistsnotInnotInnotInnotInnotInnotInnotInnotInnotInnotInnotInnotInnotLikenotLikenotLikenotLikenotNullnullIfnullsFirstnullsLastoperatororperformOperatorpostfixSQLprefixSQLrefregexpregexpregisterInreplacereplicatereplicateresetCachereverserightrightrightPadrightPadrightTrimrightTrimroundDateselectIfOrderedBysetLocalBasesetSelectIfOrderedBysizesizesomesomesomesomesomesomesomesomesomesomesomesomesqlstandardDeviationsubQuerysubstringsubstringsubstringsubstringsumtoChartoChartoCharactertoDatetoLowerCasetoNumbertoStringtoStringtoUpperCasetoUppercaseCasedWordstranslatetreattrimtrimtruncateDatetwisttypeunionunionunionAllunionAllvaluevaluevaluevaluevaluevaluevaluevaluevaluevaluevalueFromObjectvalueFromObjectvariancewriteAliaswriteFieldwriteFields

Field Detail

builderback to summary
protected ExpressionBuilder builder
firstChildback to summary
protected Expression firstChild
operatorback to summary
protected ExpressionOperator operator
platformOperatorback to summary
protected transient ExpressionOperator platformOperator
secondChildback to summary
protected Expression secondChild

Constructor Detail

CompoundExpressionback to summary
protected CompoundExpression()

Method Detail

aliasForTableback to summary
public DatabaseTable aliasForTable(DatabaseTable table)

Overrides org.eclipse.persistence.expressions.Expression.aliasForTable.

INTERNAL: Find the alias for a given table from the first or second child in the additionalOuterJoinCriteria

Annotations
@Override
asOfback to summary
public Expression asOf(AsOfClause clause)

Overrides org.eclipse.persistence.expressions.Expression.asOf.

Doc from org.eclipse.persistence.expressions.Expression.asOf.

Sets all tables represented by this expression to be queried as of a past time.

Example:

 EclipseLink: employee.asOf(new AsOfClause(pastTime))
 Java: None
 SQL (Flashback): SELECT ... FROM EMPLOYEE AS OF TIMESTAMP (pastTime) t0 ...
 SQL (Generic): .. WHERE (t1.START <= pastTime) AND ((t1.END IS NULL) OR t1.END > pastTime)

Set an as of clause at the expression level to still query for current objects while expressing selection criteria like:

  • query objects as of one time that met some condition at another time.
  • query objects that changed a certain way over a certain interval (querying for change).

Simultaneously querying on two versions of the same object (one past one present) lets you express these advanced selection criteria.

Example: Querying on past attributes using parallel expressions.

  // Finds all employees who lived in Ottawa as of a past time.
  ExpressionBuilder employee = new ExpressionBuilder();
  ExpressionBuilder pastEmployee = new ExpressionBuilder(Employee.class);
  pastEmployee.asOf(pastTime);
  Expression pastAddress = pastEmployee.get("address"); // by default address will also be as of past time.
  Expression selectionCriteria = pastAddress.get("city").equal("Ottawa").and(
      employee.equal(pastEmployee));

The advantage of the parallel expression is that you can still read current objects, the as of clause will affect only the where clause / selection criteria.

You may be tempted to rewrite the above as employee.get("address").asOf(pastTime). That is allowed but see below for the finer points involved in this.

Example: Querying on object changes using parallel expressions.

  // Finds all employees who recently received a raise.  Note that current
  // objects are returned, so can be cached normally.
  ExpressionBuilder employee = new ExpressionBuilder();
  Expression pastEmployee = new ExpressionBuilder(Employee.class);
  pastEmployee.asOf(yesterday);
  Expression parallelJoin = employee.equal(pastEmployee);
  Expression selectionCriteria = parallelJoin.and(
      employee.get("salary").greaterThan(pastEmployee.get("salary")));

Example: Querying on object changes using custom query keys

  // First define the custom query key and add it to your descriptor.
  ExpressionBuilder builder = new ExpressionBuilder(Employee.class);
  Expression joinCriteria = builder.getField("EMPLOYEE.EMP_ID").equal(builder.getParameter("EMPLOYEE.EMP_ID"));
  OneToOneQueryKey selfReferential = new OneToOneQueryKey();
  selfReferential.setName("this");
  selfReferential.setJoinCriteria(joinCriteria);
  selfReferential.setReferenceClass(Employee.class);
  getSession().getDescriptor(Employee.class).addQueryKey(selfReferential);

  // Now build query as before.
  Expression employee = new ExpessionBuilder();
  Expression pastEmployee = employee.get("this").asOf(yesterday);
  Expression selectionCriteria = employee.get("salary").greaterThan(pastEmployee.get("salary"));

Note in general that any parallel expression can be rewritten using a custom query key. EclipseLink will even automatically interpret x.get("this") for you so you do not need to define the above query key first.

Full Reference:

If an object is mapped to multiple tables, then each table will be as of the same time. Two objects mapped to the same table can not have different as of times. Conversely only expressions which have associated tables can have an as of clause.

If an as of clause is not explicitly set an expression will use the clause of its base expression, and so on recursively until one is found or an ExpressionBuilder is reached. Some usage scenarios follow:

  • employee.asOf(pastTime).anyOf("projects"): projects as of past time.
  • expressionBuilder.asOf(pastTime): entire expression as of past time.
  • employee.asOf(pastTime).anyOf("projects").asOf(null): projects as of current time.
  • employee.anyOf("projects").asOf(pastTime): projects only as of past time.

Watch out for x.asOf(oneTime).get("y").asOf(anotherTime).

  • emp.anyOf("phoneNumbers").asOf(yesterday) = emp.asOf(yesterday).anyOf("phoneNumbers") but:
  • emp.get("address").asOf(yesterday) != emp.asOf(yesterday).get("address").
Whether the join is also as of yesterday depends on which table the foreign key field resides on. In an anyOf the foreign key is always on the right, but in a get (1-1) it could be on either side. For this reason employee.get("address").asOf(yesterday) is undefined as it can mean either 'my address as of yesterday', or 'my address, as of yesterday.'
Parameters
clause:AsOfClause

A read only data object used to represent a past time.

Returns:Expression

this

Annotations
@Override
computeHashCodeback to summary
public int computeHashCode()

Overrides org.eclipse.persistence.expressions.Expression.computeHashCode.

INTERNAL: Compute a consistent hash-code for the expression. This is used to allow dynamic expression's SQL to be cached.

Annotations
@Override
createback to summary
public Expression create(Expression base, Object singleArgument, ExpressionOperator operator)

Overrides org.eclipse.persistence.expressions.Expression.create.

INTERNAL:

Annotations
@Override
createback to summary
public Expression create(Expression base, List<E> arguments, ExpressionOperator operator)

Overrides org.eclipse.persistence.expressions.Expression.create.

INTERNAL:

Annotations
@Override
descriptionOfNodeTypeback to summary
public String descriptionOfNodeType()

Overrides org.eclipse.persistence.expressions.Expression.descriptionOfNodeType.

INTERNAL: Used for debug printing.

Annotations
@Override
equalsback to summary
public boolean equals(Object object)

Overrides org.eclipse.persistence.expressions.Expression.equals.

INTERNAL: Return if the expression is equal to the other. This is used to allow dynamic expression's SQL to be cached.

Parameters
object:Object

Doc from java.lang.Object.equals.

the reference object with which to compare.

Returns:boolean

Doc from java.lang.Object.equals.

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getBuilderback to summary
public ExpressionBuilder getBuilder()

Implements abstract org.eclipse.persistence.expressions.Expression.getBuilder.

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)

Annotations
@Override
getFirstChildback to summary
public Expression getFirstChild()
getOperatorback to summary
public ExpressionOperator getOperator()

Overrides org.eclipse.persistence.expressions.Expression.getOperator.

Doc from org.eclipse.persistence.expressions.Expression.getOperator.

INTERNAL: Most expression have operators, so this is just a convenience method.

Annotations
@Override
getPlatformOperatorback to summary
public ExpressionOperator getPlatformOperator(DatabasePlatform platform)
getSecondChildback to summary
public Expression getSecondChild()
initializePlatformOperatorback to summary
public void initializePlatformOperator(DatabasePlatform platform)

INTERNAL:

isCompoundExpressionback to summary
public boolean isCompoundExpression()

Overrides org.eclipse.persistence.expressions.Expression.isCompoundExpression.

Doc from org.eclipse.persistence.expressions.Expression.isCompoundExpression.

INTERNAL:

Annotations
@Override
iterateOnback to summary
public void iterateOn(ExpressionIterator iterator)

Overrides org.eclipse.persistence.expressions.Expression.iterateOn.

INTERNAL: For iterating using an inner class

Annotations
@Override
normalizeback to summary
public Expression normalize(ExpressionNormalizer normalizer)

Overrides org.eclipse.persistence.expressions.Expression.normalize.

INTERNAL: Normalize into a structure that is printable. Also compute printing information such as outer joins.

Annotations
@Override
postCopyInback to summary
protected void postCopyIn(Map<K, V> alreadyDone)

Overrides org.eclipse.persistence.expressions.Expression.postCopyIn.

INTERNAL: Used for cloning.

Annotations
@Override
printJavaback to summary
public void printJava(ExpressionJavaPrinter printer)

Overrides org.eclipse.persistence.expressions.Expression.printJava.

INTERNAL: Print java for project class generation

Annotations
@Override
printSQLback to summary
public void printSQL(ExpressionSQLPrinter printer)

Implements abstract org.eclipse.persistence.expressions.Expression.printSQL.

INTERNAL: Print SQL

Annotations
@Override
rebuildOnback to summary
public Expression rebuildOn(Expression newBase)

Implements abstract org.eclipse.persistence.expressions.Expression.rebuildOn.

INTERNAL: This expression is built on a different base than the one we want. Rebuild it and return the root of the new tree

Annotations
@Override
resetPlaceHolderBuilderback to summary
public void resetPlaceHolderBuilder(ExpressionBuilder queryBuilder)

Implements abstract org.eclipse.persistence.expressions.Expression.resetPlaceHolderBuilder.

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.

Annotations
@Override
setFirstChildback to summary
protected void setFirstChild(Expression firstChild)
setOperatorback to summary
public void setOperator(ExpressionOperator newOperator)
setSecondChildback to summary
protected void setSecondChild(Expression secondChild)
shallowCloneback to summary
public Expression shallowClone()

Overrides org.eclipse.persistence.expressions.Expression.shallowClone.

INTERNAL: Clear the builder when cloning.

Annotations
@Override
twistedForBaseAndContextback to summary
public Expression twistedForBaseAndContext(Expression newBase, Expression context, Expression oldBase)

Overrides org.eclipse.persistence.expressions.Expression.twistedForBaseAndContext.

INTRENAL: Used to change an expression off of one base to an expression off of a different base. i.e. expression on address to an expression on an employee's address.

Annotations
@Override
validateNodeback to summary
public void validateNode()

Overrides org.eclipse.persistence.expressions.Expression.validateNode.

Do any required validation for this node. Throw an exception if it's incorrect. Ensure that both sides are not data expressions.

Annotations
@Override
writeDescriptionOnback to summary
public void writeDescriptionOn(BufferedWriter writer) throws IOException

Overrides org.eclipse.persistence.expressions.Expression.writeDescriptionOn.

INTERNAL: Used to print a debug form of the expression tree.

Annotations
@Override
writeSubexpressionsToback to summary
public void writeSubexpressionsTo(BufferedWriter writer, int indent) throws IOException

Overrides org.eclipse.persistence.expressions.Expression.writeSubexpressionsTo.

INTERNAL: Used for toString for debugging only.

Annotations
@Override