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

public Class FunctionExpression

extends BaseExpression
Class Inheritance
Known Direct Subclasses
org.eclipse.persistence.internal.expressions.ArgumentListFunctionExpression
Imports
java.io.BufferedWriter, .IOException, java.util.ArrayList, .Enumeration, .Iterator, .List, .Map, .Vector, org.eclipse.persistence.descriptors.ClassDescriptor, org.eclipse.persistence.exceptions.QueryException, org.eclipse.persistence.expressions.Expression, .ExpressionBuilder, .ExpressionOperator, org.eclipse.persistence.history.AsOfClause, org.eclipse.persistence.internal.databaseaccess.DatabasePlatform, org.eclipse.persistence.internal.helper.ClassConstants, .DatabaseField, .DatabaseTable, .NonSynchronizedVector, org.eclipse.persistence.internal.queries.ReportItem, org.eclipse.persistence.internal.sessions.AbstractRecord, .AbstractSession, org.eclipse.persistence.mappings.DatabaseMapping, .OneToOneMapping, org.eclipse.persistence.mappings.querykeys.ForeignReferenceQueryKey, .QueryKey, org.eclipse.persistence.queries.DatabaseQuery, .ReadQuery, .ReportQuery

Used for expressions that have 0 to n children. These include not, between and all functions.

Field Summary

Modifier and TypeField and Description
protected Vector<Expression>
protected ExpressionOperator
protected transient ExpressionOperator
protected Class<?>
Inherited from org.eclipse.persistence.internal.expressions.BaseExpression:
baseExpressionbuilder

Constructor Summary

AccessConstructor and Description
public

Method Summary

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

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

INTERNAL: Find the alias for a given table
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 Expression
createWithBaseLast(Expression base, Object singleArgument, ExpressionOperator anOperator)

Overrides org.eclipse.persistence.expressions.Expression.createWithBaseLast.

INTERNAL: added for Trim support.
public String
public boolean
doesConform(Object object, AbstractSession session, AbstractRecord translationRow, int valueHolderPolicy, boolean
true if object possibly not a clone, but is being conformed against the unit of work cache; if object is not in the UOW cache but some of its attributes are, use the registered versions of object's attributes for the purposes of this method.
isObjectUnregistered
)

Overrides org.eclipse.persistence.expressions.Expression.doesConform.

INTERNAL: Check if the object conforms to the expression in memory.
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 Vector<Expression>
public List<DatabaseField>
getFields()

Overrides org.eclipse.persistence.expressions.Expression.getFields.

INTERNAL: Not to be confused with the public getField(String) This returns a collection of all fields associated with this object.
public DatabaseMapping
getLeafMapping(DatabaseQuery query, ClassDescriptor rootDescriptor, AbstractSession session)

Overrides org.eclipse.persistence.expressions.Expression.getLeafMapping.

INTERNAL: Lookup the mapping for this item by traversing its expression recursively.
protected QueryKey
getLeafQueryKeyFor(DatabaseQuery query, Expression expression, ClassDescriptor rootDescriptor, AbstractSession session)

INTERNAL: Lookup the query key for this item.

protected DatabaseMapping
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 Class<?>
public List<DatabaseField>
public boolean
public void
public boolean
protected boolean
isObjectComparison()

INTERNAL: Return if the represents an object comparison.

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.internal.expressions.BaseExpression.postCopyIn.

INTERNAL: Used for cloning.
public void
prepareObjectAttributeCount(ExpressionNormalizer normalizer, ReportItem item, ReportQuery query, Map<K, V> clonedExpressions)

INTERNAL: JPQL allows count([distinct] e), where e can be an object, not just a single field, however the database only allows a single field, so object needs to be translated to a single field.

public void
printJava(ExpressionJavaPrinter printer)

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

INTERNAL: Print java for project class generation
public void
printSQL(ExpressionSQLPrinter printer)

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

INTERNAL: Print SQL using the operator.
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)

Overrides org.eclipse.persistence.internal.expressions.BaseExpression.resetPlaceHolderBuilder.

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

Overrides org.eclipse.persistence.expressions.Expression.setLocalBase.

INTERNAL: Set the local base expression, ie the one on the other side of the operator Most types will ignore this, since they don't need it.
public void
public void
setResultType(Class<?> resultType)

public Expression
twistedForBaseAndContext(Expression newBase, Expression context, Expression oldBase)

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

INTERNAL: Rebuild myself against the base, with the values of parameters supplied by the context expression.
public Object
valueFromObject(Object object, AbstractSession session, AbstractRecord translationRow, int valueHolderPolicy, boolean
true if object possibly not a clone, but is being conformed against the unit of work cache.
isObjectUnregistered
)

Overrides org.eclipse.persistence.expressions.Expression.valueFromObject.

INTERNAL: Return the value for in memory comparison.
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
writeFields(ExpressionSQLPrinter printer, List<DatabaseField> newFields, SQLSelectStatement statement)

Overrides org.eclipse.persistence.expressions.Expression.writeFields.

INTERNAL: called from SQLSelectStatement.writeFieldsFromExpression(...)
public void
Inherited from org.eclipse.persistence.internal.expressions.BaseExpression:
getBaseExpressiongetBuildersetBaseExpressionshallowClone

Field Detail

childrenback to summary
protected Vector<Expression> children
operatorback to summary
protected ExpressionOperator operator
platformOperatorback to summary
protected transient ExpressionOperator platformOperator
resultTypeback to summary
protected Class<?> resultType

Constructor Detail

FunctionExpressionback to summary
public FunctionExpression()

Method Detail

addChildback to summary
public void addChild(Expression child)
aliasForTableback to summary
public DatabaseTable aliasForTable(DatabaseTable table)

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

INTERNAL: Find the alias for a given table

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 anOperator)

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

INTERNAL:

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

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

INTERNAL:

Annotations
@Override
createWithBaseLastback to summary
public Expression createWithBaseLast(Expression base, Object singleArgument, ExpressionOperator anOperator)

Overrides org.eclipse.persistence.expressions.Expression.createWithBaseLast.

INTERNAL: added for Trim support. TRIM([trim_character FROM] string_primary)

Annotations
@Override
descriptionOfNodeTypeback to summary
public String descriptionOfNodeType()

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

INTERNAL: Used for debug printing.

Annotations
@Override
doesConformback to summary
public boolean doesConform(Object object, AbstractSession session, AbstractRecord translationRow, int valueHolderPolicy, boolean isObjectUnregistered)

Overrides org.eclipse.persistence.expressions.Expression.doesConform.

INTERNAL: Check if the object conforms to the expression in memory. This is used for in-memory querying. If the expression in not able to determine if the object conform throw a not supported exception.

Parameters
isObjectUnregistered:boolean

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

true if object possibly not a clone, but is being conformed against the unit of work cache; if object is not in the UOW cache but some of its attributes are, use the registered versions of object's attributes for the purposes of this method.

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. This must be over written by each subclass.

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
getChildrenback to summary
public Vector<Expression> getChildren()
getFieldsback to summary
public List<DatabaseField> getFields()

Overrides org.eclipse.persistence.expressions.Expression.getFields.

INTERNAL: Not to be confused with the public getField(String) This returns a collection of all fields associated with this object. Really only applies to query keys representing an object or to expression builders.

Annotations
@Override
getLeafMappingback to summary
public DatabaseMapping getLeafMapping(DatabaseQuery query, ClassDescriptor rootDescriptor, AbstractSession session)

Overrides org.eclipse.persistence.expressions.Expression.getLeafMapping.

INTERNAL: Lookup the mapping for this item by traversing its expression recursively.

Annotations
@Override
getLeafQueryKeyForback to summary
protected QueryKey getLeafQueryKeyFor(DatabaseQuery query, Expression expression, ClassDescriptor rootDescriptor, AbstractSession session) throws QueryException

INTERNAL: Lookup the query key for this item. If an aggregate of foreign mapping is found it is traversed.

getMappingOfFirstPrimaryKeyback to summary
protected DatabaseMapping getMappingOfFirstPrimaryKey(ClassDescriptor descriptor)
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)
getResultTypeback to summary
public Class<?> getResultType()
getSelectionFieldsback to summary
public List<DatabaseField> getSelectionFields(ReadQuery query)

Overrides org.eclipse.persistence.expressions.Expression.getSelectionFields.

INTERNAL:

Annotations
@Override
hasResultTypeback to summary
public boolean hasResultType()
initializePlatformOperatorback to summary
public void initializePlatformOperator(DatabasePlatform platform)

INTERNAL:

isFunctionExpressionback to summary
public boolean isFunctionExpression()

Overrides org.eclipse.persistence.expressions.Expression.isFunctionExpression.

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

INTERNAL:

Annotations
@Override
isObjectComparisonback to summary
protected boolean isObjectComparison()

INTERNAL: Return if the represents an object comparison.

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. This checks for object isNull, notNull, in and notIn comparisons.

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

Overrides org.eclipse.persistence.internal.expressions.BaseExpression.postCopyIn.

INTERNAL: Used for cloning.

Annotations
@Override
prepareObjectAttributeCountback to summary
public void prepareObjectAttributeCount(ExpressionNormalizer normalizer, ReportItem item, ReportQuery query, Map<K, V> clonedExpressions)

INTERNAL: JPQL allows count([distinct] e), where e can be an object, not just a single field, however the database only allows a single field, so object needs to be translated to a single field. If the descriptor has a single pk, it is used, otherwise any pk is used if distinct, otherwise a subselect is used. If the object was obtained through an outer join, then the subselect also will not work, so an error is thrown.

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 using the operator.

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)

Overrides org.eclipse.persistence.internal.expressions.BaseExpression.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
setLocalBaseback to summary
public void setLocalBase(Expression exp)

Overrides org.eclipse.persistence.expressions.Expression.setLocalBase.

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

INTERNAL: Set the local base expression, ie the one on the other side of the operator Most types will ignore this, since they don't need it.

Annotations
@Override
setOperatorback to summary
public void setOperator(ExpressionOperator theOperator)
setResultTypeback to summary
public void setResultType(Class<?> resultType)
twistedForBaseAndContextback to summary
public Expression twistedForBaseAndContext(Expression newBase, Expression context, Expression oldBase)

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

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"

Annotations
@Override
valueFromObjectback to summary
public Object valueFromObject(Object object, AbstractSession session, AbstractRecord translationRow, int valueHolderPolicy, boolean isObjectUnregistered)

Overrides org.eclipse.persistence.expressions.Expression.valueFromObject.

INTERNAL: Return the value for in memory comparison. This is only valid for valueable expressions.

Parameters
isObjectUnregistered:boolean

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

true if object possibly not a clone, but is being conformed against the unit of work cache.

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
writeFieldsback to summary
public void writeFields(ExpressionSQLPrinter printer, List<DatabaseField> newFields, SQLSelectStatement statement)

Overrides org.eclipse.persistence.expressions.Expression.writeFields.

INTERNAL: called from SQLSelectStatement.writeFieldsFromExpression(...)

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

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

INTERNAL: Used in SQL printing.

Annotations
@Override