Interface Transaction

All Superinterfaces:
AutoCloseable
All Known Subinterfaces:
RemoteTransaction

public interface Transaction extends AutoCloseable
A set of methods that allow for control of transactional behavior of a Graph instance. Providers may consider using AbstractTransaction as a base implementation that provides default features for most of these methods.
Author:
Marko A. Rodriguez (http://markorodriguez.com), Stephen Mallette (http://stephen.genoprime.com), TinkerPop Community (http://tinkerpop.apache.org)
  • Field Details

  • Method Details

    • commit

      void commit()
      Commits a transaction. This method may optionally throw TransactionException 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.
    • rollback

      void rollback()
      Rolls back a transaction. This method may optionally throw TransactionException 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.
    • createThreadedTx

      default <G extends Graph> G createThreadedTx()
      Creates a transaction that can be executed across multiple threads. The Graph 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 a Graph instance that has a transaction context that enables multiple threads to collaborate on the same transaction. A standard transactional context tied to a Graph that supports transactions will typically bind a transaction to a single thread via ThreadLocal.
    • begin

      default <T extends TraversalSource> T begin()
      Starts a transaction in the context of a GraphTraversalSource instance and returns that transaction-bound source. See begin(Class) for the full contract.
    • begin

      <T extends TraversalSource> T begin(Class<T> traversalSourceClass)
      Starts a transaction in the context of a particular TraversalSource instance and returns a TraversalSource bound to it. If a transaction is not already open for this Transaction, 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 returned TraversalSource is bound to the transaction's context is up to the implementation and up to users to be aware of that meaning.
    • isOpen

      boolean isOpen()
      Determines if a transaction is currently open.
    • readWrite

      void readWrite()
      An internal function that signals a read or a write has occurred - not meant to be called directly by end users.
    • close

      void close()
      Closes the transaction where the default close behavior defined by {onClose(Consumer)} will be executed.
      Specified by:
      close in interface AutoCloseable
    • onReadWrite

      Transaction onReadWrite(Consumer<Transaction> consumer)
      Describes how a transaction is started when a read or a write occurs. This value can be set using standard behaviors defined in Transaction.READ_WRITE_BEHAVIOR or a mapper Consumer function.
    • onClose

      Transaction onClose(Consumer<Transaction> consumer)
      Describes what happens to a transaction on a call to Graph.close(). This value can be set using standard behavior defined in Transaction.CLOSE_BEHAVIOR or a mapper Consumer function.
    • addTransactionListener

      void addTransactionListener(Consumer<Transaction.Status> listener)
      Adds a listener that is called back with a status when a commit or rollback is successful. It is expected that listeners be bound to the current thread as is standard for transactions. Therefore a listener registered in the current thread will not get callback events from a commit or rollback call in a different thread.
    • removeTransactionListener

      void removeTransactionListener(Consumer<Transaction.Status> listener)
      Removes a transaction listener.
    • clearTransactionListeners

      void clearTransactionListeners()
      Removes all transaction listeners.