Class FunctionExpression
- java.lang.Object
-
- org.eclipse.persistence.expressions.Expression
-
- org.eclipse.persistence.internal.expressions.BaseExpression
-
- org.eclipse.persistence.internal.expressions.FunctionExpression
-
- All Implemented Interfaces:
Serializable
,Cloneable
- Direct Known Subclasses:
ArgumentListFunctionExpression
public class FunctionExpression extends BaseExpression
Used for expressions that have 0 to n children. These include not, between and all functions.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected Vector<Expression>
children
protected ExpressionOperator
operator
protected ExpressionOperator
platformOperator
protected Class
resultType
-
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, shouldUseUpperCaseForIgnoreCase
-
-
Constructor Summary
Constructors Constructor Description FunctionExpression()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addChild(Expression child)
DatabaseTable
aliasForTable(DatabaseTable table)
INTERNAL: Find the alias for a given tableExpression
asOf(AsOfClause clause)
Sets all tables represented by this expression to be queried as of a past time.int
computeHashCode()
INTERNAL: Compute a consistent hash-code for the expression.Expression
create(Expression base, Object singleArgument, ExpressionOperator anOperator)
INTERNAL:Expression
create(Expression base, List arguments, ExpressionOperator anOperator)
INTERNAL:Expression
createWithBaseLast(Expression base, Object singleArgument, ExpressionOperator anOperator)
INTERNAL: added for Trim support.String
descriptionOfNodeType()
INTERNAL: Used for debug printing.boolean
doesConform(Object object, AbstractSession session, AbstractRecord translationRow, int valueHolderPolicy, boolean isObjectUnregistered)
INTERNAL: Check if the object conforms to the expression in memory.boolean
equals(Object object)
INTERNAL: Return if the expression is equal to the other.Vector<Expression>
getChildren()
List<DatabaseField>
getFields()
INTERNAL: Not to be confused with the public getField(String) This returns a collection of all fields associated with this object.DatabaseMapping
getLeafMapping(DatabaseQuery query, ClassDescriptor rootDescriptor, AbstractSession session)
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
getMappingOfFirstPrimaryKey(ClassDescriptor descriptor)
ExpressionOperator
getOperator()
INTERNAL: Most expression have operators, so this is just a convenience method.ExpressionOperator
getPlatformOperator(DatabasePlatform platform)
Class
getResultType()
List<DatabaseField>
getSelectionFields(ReadQuery query)
INTERNAL:boolean
hasResultType()
void
initializePlatformOperator(DatabasePlatform platform)
INTERNAL:boolean
isFunctionExpression()
INTERNAL:protected boolean
isObjectComparison()
INTERNAL: Return if the represents an object comparison.void
iterateOn(ExpressionIterator iterator)
INTERNAL: For iterating using an inner classExpression
normalize(ExpressionNormalizer normalizer)
INTERNAL: Normalize into a structure that is printable.protected void
postCopyIn(Map alreadyDone)
INTERNAL: Used for cloning.void
prepareObjectAttributeCount(ExpressionNormalizer normalizer, ReportItem item, ReportQuery query, Map 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.void
printJava(ExpressionJavaPrinter printer)
INTERNAL: Print java for project class generationvoid
printSQL(ExpressionSQLPrinter printer)
INTERNAL: Print SQL using the operator.Expression
rebuildOn(Expression newBase)
INTERNAL: This expression is built on a different base than the one we want.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
setLocalBase(Expression exp)
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.void
setOperator(ExpressionOperator theOperator)
void
setResultType(Class resultType)
Expression
twistedForBaseAndContext(Expression newBase, Expression context, Expression oldBase)
INTERNAL: Rebuild myself against the base, with the values of parameters supplied by the context expression.Object
valueFromObject(Object object, AbstractSession session, AbstractRecord translationRow, int valueHolderPolicy, boolean isObjectUnregistered)
INTERNAL: Return the value for in memory comparison.void
writeDescriptionOn(BufferedWriter writer)
INTERNAL: Used to print a debug form of the expression tree.void
writeFields(ExpressionSQLPrinter printer, List<DatabaseField> newFields, SQLSelectStatement statement)
INTERNAL: called from SQLSelectStatement.writeFieldsFromExpression(...)void
writeSubexpressionsTo(BufferedWriter writer, int indent)
INTERNAL: Used in SQL printing.-
Methods inherited from class org.eclipse.persistence.internal.expressions.BaseExpression
getBaseExpression, getBuilder, setBaseExpression, shallowClone
-
Methods inherited from class org.eclipse.persistence.expressions.Expression
addDate, addDate, addMonths, addMonths, alias, 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, anyOf, anyOf, anyOfAllowingNone, anyOfAllowingNone, as, ascending, asciiValue, assignAlias, assignTableAliasesStartingAt, average, between, between, between, between, between, between, between, between, between, caseConditionStatement, caseConditionStatement, caseStatement, caseStatement, cast, clone, cloneUsing, coalesce, coalesce, concat, containsAllKeyWords, containsAnyKeyWords, containsSubstring, containsSubstring, containsSubstringIgnoringCase, containsSubstringIgnoringCase, convertNodeToUseOuterJoin, convertToUseOuterJoin, copiedVersionFrom, count, currentDate, currentDateDate, currentTime, currentTimeStamp, dateDifference, dateDifference, dateName, datePart, dateToString, decode, descending, difference, distinct, doesConform, equal, equal, equal, equal, equal, equal, equal, equal, equal, equal, equalOuterJoin, equalOuterJoin, equalsIgnoreCase, equalsIgnoreCase, except, except, exceptAll, exceptAll, exists, existsNode, extract, extractFields, extractPrimaryKeyValues, extractValue, extractValues, extractXml, from, fromConstant, fromLiteral, get, get, getAlias, getAllowingNull, getAsOfClause, getAsOfClauseRecursively, getClonedField, getField, getField, getFieldValue, getFunction, getFunction, getFunction, getFunction, getFunctionWithArguments, getLeafDescriptor, getName, getNumberVal, getOperator, getOwnedTables, getParameter, getParameter, getParameter, getProperty, getSelectionFields, getSession, getStringVal, getTable, getTable, getTableAliases, greaterThan, greaterThan, greaterThan, greaterThan, greaterThan, greaterThan, greaterThan, greaterThan, greaterThan, greaterThan, greaterThanEqual, greaterThanEqual, greaterThanEqual, greaterThanEqual, greaterThanEqual, greaterThanEqual, greaterThanEqual, greaterThanEqual, greaterThanEqual, greaterThanEqual, hasAsOfClause, hasBeenAliased, hashCode, hexToRaw, ifNull, in, in, in, in, in, in, in, in, in, in, in, in, index, indexOf, intersect, intersect, intersectAll, intersectAll, isClassTypeExpression, isCompoundExpression, isConstantExpression, isDataExpression, isEmpty, isExpressionBuilder, isFieldExpression, isFragment, isLiteralExpression, isLogicalExpression, isMapEntryExpression, isNull, isObjectExpression, isParameterExpression, isQueryKeyExpression, isRelationExpression, isSubSelectExpression, isTableExpression, isTreatExpression, isValueExpression, join, lastDay, leftJoin, 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, nullsFirst, nullsLast, operator, or, performOperator, postfixSQL, prefixSQL, ref, regexp, regexp, registerIn, replace, replicate, replicate, resetCache, reverse, right, right, rightPad, rightPad, rightTrim, rightTrim, roundDate, selectIfOrderedBy, setSelectIfOrderedBy, size, size, some, some, some, some, some, some, some, some, some, some, some, some, sql, standardDeviation, subQuery, substring, substring, substring, substring, sum, toChar, toChar, toCharacter, toDate, toLowerCase, toNumber, toString, toString, toUpperCase, toUppercaseCasedWords, translate, treat, trim, trim, truncateDate, twist, type, union, union, unionAll, unionAll, validateNode, value, value, value, value, value, value, value, value, value, value, valueFromObject, variance, writeAlias, writeField
-
-
-
-
Field Detail
-
children
protected Vector<Expression> children
-
operator
protected ExpressionOperator operator
-
platformOperator
protected transient ExpressionOperator platformOperator
-
resultType
protected Class resultType
-
-
Method Detail
-
equals
public boolean equals(Object object)
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.- Overrides:
equals
in classExpression
-
computeHashCode
public int computeHashCode()
INTERNAL: Compute a consistent hash-code for the expression. This is used to allow dynamic expression's SQL to be cached.- Overrides:
computeHashCode
in classExpression
-
addChild
public void addChild(Expression child)
-
aliasForTable
public DatabaseTable aliasForTable(DatabaseTable table)
INTERNAL: Find the alias for a given table- Overrides:
aliasForTable
in classExpression
-
asOf
public Expression asOf(AsOfClause clause)
Description copied from class:Expression
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").
- Overrides:
asOf
in classExpression
- Parameters:
clause
- A read only data object used to represent a past time.- Returns:
this
- See Also:
AsOfClause
,Expression.hasAsOfClause()
,Session.acquireHistoricalSession(org.eclipse.persistence.history.AsOfClause)
,ObjectLevelReadQuery.setAsOfClause(org.eclipse.persistence.history.AsOfClause)
-
create
public Expression create(Expression base, Object singleArgument, ExpressionOperator anOperator)
INTERNAL:- Overrides:
create
in classExpression
-
createWithBaseLast
public Expression createWithBaseLast(Expression base, Object singleArgument, ExpressionOperator anOperator)
INTERNAL: added for Trim support. TRIM([trim_character FROM] string_primary)- Overrides:
createWithBaseLast
in classExpression
-
create
public Expression create(Expression base, List arguments, ExpressionOperator anOperator)
INTERNAL:- Overrides:
create
in classExpression
-
descriptionOfNodeType
public String descriptionOfNodeType()
INTERNAL: Used for debug printing.- Overrides:
descriptionOfNodeType
in classExpression
-
doesConform
public boolean doesConform(Object object, AbstractSession session, AbstractRecord translationRow, int valueHolderPolicy, boolean isObjectUnregistered)
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.- Overrides:
doesConform
in classExpression
isObjectUnregistered
- 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.
-
getChildren
public Vector<Expression> getChildren()
-
getFields
public List<DatabaseField> 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.- Overrides:
getFields
in classExpression
-
getSelectionFields
public List<DatabaseField> getSelectionFields(ReadQuery query)
INTERNAL:- Overrides:
getSelectionFields
in classExpression
-
getOperator
public ExpressionOperator getOperator()
Description copied from class:Expression
INTERNAL: Most expression have operators, so this is just a convenience method.- Overrides:
getOperator
in classExpression
-
getPlatformOperator
public ExpressionOperator getPlatformOperator(DatabasePlatform platform)
-
getResultType
public Class getResultType()
-
hasResultType
public boolean hasResultType()
-
initializePlatformOperator
public void initializePlatformOperator(DatabasePlatform platform)
INTERNAL:
-
isFunctionExpression
public boolean isFunctionExpression()
Description copied from class:Expression
INTERNAL:- Overrides:
isFunctionExpression
in classExpression
-
isObjectComparison
protected boolean isObjectComparison()
INTERNAL: Return if the represents an object comparison.
-
iterateOn
public void iterateOn(ExpressionIterator iterator)
INTERNAL: For iterating using an inner class- Overrides:
iterateOn
in classExpression
-
normalize
public Expression normalize(ExpressionNormalizer normalizer)
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.- Overrides:
normalize
in classExpression
-
postCopyIn
protected void postCopyIn(Map alreadyDone)
INTERNAL: Used for cloning.- Overrides:
postCopyIn
in classBaseExpression
-
printSQL
public void printSQL(ExpressionSQLPrinter printer)
INTERNAL: Print SQL using the operator.- Specified by:
printSQL
in classExpression
-
printJava
public void printJava(ExpressionJavaPrinter printer)
INTERNAL: Print java for project class generation- Overrides:
printJava
in classExpression
-
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- Specified by:
rebuildOn
in classExpression
- 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 classBaseExpression
-
setLocalBase
public void setLocalBase(Expression exp)
Description copied from class:Expression
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.- Overrides:
setLocalBase
in classExpression
-
setOperator
public void setOperator(ExpressionOperator theOperator)
-
setResultType
public void setResultType(Class resultType)
-
twistedForBaseAndContext
public Expression twistedForBaseAndContext(Expression newBase, Expression context, Expression oldBase)
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 classExpression
-
valueFromObject
public Object valueFromObject(Object object, AbstractSession session, AbstractRecord translationRow, int valueHolderPolicy, boolean isObjectUnregistered)
INTERNAL: Return the value for in memory comparison. This is only valid for valueable expressions.- Overrides:
valueFromObject
in classExpression
isObjectUnregistered
- true if object possibly not a clone, but is being conformed against the unit of work cache.
-
writeDescriptionOn
public void writeDescriptionOn(BufferedWriter writer) throws IOException
INTERNAL: Used to print a debug form of the expression tree.- Overrides:
writeDescriptionOn
in classExpression
- Throws:
IOException
-
writeFields
public void writeFields(ExpressionSQLPrinter printer, List<DatabaseField> newFields, SQLSelectStatement statement)
INTERNAL: called from SQLSelectStatement.writeFieldsFromExpression(...)- Overrides:
writeFields
in classExpression
-
writeSubexpressionsTo
public void writeSubexpressionsTo(BufferedWriter writer, int indent) throws IOException
INTERNAL: Used in SQL printing.- Overrides:
writeSubexpressionsTo
in classExpression
- Throws:
IOException
-
prepareObjectAttributeCount
public void prepareObjectAttributeCount(ExpressionNormalizer normalizer, ReportItem item, ReportQuery query, Map 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.
-
getLeafQueryKeyFor
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.- Throws:
QueryException
-
getMappingOfFirstPrimaryKey
protected DatabaseMapping getMappingOfFirstPrimaryKey(ClassDescriptor descriptor)
-
getLeafMapping
public DatabaseMapping getLeafMapping(DatabaseQuery query, ClassDescriptor rootDescriptor, AbstractSession session)
INTERNAL: Lookup the mapping for this item by traversing its expression recursively.- Overrides:
getLeafMapping
in classExpression
-
-