Package wt.fc.batch

Provides a mechanism for specifying operations that affect mulitple objects in the persistent datastore.

See:
          Description

Class Summary
AbstractBatchSpec This class specifies the contract for processing multiple row update and delete operations.
BatchSpecificationUtilities Utility methods for processing batch specification operations.
DeleteBatchSpec This class implements processing multiple row delete operations.
UpdateBatchSpec This class implements processing multiple row update operations.
UpdateColumnExpression This class specifies a ClassAttribute and associate expression that is used for batch specficiation update.
 

Package wt.fc.batch Description

Provides a mechanism for specifying operations that affect mulitple objects in the persistent datastore.

A batch specification operation is executed using the PersistenceManagerSvr.execute(wt.fc.batch.AbstractBatchSpec) method and directly modifies the persistent state of objects in the datastore. Events associated with modify and delete are not guaranteed to be generated when a batch specification is executed. Any in-memory Persistable objects are not affected. Therefore, when using this functionality, care must be taken to ensure that any in-memory objects are refreshed to avoid stale exceptions. In terms of performance, this functionality should generally only be used when refreshing the target objects is not necessary.

The target of batch specification operation is specified using a ClassTableExpression. The AbstractClassTableExpression.setExcludedDescendants(java.util.List), AbstractClassTableExpression.setDescendantsIncluded(boolean), and AbstractClassTableExpression.setIncludedInterfaces(java.util.List) methods can all be used to further specify which concrete sub-classes and associated tables are affected.

Update

Persistable objects that are already persisted in the datastore can be updated using the UpdateBatchSpec. The general pattern for constructing an UpdateBatchSpec and executing it is as follows.

  1. Create an UpdateBatchSpec object.
  2. Set the target class using AbstractBatchSpec.setTarget(wt.query.ClassTableExpression) and ClassTableExpression.
  3. Set the columns and associated values to update using UpdateBatchSpec.setUpdateColumns(wt.fc.batch.UpdateColumnExpression[]) and UpdateColumnExpression.
  4. Set or add criteria to specify the objects in the persistent datastore that will be affected using AbstractBatchSpec.setWhere(wt.query.WhereExpression) or AbstractBatchSpec.appendWhere(wt.query.WhereExpression, wt.query.LogicalOperator), respectively.
  5. Execute the UpdateBatchSpec object using PersistenceManagerSvr.execute(wt.fc.batch.AbstractBatchSpec) .

Example:

UpdateBatchSpec batchSpec = new UpdateBatchSpec(); 

batchSpec.setTarget(new ClassTableExpression(Customer.class));

ClassAttribute nameAttribute = new ClassAttribute(Customer.class, Customer.NAME);
UpdateColumnExpression[] updateColumns = new UpdateColumnExpression[1];
updateColumns[0] = new UpdateColumnExpression(nameAttribute, new ConstantExpression("SMITH"));
batchSpec.setUpdateColumns(updateColumns);

SearchCondition criteria = new SearchCondition(nameAttribute, SearchCondition.EQUAL, new ConstantExpression("smith"));
batchSpec.setWhere(criteria);

int count = PersistenceServerHelper.manager.execute(batchSpec);

Steps #1-4 can be combined using the single call to the constructor UpdateBatchSpec.UpdateBatchSpec(wt.query.ClassTableExpression,wt.query.WhereExpression,UpdateColumnExpression[]).

The persistence service updates the affected objects' persistence attributes in the datastore. The “thePersistInfo.updateCount” attribute is incremented by 1. If "thePersistInfo.updateStamp” is specified in the UpdateColumnExpressions list, then the specified update value will be set, otherwise, it is set to the MethodServer's current time. If any of the following attributes are specified in the UpdateColumnExpressions list, then an exception will be thrown.

Delete

Persistable objects that are already persisted in the datastore can be deleted using the DeleteBatchSpec. The general pattern for constructing a DeleteBatchSpec and executing it is as follows.

  1. Create a DeleteBatchSpec object.
  2. Set the target class using AbstractBatchSpec.setTarget(wt.query.ClassTableExpression) and ClassTableExpression.
  3. Set or add criteria to specify the objects in the persistent datastore that will be affected using AbstractBatchSpec.setWhere(wt.query.WhereExpression) or AbstractBatchSpec.appendWhere(wt.query.WhereExpression, wt.query.LogicalOperator), respectively.
  4. Execute the DeleteBatchSpec object using PersistenceManagerSvr.execute(wt.fc.batch.AbstractBatchSpec) .

Example:

DeleteBatchSpec batchSpec = new DeleteBatchSpec(); 

batchSpec.setTarget(new ClassTableExpression(Customer.class));

ClassAttribute nameAttribute = new ClassAttribute(Customer.class, Customer.NAME);
SearchCondition criteria = new SearchCondition(nameAttribute, SearchCondition.EQUAL, new ConstantExpression("smith"));
batchSpec.setWhere(criteria);

int count = PersistenceServerHelper.manager.execute(batchSpec);

Steps #1-3 can be combined using the single call to the constructor DeleteBatchSpec.DeleteBatchSpec(wt.query.ClassTableExpression,wt.query.WhereExpression).

If necessary, the persistence service will also perform referential integrity processing on the affected objects. The processing is identical to retrieving the affected objects from the datastore and executing PersistenceManagerSvr.remove(wt.fc.collections.WTSet) on the affected objects.