Class AbstractTransaction
- java.lang.Object
-
- org.apache.tinkerpop.gremlin.structure.util.AbstractTransaction
-
- All Implemented Interfaces:
AutoCloseable
,Transaction
- Direct Known Subclasses:
AbstractThreadedTransaction
,AbstractThreadLocalTransaction
public abstract class AbstractTransaction extends Object implements Transaction
A simple base class forTransaction
that provides some common functionality and default behavior. While providers can choose to use this class, it is generally better to extend fromAbstractThreadedTransaction
orAbstractThreadLocalTransaction
which include default "listener" functionality. Implementers should note that this class assumes that threaded transactions are not enabled and should explicitly overridecreateThreadedTx()
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
-
-
Field Summary
-
Fields inherited from interface org.apache.tinkerpop.gremlin.structure.Transaction
NO_OP
-
-
Constructor Summary
Constructors Constructor Description AbstractTransaction(Graph graph)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description <T extends TraversalSource>
Tbegin(Class<T> traversalSourceClass)
Starts a transaction in the context of a particularTraversalSource
instance.void
close()
Closes the transaction where the default close behavior defined by {Transaction.onClose(Consumer)
} will be executed.void
commit()
Commits a transaction.<G extends Graph>
GcreateThreadedTx()
Creates a transaction that can be executed across multiple threads.protected abstract void
doClose()
Calledclose()
.protected abstract void
doCommit()
Called withcommit()
after theTransaction.onReadWrite(Consumer)
has been notified.protected abstract void
doOpen()
Called withinopen()
if it is determined that the transaction is not yet open givenTransaction.isOpen()
.protected abstract void
doReadWrite()
CalledreadWrite()
.protected abstract void
doRollback()
Called withrollback()
after theTransaction.onReadWrite(Consumer)
has been notified.protected abstract void
fireOnCommit()
Called withincommit()
just after the internal call todoCommit()
.protected abstract void
fireOnRollback()
Called withinrollback()
just after the internal call todoRollback()
()}.void
open()
Opens a transaction.void
readWrite()
An internal function that signals a read or a write has occurred - not meant to be called directly by end users.void
rollback()
Rolls back a transaction.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.tinkerpop.gremlin.structure.Transaction
addTransactionListener, begin, clearTransactionListeners, isOpen, onClose, onReadWrite, removeTransactionListener
-
-
-
-
Constructor Detail
-
AbstractTransaction
public AbstractTransaction(Graph graph)
-
-
Method Detail
-
doOpen
protected abstract void doOpen()
Called withinopen()
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
protected abstract void doCommit() throws TransactionException
Called withcommit()
after theTransaction.onReadWrite(Consumer)
has been notified. Implementers should include their commit logic here.- Throws:
TransactionException
-
doRollback
protected abstract void doRollback() throws TransactionException
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.COMMIT
events 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.ROLLBACK
events 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.
-
open
public void open()
Opens a transaction.- Specified by:
open
in interfaceTransaction
-
commit
public void commit()
Commits a transaction. This method may optionally throwTransactionException
on 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:
commit
in interfaceTransaction
-
rollback
public void rollback()
Rolls back a transaction. This method may optionally throwTransactionException
on 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:
rollback
in interfaceTransaction
-
createThreadedTx
public <G extends Graph> G createThreadedTx()
Creates a transaction that can be executed across multiple threads. TheGraph
returned from this method is not meant to represent some form of child transaction that can be committed from this object. A threaded transaction is aGraph
instance that has a transaction context that enables multiple threads to collaborate on the same transaction. A standard transactional context tied to aGraph
that supports transactions will typically bind a transaction to a single thread viaThreadLocal
.- Specified by:
createThreadedTx
in interfaceTransaction
-
begin
public <T extends TraversalSource> T begin(Class<T> traversalSourceClass)
Description copied from interface:Transaction
Starts a transaction in the context of a particularTraversalSource
instance. It is up to theTransaction
implementation to decide what this means and up to users to be aware of that meaning.- Specified by:
begin
in 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:
readWrite
in interfaceTransaction
-
close
public void close()
Closes the transaction where the default close behavior defined by {Transaction.onClose(Consumer)
} will be executed.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceTransaction
-
-