Interface Transaction

All Superinterfaces:
AutoCloseable
All Known Implementing Classes:
AbstractTransaction

public interface Transaction extends AutoCloseable
A transaction against a single system, which may include several operations against the system, to be committed as one. Implementations are required to atomically apply changes in the commit step or throw an exception if it fails. Operations are performed in the order they are added.
Author:
Ulf Lilleengen, bratseth
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static interface 
    Operations that a transaction supports should implement this interface.
  • Method Summary

    Modifier and Type
    Method
    Description
    Adds an operation to this transaction.
    Adds multiple operations to this transaction.
    void
    Closes and frees any resources allocated by this transaction.
    void
    Commit this transaction.
    Returns the operations of this.
    void
    Checks whether or not the transaction is able to commit in its current state and do any transient preparatory work to commit.
    void
    This is called if the transaction should be rolled back after commit.
  • Method Details

    • add

      Adds an operation to this transaction. Return self for chaining.
      Parameters:
      operation - Transaction.Operation to append
      Returns:
      self, for chaining
    • add

      Adds multiple operations to this transaction. Return self for chaining.
      Parameters:
      operation - Transaction.Operation to append
      Returns:
      self, for chaining
    • operations

      Returns the operations of this. Ownership of the returned list is transferred to the caller. The ist may be ready only.
    • prepare

      void prepare()
      Checks whether or not the transaction is able to commit in its current state and do any transient preparatory work to commit.
      Throws:
      IllegalStateException - if the transaction cannot be committed
    • commit

      void commit()
      Commit this transaction. If this method returns, all operations in this transaction was committed successfully. Implementations of this must be exception safe or log a message of type severe if they partially alter state.
      Throws:
      IllegalStateException - if transaction failed.
    • rollbackOrLog

      void rollbackOrLog()
      This is called if the transaction should be rolled back after commit. If a rollback is not possible or supported. This must log a message of type severe with detailed information about the resulting state.
    • close

      void close()
      Closes and frees any resources allocated by this transaction. The transaction instance cannot be reused once closed.
      Specified by:
      close in interface AutoCloseable