![]() | ![]() |
![]() |
| Project | Ver 1.1 | Ver 1.2 | JDO | JPA | Guides | Tools |
| 1.2 | Persistence | JDO ORM | JPA ORM | Runtime | JDO Runtime | JPA Runtime | Extensions | Developer |
![]() JDO 1.0 and 2.0 define an interface for PersistenceCapable classes so that they can be notified of events in their own lifecycle and perform any additional operations that are needed at these checkpoints. This is a complement to the Lifecycle Listeners interface which provides listeners for all objects of particular classes, with the events sent to a listener. With InstanceCallbacks the PersistenceCapable class is the destination of the lifecycle events. As a result the Instance Callbacks method is more intrusive than the method of Lifecycle Listeners in that it requires methods adding to each class that wishes to receive the callbacks.
JPOX supports the InstanceCallbacks interface
To give an example of this capability, let us define a class that needs to perform some operation just before it's object is deleted.
public class MyClass implements InstanceCallbacks
{
String name;
... (class methods)
public void jdoPostLoad() {}
public void jdoPreClear() {}
public void jdoPreStore() {}
public void jdoPreDelete()
{
// Perform some operation just before being deleted.
}
}So we have implemented InstanceCallbacks and have defined the 4 required methods. Only one of these is of importance in this example. These methods will be called just before storage in the data store (jdoPreStore), just before clearing (jdoPreClear), just after being loaded from the datastore (jdoPostLoad) and just before being deleted (jdoPreDelete).
JDO2 adds 2 new callbacks to complement InstanceCallbacks. These are AttachCallback
public interface AttachCallback
{
public void jdoPreAttach();
public void jdoPostAttach(Object attached);
}
public interface DetachCallback
{
public void jdoPreDetach();
public void jdoPostDetach(Object detached);
} |