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. TopLink 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:
Watch out for x.asOf(oneTime).get("y").asOf(anotherTime).
this
@since OracleAS TopLink 10g (10.0.3)
@see org.eclipse.persistence.history.AsOfClause
@see #hasAsOfClause
@see org.eclipse.persistence.sessions.Session#acquireHistoricalSession(org.eclipse.persistence.history.AsOfClause)
@see org.eclipse.persistence.queries.ObjectLevelReadQuery#setAsOfClause(org.eclipse.persistence.history.AsOfClause))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|