Class LocalTransactionContext

  • All Implemented Interfaces:
    org.wildfly.common.context.Contextual<LocalTransactionContext>

    public final class LocalTransactionContext
    extends Object
    implements org.wildfly.common.context.Contextual<LocalTransactionContext>
    The local transaction context, which manages the creation and usage of local transactions.
    Author:
    David M. Lloyd
    • Field Detail

      • DEFAULT_TXN_TIMEOUT

        public static final int DEFAULT_TXN_TIMEOUT
        The default transaction timeout (5 minutes).
        See Also:
        Constant Field Values
    • Constructor Detail

      • LocalTransactionContext

        public LocalTransactionContext​(LocalTransactionProvider provider)
        Construct a new instance. The given provider will be used to manage local transactions.
        Parameters:
        provider - the local transaction provider
    • Method Detail

      • getContextManager

        @NotNull
        public static org.wildfly.common.context.ContextManager<LocalTransactionContext> getContextManager()
        Get the context manager.
        Returns:
        the context manager (not null)
      • getInstanceContextManager

        @NotNull
        public org.wildfly.common.context.ContextManager<LocalTransactionContext> getInstanceContextManager()
        Get the context manager; delegates to getContextManager().
        Specified by:
        getInstanceContextManager in interface org.wildfly.common.context.Contextual<LocalTransactionContext>
        Returns:
        the context manager (not null)
      • getCurrent

        @NotNull
        public static LocalTransactionContext getCurrent()
        Get the current local transaction context. The default context does not support initiating new transactions.
        Returns:
        the current local transaction context (not null)
      • registerCreationListener

        public void registerCreationListener​(CreationListener creationListener)
        Register a transaction creation listener.
        Parameters:
        creationListener - the creation listener (must not be null)
      • removeCreationListener

        public void removeCreationListener​(CreationListener creationListener)
        Remove a transaction creation listener.
        Parameters:
        creationListener - the creation listener (must not be null)
      • beginTransaction

        @NotNull
        public LocalTransaction beginTransaction​(int timeout)
                                          throws SystemException,
                                                 SecurityException
        Begin a new, local transaction on behalf of a local peer.
        Parameters:
        timeout - the transaction timeout to use for this transaction
        Returns:
        the local transaction (not null)
        Throws:
        SystemException - if the transaction creation failed for some reason, one of the possible reasons being suspended server
        SecurityException - if the caller is not authorized to create a local transaction in this context
      • beginTransaction

        @NotNull
        public LocalTransaction beginTransaction​(int timeout,
                                                 boolean failOnSuspend)
                                          throws SystemException,
                                                 SecurityException
        Begin a new, local transaction on behalf of a local or remote peer.
        Parameters:
        timeout - the transaction timeout to use for this transaction
        failOnSuspend - true to fail if the server is suspended, false to begin the transaction even if the server is suspended
        Returns:
        the local transaction (not null)
        Throws:
        SystemException - if the transaction creation failed for some reason, one of the possible reasons being suspended server
        SecurityException - if the caller is not authorized to create a local transaction in this context
      • findOrImportTransaction

        public ImportResult<LocalTransaction> findOrImportTransaction​(Xid xid,
                                                                      int timeout,
                                                                      boolean doNotImport)
                                                               throws XAException
        Attempt to import a transaction, which subsequently may be controlled by its XID or by the returned handle.
        Parameters:
        xid - the XID of the transaction to import (must not be null)
        timeout - the transaction timeout to use, if new
        doNotImport - true to indicate that a non-existing transaction should not be imported, false otherwise
        Returns:
        the transaction import result, or null if (and only if) doNotImport is true and the transaction didn't exist locally
        Throws:
        XAException - if a problem occurred while importing the transaction
      • findOrImportTransaction

        @NotNull
        public ImportResult<LocalTransaction> findOrImportTransaction​(Xid xid,
                                                                      int timeout)
                                                               throws XAException
        Attempt to import a transaction, which subsequently may be controlled by its XID or by the returned handle.
        Parameters:
        xid - the XID of the transaction to import (must not be null)
        timeout - the transaction timeout to use, if new
        Returns:
        the transaction import result (not null)
        Throws:
        XAException - if a problem occurred while importing the transaction
      • importProviderTransaction

        public boolean importProviderTransaction()
                                          throws SystemException
        Attempt to import a provider's current transaction as a local transaction.
        Returns:
        true if the transaction was associated, false if the provider had no current transaction
        Throws:
        SystemException - if an error occurred acquiring the current transaction from the provider
        IllegalStateException - if the thread is associated with a transaction that isn't equal to the provider's transaction
      • getRecoveryInterface

        @NotNull
        public XARecoverable getRecoveryInterface()
        Get the recovery interface for this context. The recovery interface can be used to recover transactions which were imported into this context via findOrImportTransaction(Xid, int).
        Returns:
        the recovery interface for this context (not null)
      • getXATerminator

        @NotNull
        public javax.resource.spi.XATerminator getXATerminator()