Interface TransactionContext


@ProviderType public interface TransactionContext
A transaction context defines the current transaction, and allows resources to register information and/or synchronizations
  • Method Details

    • getTransactionKey

      Object getTransactionKey()
      Get the key associated with the current transaction
      Returns:
      the transaction key, or null if there is no transaction
    • getScopedValue

      Object getScopedValue(Object key)
      Get a value scoped to this transaction
      Parameters:
      key -
      Returns:
      The resource, or null
    • putScopedValue

      void putScopedValue(Object key, Object value)
      Associate a value with this transaction
      Parameters:
      key -
      value -
    • getRollbackOnly

      boolean getRollbackOnly() throws IllegalStateException
      Is this transaction marked for rollback only
      Returns:
      true if this transaction is rollback only
      Throws:
      IllegalStateException - if no transaction is active
    • setRollbackOnly

      void setRollbackOnly() throws IllegalStateException
      Mark this transaction for rollback
      Throws:
      IllegalStateException - if no transaction is active
    • getTransactionStatus

      TransactionStatus getTransactionStatus()
      Returns:
      The current transaction status
    • preCompletion

      void preCompletion(Runnable job) throws IllegalStateException
      Register a callback that will be made before a scope completes.

      For transactional scopes the state of the scope will be either TransactionStatus.ACTIVE or TransactionStatus.MARKED_ROLLBACK. Pre-completion callbacks may call setRollbackOnly() to prevent a commit from proceeding.

      For no-transaction scopes the state of the scope will always be TransactionStatus.NO_TRANSACTION.

      Exceptions thrown by pre-completion callbacks are treated as if they were thrown by the scoped work, including any configured commit or rollback behaviors for transactional scopes.

      Parameters:
      job - The action to perform before completing the scope
      Throws:
      IllegalStateException - if the transaction has already passed beyond the TransactionStatus.MARKED_ROLLBACK state
    • postCompletion

      void postCompletion(Consumer<TransactionStatus> job) throws IllegalStateException
      Register a callback that will be made after the scope completes

      For transactional scopes the state of the scope will be either TransactionStatus.COMMITTED or TransactionStatus.ROLLED_BACK.

      For no-transaction scopes the state of the scope will always be TransactionStatus.NO_TRANSACTION.

      Post-completion callbacks should not throw Exceptions and cannot affect the outcome of a piece of scoped work

      Parameters:
      job -
      Throws:
      IllegalStateException - if no transaction is active
    • supportsXA

      boolean supportsXA()
      Returns:
      true if the current transaction supports XA resources
    • supportsLocal

      boolean supportsLocal()
      Returns:
      true if the current transaction supports Local resources
    • isReadOnly

      boolean isReadOnly()
      Returns:
      true if the TransactionContext supports read-only optimizations and the transaction was marked read only. In particular it is legal for this method to return false even if the transaction was marked read only by the initiating client.
    • registerXAResource

      void registerXAResource(XAResource resource, String recoveryId) throws IllegalStateException
      Register an XA resource with the current transaction
      Parameters:
      resource -
      recoveryId - The resource id to be used for recovery, the id may be null if this resource is not recoverable.

      If an id is passed then a RecoverableXAResource with the same id must be registered in the service registry for recovery to occur.

      If the underlying TransactionControl service does not support recovery then it must treat the resource as if it is not recoverable.

      Throws:
      IllegalStateException - if no transaction is active, or the current transaction is not XA capable
    • registerLocalResource

      void registerLocalResource(LocalResource resource) throws IllegalStateException
      Register a Local resource with the current transaction
      Parameters:
      resource -
      Throws:
      IllegalStateException - if no transaction is active, or the current transaction does not support local resources.