Class AbstractTransaction
java.lang.Object
org.apache.tinkerpop.gremlin.structure.util.AbstractTransaction
- All Implemented Interfaces:
AutoCloseable,Transaction
- Direct Known Subclasses:
AbstractThreadedTransaction,AbstractThreadLocalTransaction
A simple base class for
Transaction that provides some common functionality and default behavior.
While providers can choose to use this class, it is generally better to extend from
AbstractThreadedTransaction or AbstractThreadLocalTransaction which include default "listener"
functionality. Implementers should note that this class assumes that threaded transactions are not enabled
and should explicitly override createThreadedTx() to implement that functionality if required.- Author:
- Stephen Mallette (http://stephen.genoprime.com)
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.tinkerpop.gremlin.structure.Transaction
Transaction.CLOSE_BEHAVIOR, Transaction.Exceptions, Transaction.READ_WRITE_BEHAVIOR, Transaction.Status, Transaction.Symbols -
Field Summary
Fields inherited from interface org.apache.tinkerpop.gremlin.structure.Transaction
NO_OP -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T extends TraversalSource>
TStarts a transaction in the context of a particularTraversalSourceinstance and returns aTraversalSourcebound to it.voidclose()Closes the transaction where the default close behavior defined by {Transaction.onClose(Consumer)} will be executed.voidcommit()Commits a transaction.<G extends Graph>
GCreates a transaction that can be executed across multiple threads.protected abstract voiddoClose()Calledclose().protected abstract voiddoCommit()Called withcommit()after theTransaction.onReadWrite(Consumer)has been notified.protected abstract voiddoOpen()Called withinbegin(Class)if it is determined that the transaction is not yet open givenTransaction.isOpen().protected abstract voidCalledreadWrite().protected abstract voidCalled withrollback()after theTransaction.onReadWrite(Consumer)has been notified.protected abstract voidCalled withincommit()just after the internal call todoCommit().protected abstract voidCalled withinrollback()just after the internal call todoRollback()()}.voidAn internal function that signals a read or a write has occurred - not meant to be called directly by end users.voidrollback()Rolls back a transaction.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.tinkerpop.gremlin.structure.Transaction
addTransactionListener, begin, clearTransactionListeners, isOpen, onClose, onReadWrite, removeTransactionListener
-
Constructor Details
-
AbstractTransaction
-
-
Method Details
-
doOpen
protected abstract void doOpen()Called withinbegin(Class)if it is determined that the transaction is not yet open givenTransaction.isOpen(). Implementers should assume the transaction is not yet started and should thus open one. -
doCommit
Called withcommit()after theTransaction.onReadWrite(Consumer)has been notified. Implementers should include their commit logic here.- Throws:
TransactionException
-
doRollback
Called withrollback()after theTransaction.onReadWrite(Consumer)has been notified. Implementers should include their rollback logic here.- Throws:
TransactionException
-
fireOnCommit
protected abstract void fireOnCommit()Called withincommit()just after the internal call todoCommit(). Implementations of this method should raiseTransaction.Status.COMMITevents to any listeners added viaTransaction.addTransactionListener(Consumer). -
fireOnRollback
protected abstract void fireOnRollback()Called withinrollback()just after the internal call todoRollback()()}. Implementations of this method should raiseTransaction.Status.ROLLBACKevents to any listeners added viaTransaction.addTransactionListener(Consumer). -
doReadWrite
protected abstract void doReadWrite()CalledreadWrite(). Implementers should run their readWrite consumer here. -
doClose
protected abstract void doClose()Calledclose(). Implementers should run their readWrite consumer here. -
commit
public void commit()Commits a transaction. This method may optionally throwTransactionExceptionon error. Providers should consider wrapping their transaction exceptions in this TinkerPop exception as it will lead to better error handling with Gremlin Server and other parts of the stack.- Specified by:
commitin interfaceTransaction
-
rollback
public void rollback()Rolls back a transaction. This method may optionally throwTransactionExceptionon error. Providers should consider wrapping their transaction exceptions in this TinkerPop exception as it will lead to better error handling with Gremlin Server and other parts of the stack.- Specified by:
rollbackin interfaceTransaction
-
createThreadedTx
Creates a transaction that can be executed across multiple threads. TheGraphreturned from this method is not meant to represent some form of child transaction that can be committed from this object. A threaded transaction is aGraphinstance that has a transaction context that enables multiple threads to collaborate on the same transaction. A standard transactional context tied to aGraphthat supports transactions will typically bind a transaction to a single thread viaThreadLocal.- Specified by:
createThreadedTxin interfaceTransaction
-
begin
Starts a transaction in the context of a particularTraversalSourceinstance and returns aTraversalSourcebound to it. If a transaction is not already open for thisTransaction, one is started; if a transaction is already open, this method is idempotent - it does not start a new transaction and does not throw, returning a source bound to the open transaction. The identity of the returned source across calls is unspecified and must not be relied upon. How the returnedTraversalSourceis bound to the transaction's context is up to the implementation and up to users to be aware of that meaning.Starts a transaction if one is not already open for this
Transaction(delegating todoOpen()under anTransaction.isOpen()guard) and returns aTraversalSourcebound to it. This method is idempotent with respect to the transaction: calling it while a transaction is already open does not start a new transaction and does not throw - it simply returns a traversal source bound to the open transaction. The identity of the returned source across calls is unspecified; callers must not rely on reference identity.- Specified by:
beginin interfaceTransaction
-
readWrite
public void readWrite()An internal function that signals a read or a write has occurred - not meant to be called directly by end users.- Specified by:
readWritein interfaceTransaction
-
close
public void close()Closes the transaction where the default close behavior defined by {Transaction.onClose(Consumer)} will be executed.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceTransaction
-