Skip to content

Graph Transactions

okram edited this page May 14, 2012 · 27 revisions

A Graph that implements the TransactionalGraph or ThreadedTransactionalGraph interfaces must natively support transaction handling.

TransactionalGraph and Starting and Stopping Transactions

A TransactionalGraph has the following methods.

public void startTransaction();
public void stopTransaction(Conclusion conclusion);

When a transaction is started, all the subsequent mutation operations in the transaction occur within a transaction context. When the transaction is successfully stopped, those mutations operations are persisted and visible to other contexts interacting with the graph. If a transaction is failed, then the mutation operations are “rolled back” to when the transaction was started.

To facilitate ease of use, a call to startTransaction() is not required. If a mutating operation is evaluated and a transaction has not been started, then a transaction is automatically started. However, it is up to the user to stopTransaction(Conclusion conclusion) or else they run the risk of a OutOfMemoryException if too many mutations have occurred. Finally, note that a TransactionalGraph.shutdown() will automatically successfully commit any open transaction.

ThreadedTransactionalGraph and Multi-Threads for One Transaction

A ThreadedTransactionalGraph extends TransactionalGraph with a single method.

``java
public TransactionalGraph startThreadTransaction()
```