Page Edited :
CAYDOC :
Lifecycle Callbacks
Lifecycle Callbacks has been edited by Andrus Adamchik (Dec 26, 2006). Content:(in 3.0 since 9/21/2006) TODO: annotations, default callback for all entities, Modeler support Users can register callback methods that will be invoked during the lifecycle of persistent objects. Callback mechanism matches closely the one defined in the JPA Specification (except that it works with JDK 1.4 and allows preconfigured listeners). There are seven lifecycle callbacks described below (PrePersist, PostPersist, PreUpdate, PostUpdate, PreRemove, PostRemove, PostLoad). There are two types of invocations for each one of them: callback on a persistent object itself or a callback on an arbitrary listener object.
Callback Method Semantics
Callback on persistent object example: public class Artist {
... // a vaid callback method protected void setDefaultProperties() { ... } } Callback on a listener class example: public class MyListener { ... // a valid callback method public void initArtist(Artist a) { ... } } Types of Callbacks
Enabling CallbacksTODO: expect this to be changed to something more user-friendly. Registering listener: DataDomain domain = ... int callbackType = LifecycleEventCallback.PRE_PERSIST; // choose callback type you care about domain.getEntityResolver().getCallbacks(callbackType).addListener( MyEntity.class, new MyListener(), "callbackMethod"); Building ObjectContext with enabled callbacks: DataChannelCallbackInterceptor postInterceptor = new DataChannelCallbackInterceptor(); postInterceptor.setChannel(domain); ObjectStore objectStore = new ObjectStore(domain.getSharedSnapshotCache()); ObjectContextCallbackInterceptor preInterceptor = new ObjectContextCallbackInterceptor(); preInterceptor.setContext(new DataContext(postInterceptor, objectStore)); ObjectContext userContext = preInterceptor; |
Unsubscribe or edit your notifications preferences