Class JTA11TransactionController

All Implemented Interfaces:
ExternalTransactionController
Direct Known Subclasses:
GlassfishTransactionController11, JBossTransactionController11, WebLogicTransactionController11, WildFlyTransactionController11

public class JTA11TransactionController extends JTATransactionController

Purpose: TransactionController extensions for JTA 1.1

Description: Implements the required behavior for controlling JTA 1.1 transactions. Specific JTA implementations may need to extend this class when special controller behavior is necessary.

The JTA TransactionSynchronizationRegistry must be obtained and set on the instance in order for a Synchronization listener to be registered against the transaction. This can be done either by extending this class and defining acquireTransactionSynchronizationRegistry() to return the manager for the server, or by using this class and explicitly calling the setTransactionSynchronizationRegistry() method on it after the fact. e.g. TransactionSynchronizationRegistry tsr = controller.jndiLookup("java:comp/setTransactionSynchronizationRegistry"); controller.setTransactionManager(tsr);

If a different listener needs to be used for synchronization, the SynchronizationListenerFactory should be set on the controller instance. The listener subclass should implement the factory interface, so that setting the factory is simply a matter of assigning an instance of the listener. e.g. controller.setSynchronizationListenerFactory( new DifferentServerSynchronizationListener()); The default listener factory creates instances of JTATransactionListener.

Since:
2.7.1
See Also:
  • Field Details

  • Constructor Details

    • JTA11TransactionController

      public JTA11TransactionController()
      PUBLIC: Return a new controller for use with acquired JTA 1.1 compliant TransactionSynchronizationRegistry.
    • JTA11TransactionController

      public JTA11TransactionController(TransactionSynchronizationRegistry supplTsr, TransactionManager supplTm)
      PUBLIC: Return a new controller for use with supplied JTA 1.1 compliant synchronization objects registry.
      Parameters:
      supplTsr - supplied JTA 1.1 compliant synchronization objects registry
      supplTm - supplied JTA 1.0 compliant transaction manager.
  • Method Details

    • getDefaultTransactionSynchronizationRegistry

      public static TransactionSynchronizationRegistry getDefaultTransactionSynchronizationRegistry()
      PUBLIC: Get the default JTA 1.1 synchronization objects registry being used.
      Returns:
      synchronization objects registry being used or null if no default value was set yet.
    • setDefaultTransactionSynchronizationRegistry

      public static void setDefaultTransactionSynchronizationRegistry(TransactionSynchronizationRegistry tsr)
      PUBLIC: Set the default JTA 1.1 synchronization objects registry to be used. This can be called directly before login to configure JTA integration manually, or using Spring injection.
      Parameters:
      tsr - synchronization objects registry to set
    • acquireTransactionSynchronizationRegistry

      protected TransactionSynchronizationRegistry acquireTransactionSynchronizationRegistry()
      INTERNAL: Obtain and return the JTA 1.1 TransactionSynchronizationRegistry on this platform. This method can be can be overridden by subclasses to obtain the TransactionSynchronizationRegistry by whatever means is appropriate to the server. This method is invoked by the constructor to initialize the synchronization objects registry at instance-creation time. Alternatively the synchronization objects registry can be set directly on the controller instance using the setTransactionManager() method after the instance has been created.
      Returns:
      the TransactionSynchronizationRegistry for the transaction system or null if no default value was found
    • getTransactionSynchronizationRegistry

      public TransactionSynchronizationRegistry getTransactionSynchronizationRegistry()
      PUBLIC: Return the synchronization objects registry used to control the JTA 1.1 transactions.
      Returns:
      the JTA 1.1 TransactionSynchronizationRegistry that is used to obtain transaction state information and control the active transaction
    • setTransactionManager

      public void setTransactionManager(TransactionSynchronizationRegistry supplTsr)
      PUBLIC: Set the synchronization objects registry used to control the JTA 1.1 transactions.
      Parameters:
      supplTsr - a valid JTA 1.1 TransactionSynchronizationRegistry that can be accessed by this controller to obtain transaction state information and control the active transaction
    • registerSynchronization_impl

      protected void registerSynchronization_impl(AbstractSynchronizationListener listener, Object txn) throws Exception
      INTERNAL: Register the specified synchronization listener with the given active transaction.
      Overrides:
      registerSynchronization_impl in class JTATransactionController
      Parameters:
      listener - the synchronization listener created for this transaction
      txn - the active transaction for which notification is being requested
      Throws:
      Exception
    • getTransactionKey_impl

      protected Object getTransactionKey_impl(Object transaction) throws Exception
      INTERNAL: Return a key for the specified external transaction object. The key is just something that can be inserted into a hash table (must support hashCode() and equals() methods).
      Overrides:
      getTransactionKey_impl in class JTATransactionController
      Parameters:
      transaction - The transaction to which the returned key applies (may be null)
      Returns:
      an opaque object to represent the transaction bound to the current thread at the time this method is called, or null if no transaction specified
      Throws:
      Exception
    • getTransactionStatus_impl

      protected Object getTransactionStatus_impl() throws Exception
      INTERNAL: Return the transaction status as an object. We will pass around Integers that wrap the int JTA status values.
      Overrides:
      getTransactionStatus_impl in class JTATransactionController
      Returns:
      the status of the transaction bound to the current thread at the time this method is called
      Throws:
      Exception
    • markTransactionForRollback_impl

      protected void markTransactionForRollback_impl() throws Exception
      INTERNAL: Mark the external transaction for rollback.
      Overrides:
      markTransactionForRollback_impl in class JTATransactionController
      Throws:
      Exception
    • isRolledBack_impl

      public boolean isRolledBack_impl(Object status)
      INTERNAL: Check whether the transaction is rolled back.
      Overrides:
      isRolledBack_impl in class JTATransactionController
      Parameters:
      status - true if the transaction is rolled back or false otherwise