Class DataExpression
- java.lang.Object
-
- org.eclipse.persistence.expressions.Expression
-
- org.eclipse.persistence.internal.expressions.BaseExpression
-
- org.eclipse.persistence.internal.expressions.DataExpression
-
- All Implemented Interfaces:
Serializable,Cloneable
- Direct Known Subclasses:
ClassTypeExpression,FieldExpression,ObjectExpression,TableExpression
public abstract class DataExpression extends BaseExpression
Superclass for all expression that have a context. i.e. a base expression.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected AsOfClauseasOfClauseprotected List<Expression>derivedFieldsprotected List<Expression>derivedTablesprotected booleanhasBeenNormalizedprotected TableAliasLookuptableAliases-
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 Modifier Constructor Description protectedDataExpression()DataExpression constructor comment.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddDerivedField(Expression addThis)voidaddDerivedTable(Expression addThis)DatabaseTablealiasForTable(DatabaseTable table)INTERNAL: Find the alias for a given tableExpressionasOf(AsOfClause clause)Sets all tables represented by this expression to be queried as of a past time.protected voidassignAlias(String name, DatabaseTable table)INTERNAL: Alias a particular table within this nodeprotected voidassignAlias(DatabaseTable alias, DatabaseTable table)INTERNAL: Alias a particular table within this nodevoidclearAliases()INTERNAL:List<Expression>copyCollection(List<Expression> in, Map alreadyDone)booleanequals(Object object)INTERNAL: Return if the expression is equal to the other.ExpressionexistingDerivedField(DatabaseField field)INTERNAL:ExpressionexistingDerivedTable(DatabaseTable table)INTERNAL:ExpressiongetAlias(Expression subSelect)ADVANCED: Return an expression representing a sub-select in the from clause.DatabaseFieldgetAliasedField()INTERNAL: Return the field appropriately aliasedAsOfClausegetAsOfClause()Answers the past time the expression is explicitly as of.ClassDescriptorgetContainingDescriptor()INTERNAL: Return the descriptor which contains this query key.ClassDescriptorgetDescriptor()DatabaseFieldgetField()INTERNAL:ExpressiongetField(String fieldName)ADVANCED: Return an expression representing a field in a data-level query.ExpressiongetField(DatabaseField field)ADVANCED: Return an expression representing a field in a data-level query.DatabaseMappinggetMapping()QueryKeygetQueryKeyOrNull()ExpressiongetTable(String tableName)ADVANCED: Return an expression representing a table in a data-level query.ExpressiongetTable(DatabaseTable table)ADVANCED: Return an expression representing a table in a data-level query.TableAliasLookupgetTableAliases()INTERNAL: Return the aliases used.booleanhasAsOfClause()ADVANCED: Answers true ifthisis to be queried as of a past time.booleanhasBeenAliased()INTERNAL: Answers if the database tables associated with this expression have been aliased.booleanhasBeenNormalized()INTERNAL: Did the normalizer already add additional joins to the where clause due to this query key representing a foreign reference mapping? This insures that join criteria (for any query key expression) is not added twice.protected booleanhasDerivedFields()protected booleanhasDerivedTables()booleanisAttribute()INTERNAL:booleanisDataExpression()INTERNAL:voiditerateOn(ExpressionIterator iterator)INTERNAL: For iterating using an inner classExpressionnewDerivedField(DatabaseField field)INTERNAL:ExpressionnewDerivedTable(DatabaseTable table)INTERNAL:Expressionnormalize(ExpressionNormalizer normalizer)INTERNAL: Normalize the expression into a printable structure.protected voidpostCopyIn(Map alreadyDone)INTERNAL: Used for cloning.voidprintSQL(ExpressionSQLPrinter printer)INTERNAL: Print SQL onto the stream, using the ExpressionPrinter for contextvoidsetHasBeenNormalized(boolean value)voidsetTableAliases(TableAliasLookup tableAliases)INTERNAL: For CR#2456, Table identity involves having two tables sharing the same aliasing table.StringtableAliasesDescription()voidwriteSubexpressionsTo(BufferedWriter writer, int indent)Print the base for debuggin purposes.-
Methods inherited from class org.eclipse.persistence.internal.expressions.BaseExpression
getBaseExpression, getBuilder, resetPlaceHolderBuilder, 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, assignTableAliasesStartingAt, average, between, between, between, between, between, between, between, between, between, caseConditionStatement, caseConditionStatement, caseStatement, caseStatement, cast, 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, descriptionOfNodeType, difference, distinct, doesConform, 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, getAllowingNull, getAsOfClauseRecursively, getClonedField, getFields, getFieldValue, getFunction, getFunction, getFunction, getFunction, getFunctionWithArguments, getLeafDescriptor, getLeafMapping, getName, getNumberVal, getOperator, getOperator, getOwnedTables, getParameter, getParameter, getParameter, getProperty, getSelectionFields, getSelectionFields, getSession, 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, intersect, intersect, intersectAll, intersectAll, isClassTypeExpression, isCompoundExpression, isConstantExpression, isEmpty, isExpressionBuilder, isFieldExpression, isFragment, isFunctionExpression, 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, localDate, localDateTime, localTime, 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, printJava, rebuildOn, ref, regexp, regexp, registerIn, 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, sql, standardDeviation, subQuery, substring, substring, substring, substring, sum, toChar, toChar, toCharacter, toDate, toLowerCase, toNumber, toString, toString, toUpperCase, toUppercaseCasedWords, translate, treat, trim, trim, truncateDate, twist, twistedForBaseAndContext, type, union, union, unionAll, unionAll, validateNode, value, value, value, value, value, value, value, value, value, value, valueFromObject, valueFromObject, variance, writeAlias, writeDescriptionOn, writeField, writeFields
-
-
-
-
Field Detail
-
derivedTables
protected List<Expression> derivedTables
-
derivedFields
protected List<Expression> derivedFields
-
hasBeenNormalized
protected boolean hasBeenNormalized
-
tableAliases
protected TableAliasLookup tableAliases
-
asOfClause
protected AsOfClause asOfClause
-
-
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.- Overrides:
equalsin classExpression
-
addDerivedField
public void addDerivedField(Expression addThis)
-
addDerivedTable
public void addDerivedTable(Expression addThis)
-
asOf
public Expression asOf(AsOfClause clause)
Description copied from class:ExpressionSets 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:
asOfin 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)
-
aliasForTable
public DatabaseTable aliasForTable(DatabaseTable table)
INTERNAL: Find the alias for a given table- Overrides:
aliasForTablein classExpression
-
assignAlias
protected void assignAlias(String name, DatabaseTable table)
INTERNAL: Alias a particular table within this node- Overrides:
assignAliasin classExpression
-
assignAlias
protected void assignAlias(DatabaseTable alias, DatabaseTable table)
INTERNAL: Alias a particular table within this node
-
clearAliases
public void clearAliases()
INTERNAL:
-
copyCollection
public List<Expression> copyCollection(List<Expression> in, Map alreadyDone)
-
existingDerivedField
public Expression existingDerivedField(DatabaseField field)
INTERNAL:
-
existingDerivedTable
public Expression existingDerivedTable(DatabaseTable table)
INTERNAL:
-
getAliasedField
public DatabaseField getAliasedField()
INTERNAL: Return the field appropriately aliased
-
getAsOfClause
public AsOfClause getAsOfClause()
Description copied from class:ExpressionAnswers the past time the expression is explicitly as of.- Overrides:
getAsOfClausein classExpression- Returns:
- An immutable object representation of the past time.
nullif no clause set,AsOfClause.NO_CLAUSEif clause explicitly set tonull. - See Also:
Expression.asOf(org.eclipse.persistence.history.AsOfClause),Expression.hasAsOfClause()
-
getDescriptor
public ClassDescriptor getDescriptor()
-
getField
public DatabaseField getField()
INTERNAL:
-
getField
public Expression getField(String fieldName)
Description copied from class:ExpressionADVANCED: Return an expression representing a field in a data-level query. This is used internally in EclipseLink, or to construct queries involving fields and/or tables that are not mapped.Example:
builder.getField("ADDR_ID").greaterThan(100); builder.getTable("PROJ_EMP").getField("TYPE").equal("S");- Overrides:
getFieldin classExpression
-
getField
public Expression getField(DatabaseField field)
Description copied from class:ExpressionADVANCED: Return an expression representing a field in a data-level query. This is used internally in EclipseLink, or to construct queries involving fields and/or tables that are not mapped.Example:
builder.getField(aField).greaterThan(100);
- Overrides:
getFieldin classExpression
-
getContainingDescriptor
public ClassDescriptor getContainingDescriptor()
INTERNAL: Return the descriptor which contains this query key.
-
getMapping
public DatabaseMapping getMapping()
-
getQueryKeyOrNull
public QueryKey getQueryKeyOrNull()
-
getTable
public Expression getTable(String tableName)
Description copied from class:ExpressionADVANCED: Return an expression representing a table in a data-level query. This is used internally in EclipseLink, or to construct queries involving fields and/or tables that are not mapped.Example:
builder.getTable("PROJ_EMP").getField("TYPE").equal("S");- Overrides:
getTablein classExpression
-
getTable
public Expression getTable(DatabaseTable table)
Description copied from class:ExpressionADVANCED: Return an expression representing a table in a data-level query. This is used internally in EclipseLink, or to construct queries involving fields and/or tables that are not mapped.Example:
builder.getTable(linkTable).getField("TYPE").equal("S");- Overrides:
getTablein classExpression
-
getTableAliases
public TableAliasLookup getTableAliases()
INTERNAL: Return the aliases used. For CR#2456 must never lazily initialize as also used for Expression identity.- Overrides:
getTableAliasesin classExpression
-
hasBeenNormalized
public boolean hasBeenNormalized()
INTERNAL: Did the normalizer already add additional joins to the where clause due to this query key representing a foreign reference mapping? This insures that join criteria (for any query key expression) is not added twice.New meaning: DataExpressions are often iterated on multiple times during normalize, but Function/Relation expressions only once. Adding a has been normalized flag improves performance and is required in some applications, such as have temporal query criteria been added.
-
hasAsOfClause
public boolean hasAsOfClause()
Description copied from class:ExpressionADVANCED: Answers true ifthisis to be queried as of a past time.- Overrides:
hasAsOfClausein classExpression- Returns:
- false from
asOf(null); hasAsOfClause(). - See Also:
Expression.getAsOfClause()
-
hasBeenAliased
public boolean hasBeenAliased()
Description copied from class:ExpressionINTERNAL: Answers if the database tables associated with this expression have been aliased. This insures the same tables are not aliased twice.- Overrides:
hasBeenAliasedin classExpression
-
hasDerivedFields
protected boolean hasDerivedFields()
-
hasDerivedTables
protected boolean hasDerivedTables()
-
isAttribute
public boolean isAttribute()
INTERNAL:
-
isDataExpression
public boolean isDataExpression()
Description copied from class:ExpressionINTERNAL:- Overrides:
isDataExpressionin classExpression
-
iterateOn
public void iterateOn(ExpressionIterator iterator)
INTERNAL: For iterating using an inner class- Overrides:
iterateOnin classExpression
-
newDerivedField
public Expression newDerivedField(DatabaseField field)
INTERNAL:
-
newDerivedTable
public Expression newDerivedTable(DatabaseTable table)
INTERNAL:
-
getAlias
public Expression getAlias(Expression subSelect)
ADVANCED: Return an expression representing a sub-select in the from clause.Example:
builder.getAlias(builder.subQuery(reportQuery)).get("type").equal("S");- Overrides:
getAliasin classExpression
-
normalize
public Expression normalize(ExpressionNormalizer normalizer)
INTERNAL: Normalize the expression into a printable structure. Any joins must be added to form a new root.- Overrides:
normalizein classExpression
-
postCopyIn
protected void postCopyIn(Map alreadyDone)
INTERNAL: Used for cloning.- Overrides:
postCopyInin classBaseExpression
-
printSQL
public void printSQL(ExpressionSQLPrinter printer)
INTERNAL: Print SQL onto the stream, using the ExpressionPrinter for context- Specified by:
printSQLin classExpression
-
setHasBeenNormalized
public void setHasBeenNormalized(boolean value)
-
setTableAliases
public void setTableAliases(TableAliasLookup tableAliases)
INTERNAL: For CR#2456, Table identity involves having two tables sharing the same aliasing table.
-
tableAliasesDescription
public String tableAliasesDescription()
-
writeSubexpressionsTo
public void writeSubexpressionsTo(BufferedWriter writer, int indent) throws IOException
Print the base for debuggin purposes.- Overrides:
writeSubexpressionsToin classExpression- Throws:
IOException
-
-