Skip to content

Persistence Adapter

Jan Wiemer edited this page Jan 10, 2021 · 8 revisions

Persistence Adapter

The default version of the JACIS does not focus on the durability (the D from the ACID transaction properties). However it is possible to extend the store with a durable persistent storage of the committed objects. For this purpose the JACIS provides an extension point where different persistence frameworks can be attached to the store.

The Persistence Adapter Extension Point

An extension enabling the persistent storage of the objects is called persistence adapter and has to implement the JacisPersistenceAdapter interface. The persistence adapter can be set at the JacisObjectTypeSpec with method setPersistenceAdapter. By default there is no persistence adapter and nothing is persisted at all.

The following methods have to be implemented to fulfill the JacisPersistenceAdapter interface (some of them are optional):

void initializeStore(JacisStoreImpl<K, V, ?> store);

Called after the creation of the store to initialize the objects in the store from the persistent storage. The objects could be stored using the normal API in the store, but it is also possible to use the initStoreNonTransactional methods.

void onModification(K key, V oldValue, V newValue, JacisTransactionHandle tx);

Inherited from the JacisModificationListener interface. The method is called for each object cloned back from a TX-View to the committed objects (see chapter Modification Listener).

void afterPrepareForStore();

Called after the prepare phase for the store has been executed (optional).

void afterCommitForStore();

Called after the commit for the store has been executed (optional).

void afterRollbackForStore();

Called after a rollback for the store has been executed (optional).

void afterCommit(JacisContainer container, JacisTransactionHandle tx);

Called after the commit for the JACIS container, after all stores have been committed (optional).

void afterRollback(JacisContainer container, JacisTransactionHandle tx);

Called after the rollback for the JACIS container, after all stores have been committed (optional).

Furthermore other methods declared by the JacisTransactionListener can be implemented to react on a certain event. Usually a transaction adapter has to care about the following tasks:

  • When the store is created it has to initialize the store with the already persisted data. This happens in the initializeStore method.

  • Each modification done by the store on the committed objects have to be tracked in the onModification method.

  • The tracked modifications have finally be committed either in the after the commit for the single store (method afterCommitForStore) or after the global commit for the whole JACIS container (method afterCommit).

  • If a transaction is rolled back the tracked modifications have to be discarded.