Cayenne User Documentation
DataContextDelegate

DataContext supports runtime customization via a DataContextDelegate interface. A user can assign a custom delegate instance to a DataContext by calling DataContext.setDelegate(..). Delegate is optional, and if it is not set, DataContext would go on with its default behavior. If a delegate is set, DataContext consults with it at some critical points in the normal flow execution. A delegate can modify the flow, abort an operation, modify objects participating in an operation, or perform any other tasks it deems necessary.

DataContextDelegate currently has two groups of methods - method to filter select queries, and methods to react to external updates of the ObjectStore:

- `public Query willPerformQuery(DataContext context, Query query)`

Called from DataContext.performQuery(...) before running any select query, including prefetch queries. Implementation has a choice to modify an original query, replace it with alternative one, or return NULL, blocking query execution alltogether.

- `public boolean shouldMergeChanges(DataObject object, DataRow snapshotInStore)`
  `public boolean shouldProcessDelete(DataObject object)`
  `public void finishedMergeChanges(DataObject object)`
  `public void finishedProcessDelete(DataObject object)`

These methods are called by the ObjectStore whenever it performs an update of its state triggered by external events. Default ObjectStore behavior is to merge all changes to the existing objects, and change deleted objects state to TRANSIENT, removing them from the store. Delegate has an option to abort standard processing by returning "false" from "should*" methods.

.
Copyright ©2001-2006 Apache Software Foundation