Modification Listener
Jan Wiemer edited this page Dec 30, 2020
·
3 revisions
Modification listeners can be registered at a store to react on modifications committed on the objects in the store on commit.
All modification listeners have to implement the JacisModificationListener
interface declaring the onModification
methods
that is called for each modified object that is written back from the TX-View to the store:
public interface JacisModificationListener<K, V> {
void onModification(K key, V oldValue, V newValue, JacisTransactionHandle tx);
}
The following example shows a modification listener simply logging each modification:
public static class ExampleJacisModificationListener implements JacisModificationListener<String, Account> {
@Override
public void onModification(String key, Account oldValue, Account newValue, JacisTransactionHandle tx) {
System.out.println("modified " + key + ": " + newValue + "(by " + tx + ")");
}
}
To register a modification listener at a store it has to be passed as parameter to the registerModificationListener
at the JacisStore
. The following example shows how to register a modification listener:
JacisContainer container = new JacisContainer();
JacisObjectTypeSpec<String, Account, Account> objectTypeSpec = //
new JacisObjectTypeSpec<>(String.class, Account.class, new JacisCloningObjectAdapter<>());
JacisStore<String, Account> store = container.createStore(objectTypeSpec).getStore();
// register example modification listener at the store:
JacisModificationListener<String, Account> listener = new ExampleJacisModificationListener();
store.registerModificationListener(listener);
...
Next Chapter: Object Adapter