Interface TransactionContext


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

      • getTransactionKey

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

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

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

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

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

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

        void preCompletion​(java.lang.Runnable job)
                    throws java.lang.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:
        java.lang.IllegalStateException - if the transaction has already passed beyond the TransactionStatus.MARKED_ROLLBACK state
      • postCompletion

        void postCompletion​(java.util.function.Consumer<TransactionStatus> job)
                     throws java.lang.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:
        java.lang.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​(javax.transaction.xa.XAResource resource,
                                java.lang.String recoveryId)
                         throws java.lang.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:
        java.lang.IllegalStateException - if no transaction is active, or the current transaction is not XA capable
      • registerLocalResource

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