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

public abstract Class DataExpression

extends BaseExpression
Class Inheritance
Known Direct Subclasses
org.eclipse.persistence.internal.expressions.FieldExpression, org.eclipse.persistence.internal.expressions.ObjectExpression, org.eclipse.persistence.internal.expressions.TableExpression, org.eclipse.persistence.internal.expressions.ClassTypeExpression
Imports
java.io.BufferedWriter, .IOException, java.util.ArrayList, .List, .Map, org.eclipse.persistence.descriptors.ClassDescriptor, org.eclipse.persistence.expressions.Expression, org.eclipse.persistence.history.AsOfClause, org.eclipse.persistence.internal.helper.DatabaseField, .DatabaseTable, org.eclipse.persistence.internal.history.DecoratedDatabaseTable, org.eclipse.persistence.mappings.DatabaseMapping, org.eclipse.persistence.mappings.querykeys.QueryKey

Superclass for all expression that have a context. i.e. a base expression.

Field Summary

Modifier and TypeField and Description
protected AsOfClause
protected List<Expression>
protected List<Expression>
protected boolean
protected TableAliasLookup
Inherited from org.eclipse.persistence.internal.expressions.BaseExpression:
baseExpressionbuilder

Constructor Summary

AccessConstructor and Description
protected
DataExpression()

DataExpression constructor comment.

Method Summary

Modifier and TypeMethod and Description
public void
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.
protected void
assignAlias(String name, DatabaseTable table)

Overrides org.eclipse.persistence.expressions.Expression.assignAlias.

INTERNAL: Alias a particular table within this node
protected void
assignAlias(DatabaseTable alias, DatabaseTable table)

INTERNAL: Alias a particular table within this node

public void
clearAliases()

INTERNAL:

public List<Expression>
copyCollection(List<Expression> in, Map<K, V> alreadyDone)

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 Expression
public Expression
public Expression
getAlias(Expression subSelect)

Overrides org.eclipse.persistence.expressions.Expression.getAlias.

ADVANCED: Return an expression representing a sub-select in the from clause.
public DatabaseField
getAliasedField()

INTERNAL: Return the field appropriately aliased

public AsOfClause
getAsOfClause()

Overrides org.eclipse.persistence.expressions.Expression.getAsOfClause.

Answers the past time the expression is explicitly as of.
public ClassDescriptor
getContainingDescriptor()

INTERNAL: Return the descriptor which contains this query key.

public ClassDescriptor
public DatabaseField
getField()

INTERNAL:

public Expression
getField(String fieldName)

Overrides org.eclipse.persistence.expressions.Expression.getField.

ADVANCED: Return an expression representing a field in a data-level query.
public Expression
getField(DatabaseField field)

Overrides org.eclipse.persistence.expressions.Expression.getField.

ADVANCED: Return an expression representing a field in a data-level query.
public DatabaseMapping
public QueryKey
public Expression
getTable(String tableName)

Overrides org.eclipse.persistence.expressions.Expression.getTable.

ADVANCED: Return an expression representing a table in a data-level query.
public Expression
getTable(DatabaseTable table)

Overrides org.eclipse.persistence.expressions.Expression.getTable.

ADVANCED: Return an expression representing a table in a data-level query.
public TableAliasLookup
public boolean
hasAsOfClause()

Overrides org.eclipse.persistence.expressions.Expression.hasAsOfClause.

ADVANCED: Answers true if this is to be queried as of a past time.
public boolean
hasBeenAliased()

Overrides org.eclipse.persistence.expressions.Expression.hasBeenAliased.

INTERNAL: Answers if the database tables associated with this expression have been aliased.
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?

protected boolean
protected boolean
public boolean
isAttribute()

INTERNAL:

public boolean
public void
iterateOn(ExpressionIterator iterator)

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

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

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

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

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

INTERNAL: Used for cloning.
public void
printSQL(ExpressionSQLPrinter printer)

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

INTERNAL: Print SQL onto the stream, using the ExpressionPrinter for context
public void
setHasBeenNormalized(boolean value)

public void
setTableAliases(TableAliasLookup tableAliases)

INTERNAL: For CR#2456, Table identity involves having two tables sharing the same aliasing table.

public String
public void
writeSubexpressionsTo(BufferedWriter writer, int indent)

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

Print the base for debuggin purposes.
Inherited from org.eclipse.persistence.internal.expressions.BaseExpression:
getBaseExpressiongetBuilderresetPlaceHolderBuildersetBaseExpressionshallowClone

Field Detail

asOfClauseback to summary
protected AsOfClause asOfClause
derivedFieldsback to summary
protected List<Expression> derivedFields
derivedTablesback to summary
protected List<Expression> derivedTables
hasBeenNormalizedback to summary
protected boolean hasBeenNormalized
tableAliasesback to summary
protected TableAliasLookup tableAliases

Constructor Detail

DataExpressionback to summary
protected DataExpression()

DataExpression constructor comment.

Method Detail

addDerivedFieldback to summary
public void addDerivedField(Expression addThis)
addDerivedTableback to summary
public void addDerivedTable(Expression addThis)
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
assignAliasback to summary
protected void assignAlias(String name, DatabaseTable table)

Overrides org.eclipse.persistence.expressions.Expression.assignAlias.

INTERNAL: Alias a particular table within this node

Annotations
@Override
assignAliasback to summary
protected void assignAlias(DatabaseTable alias, DatabaseTable table)

INTERNAL: Alias a particular table within this node

clearAliasesback to summary
public void clearAliases()

INTERNAL:

copyCollectionback to summary
public List<Expression> copyCollection(List<Expression> in, Map<K, V> alreadyDone)
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
existingDerivedFieldback to summary
public Expression existingDerivedField(DatabaseField field)

INTERNAL:

existingDerivedTableback to summary
public Expression existingDerivedTable(DatabaseTable table)

INTERNAL:

getAliasback to summary
public Expression getAlias(Expression subSelect)

Overrides org.eclipse.persistence.expressions.Expression.getAlias.

ADVANCED: Return an expression representing a sub-select in the from clause.

Example:

 builder.getAlias(builder.subQuery(reportQuery)).get("type").equal("S");
Annotations
@Override
getAliasedFieldback to summary
public DatabaseField getAliasedField()

INTERNAL: Return the field appropriately aliased

getAsOfClauseback to summary
public AsOfClause getAsOfClause()

Overrides org.eclipse.persistence.expressions.Expression.getAsOfClause.

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

Answers the past time the expression is explicitly as of.

Returns:AsOfClause

An immutable object representation of the past time. null if no clause set, AsOfClause.NO_CLAUSE if clause explicitly set to null.

Annotations
@Override
getContainingDescriptorback to summary
public ClassDescriptor getContainingDescriptor()

INTERNAL: Return the descriptor which contains this query key.

getDescriptorback to summary
public ClassDescriptor getDescriptor()
getFieldback to summary
public DatabaseField getField()

INTERNAL:

getFieldback to summary
public Expression getField(String fieldName)

Overrides org.eclipse.persistence.expressions.Expression.getField.

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

ADVANCED: 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");
Annotations
@Override
getFieldback to summary
public Expression getField(DatabaseField field)

Overrides org.eclipse.persistence.expressions.Expression.getField.

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

ADVANCED: 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);
Annotations
@Override
getMappingback to summary
public DatabaseMapping getMapping()
getQueryKeyOrNullback to summary
public QueryKey getQueryKeyOrNull()
getTableback to summary
public Expression getTable(String tableName)

Overrides org.eclipse.persistence.expressions.Expression.getTable.

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

ADVANCED: 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");
Annotations
@Override
getTableback to summary
public Expression getTable(DatabaseTable table)

Overrides org.eclipse.persistence.expressions.Expression.getTable.

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

ADVANCED: 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");
Annotations
@Override
getTableAliasesback to summary
public TableAliasLookup getTableAliases()

Overrides org.eclipse.persistence.expressions.Expression.getTableAliases.

INTERNAL: Return the aliases used. For CR#2456 must never lazily initialize as also used for Expression identity.

Annotations
@Override
hasAsOfClauseback to summary
public boolean hasAsOfClause()

Overrides org.eclipse.persistence.expressions.Expression.hasAsOfClause.

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

ADVANCED: Answers true if this is to be queried as of a past time.

Returns:boolean

false from asOf(null); hasAsOfClause().

Annotations
@Override
hasBeenAliasedback to summary
public boolean hasBeenAliased()

Overrides org.eclipse.persistence.expressions.Expression.hasBeenAliased.

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

INTERNAL: Answers if the database tables associated with this expression have been aliased. This insures the same tables are not aliased twice.

Annotations
@Override
hasBeenNormalizedback to summary
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.

hasDerivedFieldsback to summary
protected boolean hasDerivedFields()
hasDerivedTablesback to summary
protected boolean hasDerivedTables()
isAttributeback to summary
public boolean isAttribute()

INTERNAL:

isDataExpressionback to summary
public boolean isDataExpression()

Overrides org.eclipse.persistence.expressions.Expression.isDataExpression.

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

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
newDerivedFieldback to summary
public Expression newDerivedField(DatabaseField field)

INTERNAL:

newDerivedTableback to summary
public Expression newDerivedTable(DatabaseTable table)

INTERNAL:

normalizeback to summary
public Expression normalize(ExpressionNormalizer normalizer)

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

INTERNAL: Normalize the expression into a printable structure. Any joins must be added to form a new root.

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
printSQLback to summary
public void printSQL(ExpressionSQLPrinter printer)

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

INTERNAL: Print SQL onto the stream, using the ExpressionPrinter for context

Annotations
@Override
setHasBeenNormalizedback to summary
public void setHasBeenNormalized(boolean value)
setTableAliasesback to summary
public void setTableAliases(TableAliasLookup tableAliases)

INTERNAL: For CR#2456, Table identity involves having two tables sharing the same aliasing table.

tableAliasesDescriptionback to summary
public String tableAliasesDescription()
writeSubexpressionsToback to summary
public void writeSubexpressionsTo(BufferedWriter writer, int indent) throws IOException

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

Print the base for debuggin purposes.

Annotations
@Override