OpenRDF Sesame already offers basic transaction handling and update notification support in any OpenRDF sail stack around a NotifyingSail. This module builds on this functionality to provide a mechanism for keeping track of all changes (added and removed triples) occurring between the time a transaction began and the time the transaction was committed or rolled back. The transaction data is then handed over to all registered transaction listeners at certain event points (in analogy to JPA we offer “before commit”, “after commit”, “on rollback”). Since the KiWi transaction support builds upon the NotifyingSail, it can be used in any OpenRDF sail stack, independently of the other KiWi modules.
Extended transaction support is e.g. used by the versioning component (each transaction is considered a unit of work or version) and by the reasoner (on transaction commit, the transaction data is handed to the incremental reasoner). It is also used by some extended Apache Marmotta and Linked Media Framework functionalities like the LMF Semantic Search.
To use the extended transaction support, include the following artifact in your Maven build file:
<dependency> <groupId>org.apache.marmotta</groupId> <artifactId>kiwi-transactions</artifactId> <version>3.3.0</version> </dependency>
In your code, the KiWi extended transactions can easily be stacked into your sail stack around any NotifyingSail. Event listeners can be added/removed by calling the appropriate addTransactionListener and removeTransactionListener methods:
KiWiTransactionalSail sail = new KiWiTransactionalSail(new MemoryStore()); sail.addTransactionListener(...); Repository repository = new SailRepository(sail); ...
The TransactionListener interface defines three methods: