Interface Transaction

All Known Implementing Classes:
TransactionAdapter

public interface Transaction
Represents a transaction.
  • Method Details

    • getContext

      Context getContext()
      Get the transaction's context.
      Returns:
      The transaction's context.
    • commit

      void commit() throws PersistException
      Commit the transaction.
      Throws:
      PersistException - If committing the transaction failed.
      RollbackException - If the transaction was set rollback only (normal rollback).
      IllegalStateException - If the transaction is not currently associated with this thread.
    • rollback

      void rollback()
      Roll back the transaction.
      Throws:
      IllegalStateException - If the transaction is not currently associated with this thread, or if it is not in State.RUNNING.
      See Also:
    • ensureRollback

      void ensureRollback()
      Roll back the transaction if not rolling back or rolled back already.

      This may be used in finally blocks for example. Otherwise it is recommended to know the state of the tx, and not to guess it.

      Throws:
      IllegalStateException - If the transaction is not currently associated with this thread, or if it is not running nor rolled back nor rolling back.
      See Also:
    • setRollbackOnly

      void setRollbackOnly()
      Set the transaction rollback only. A transaction that is set rollback only cannot be committed. commit() will then throw a RollbackException.
      Throws:
      IllegalStateException - If the transaction is not currently associated with this thread.
    • isRollbackOnly

      boolean isRollbackOnly()
      Check whether the transaction is set rollback only.
      Returns:
      true if the transaction is set rollback only.
    • getRegistered

      @Deprecated TransactionAware getRegistered(Object key)
      Deprecated.
      Check for a registered transaction aware object.
      Parameters:
      key - The key to check
      Returns:
      The registered object or null.
      Throws:
      IllegalStateException - If the transaction is not currently associated with the thread.
    • register

      TransactionAware register(Object key, TransactionAware transactionAware) throws IllegalStateException
      Register a new transaction aware object to the transaction to receive callback events, if no such object is registered yet.
      Parameters:
      key - The key of the transaction aware.
      transactionAware - The new transaction aware object.
      Returns:
      The registered transaction aware instance after this call, which is either a previously registered one which means nothing was changed, or the one you pass in now.
      Throws:
      IllegalStateException - If the transaction is not currently associated with the thread or the context of the transaction aware object and the transaction mismatch.
    • getState

      Transaction.State getState()
      Get the current state of the transaction.
      Returns:
      The current state of the transaction.
    • getExceptions

      @Deprecated List<Throwable> getExceptions()
      Deprecated.
      Retrieve any exceptions that were thrown during commit or rollback. This includes exceptions that were logged only (which may happen if TransactionAwares throw exceptions during panic or cleanup.
      Returns:
      A list of exceptions thrown during rollack or commit.
    • setAttribute

      void setAttribute(String key, Object value)
    • getAttribute

      <T> T getAttribute(String key)