The Record<T>
notifier provides
notification for object creation, modification, and deletion.
Specifically, these methods:
created
- called when an object is
created.
modified
- called when an object is
modified.
deleted
- called when an object is
deleted.
The methods in this notifier are always called on the master node for an object.
The created
and deleted
methods are not called if an object is created and deleted in the same
transaction.
The modified
method is only called once per
transaction, even if an object is modified multiple times. The
modified
method is not called for objects that are
created or deleted in a transaction.
The deleted
method is called before an object is
deleted.
notifiers are
inherited by any children of the type on which they are installed, unless
a Record<T>
Record<T>
notifier is explicitly installed on
one of the child types.
Example 10.4. Record notifier
// $Revision: 1.1.2.3 $ package com.kabira.snippets.store; import com.kabira.platform.ManagedObject; import com.kabira.platform.Transaction; import com.kabira.platform.annotation.Managed; import com.kabira.store.Record; /** * Secondary store record notifier * <p> * <h2> Target Nodes</h2> * <ul> * <li> <b>domainnode</b> = A * </ul> */ public class RecordNotifier { @Managed private static class Parent { void increment() { m_count++; } private long m_count = 0; }; private static class Child extends Parent { }; private static class Notifier extends Record<Parent> { public Notifier() { super(Parent.class); } @Override public void deleted(Parent parent) { System.out.println("INFO: Deleted " + parent); } @Override public void modified(Parent parent) { System.out.println("INFO: Modified " + parent); } @Override public void created(Parent parent) { System.out.println("INFO: Created " + parent); } } /** * Main entry point * @param args Not used */ public static void main (final String [ ] args) { new Transaction("Create Child") { @Override protected void run() { new Notifier(); m_child = new Child(); } }.execute(); new Transaction("Modify Child") { @Override protected void run() { m_child.increment(); } }.execute(); new Transaction("Delete Child") { @Override protected void run() { ManagedObject.delete(m_child); m_child = null; } }.execute(); } private static Child m_child; }
When the Example 10.4, “Record notifier” is run it outputs these messages:
INFO: Created com.kabira.snippets.store.RecordNotifier$Child@106c202d INFO: Modified com.kabira.snippets.store.RecordNotifier$Child@106c202d INFO: Deleted com.kabira.snippets.store.RecordNotifier$Child@106c202d