Skip to content
okram edited this page Jan 23, 2011 · 21 revisions

A Graph that implements the TransactionalGraph interface is a graph that supports Blueprints-style transactions. A TransactionalGraph has the following methods:

public void setTransactionMode(Mode mode);
public Mode getTransactionMode();
public void startTransaction();
public void stopTransaction(Conclusion conclusion);

Automatic Transactions

A TransactionalGraph supports two modes Mode.AUTOMATIC and Mode.MANUAL. In automatic transaction mode, every manipulation of the graph (e.g. set/remove property, add/remove vertex, add/remove edge) is automatically wrapped in a transaction and committed when the respective method completes. In this way, the developer does not need to start and stop transactions as this is automatically handled by the implementation. Upon construction, every TransactionalGraph is in automatic transaction model. In manual transaction mode, the developer is required to manually start and stop transactions when editing the graph. Note that automatic transactions are useful in terms of simplfying code, but are less performant than manual transactions.

Manual Transactions

To put a graph in manual transaction model, evaluate the following:

txGraph.setTransactionMode(TransactionalGraph.Mode.MANUAL);

Upon doing so, any edit operation (or group of edit operations) must be wrapped in a transaction. This is done as follows.

txGraph.startTransaction();
// edit operations
tx.stopTransaction(TransactionalGraph.Conclusion.SUCCESS);

There are two types of conclusions: Conclusion.SUCCESS and Conclusion.FAILURE. When a transaction is successful, it is committed to the underlying store. When the transaction is a failure, then all the edit operations up to the start of the transaction are rolled back. Note: Blueprints-enabled graphs do not require transactions for read-based operations.