org.apache.tinkerpop.gremlin.structure

## Interface Transaction

- All Superinterfaces:
    AutoCloseable

      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.

  It is expected that this interface be implemented by providers in a `ThreadLocal` fashion. In other words transactions are bound to the current thread, which means that any graph operation executed by the thread occurs in the context of that transaction and that there may only be one thread executing in a single transaction.

  It is important to realize that this class is not a "transaction object". It is a class that holds transaction related methods thus hiding them from the `Graph` interface. This object is not meant to be passed around as a transactional context.
  Author:
    Marko A. Rodriguez (http://markorodriguez.com), Stephen Mallette (http://stephen.genoprime.com), TinkerPop Community (http://tinkerpop.apache.org)

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Interface and Description
    --- | ---
    `static class` | `Transaction.CLOSE_BEHAVIOR` Behaviors to supply to the `onClose(Consumer)`.
    `static class` | `Transaction.Exceptions`
    `static class` | `Transaction.READ_WRITE_BEHAVIOR` Behaviors to supply to the `onReadWrite(Consumer)`.
    `static class` | `Transaction.Status` A status provided to transaction listeners to inform whether a transaction was successfully committed or rolled back.

  - ### Method Summary

    All Methods Instance Methods Abstract Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addTransactionListener(Consumer<Transaction.Status> listener)` Adds a listener that is called back with a status when a commit or rollback is successful.
    `void` | `clearTransactionListeners()` Removes all transaction listeners.
    `void` | `close()` Closes the transaction where the default close behavior defined by {`onClose(Consumer)`} will be executed.
    `void` | `commit()` Commits a transaction.
    `<G extends Graph> G` | `createThreadedTx()` Creates a transaction that can be executed across multiple threads.
    `boolean` | `isOpen()` Determines if a transaction is currently open.
    `Transaction` | `onClose(Consumer<Transaction> consumer)` Describes what happens to a transaction on a call to `Graph.close()`.
    `Transaction` | `onReadWrite(Consumer<Transaction> consumer)` Describes how a transaction is started when a read or a write occurs.
    `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` | `removeTransactionListener(Consumer<Transaction.Status> listener)` Removes a transaction listener.
    `void` | `rollback()` Rolls back a transaction.

- - ### Method Detail

    - #### open

          void open()

      Opens a transaction.

    - #### 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

          <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`.

    - #### 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.

Copyright © 2013–2018 Apache Software Foundation. All rights reserved.