Class JTATransactionImpl

java.lang.Object
org.datanucleus.transaction.TransactionImpl
org.datanucleus.transaction.jta.JTATransactionImpl
All Implemented Interfaces:
Synchronization, Transaction

public class JTATransactionImpl extends TransactionImpl implements Synchronization
Transaction that is synchronized with a Java Transaction Service (JTA) transaction. Works only in environments where a TransactionManager is present. This transaction joins to the transaction via the TransactionManager, and the TransactionManager notifies this class of completion via the beforeCompletion/afterCompletion callback hooks. This transaction can be configured as "autoJoin" whereby it will try to join when it is created and otherwise when isActive() is called. When it is not set to "autoJoin" the developer has to call
joinTransaction
which will check the current join status and join as necessary.

When this transaction is being used the transactions must be controlled using javax.transaction.UserTransaction, and not using local transactions (e.g PM.currentTransaction().begin()). Should also work for SessionBeans, as per spec UserTransaction reflects SessionBean-based tx demarcation. See also Transaction

  • Field Details

    • JBOSS_SERVER

      private static boolean JBOSS_SERVER
    • jtaTM

      private TransactionManager jtaTM
      JTA TransactionManager.
    • jtaTx

      private Transaction jtaTx
      JTA Transaction that we are currently synced with. Null when no JTA transaction active or not yet joined.
    • jtaSyncRegistry

      private JTASyncRegistry jtaSyncRegistry
    • joinStatus

      protected JTATransactionImpl.JoinStatus joinStatus
    • userTransaction

      private UserTransaction userTransaction
    • autoJoin

      protected boolean autoJoin
  • Constructor Details

    • JTATransactionImpl

      public JTATransactionImpl(ExecutionContext ec, boolean autoJoin, PropertyStore properties)
      Constructor. Will attempt to join with the transaction manager to get the underlying transaction.
      Parameters:
      ec - ExecutionContext
      autoJoin - Whether to auto-join to the underlying UserTransaction on isActive and at creation?
      properties - Properties to use with the transaction
  • Method Details

    • isJoined

      public boolean isJoined()
    • getTransactionStatus

      private int getTransactionStatus()
    • joinTransaction

      public void joinTransaction()
      Method to call if you want to join to the underlying UserTransaction. Will be called by isActive() and constructor if "autoJoin" is set, otherwise has to be called by user code.
    • getIsActive

      public boolean getIsActive()
      Description copied from class: TransactionImpl
      Similar to "isActive" except that it just returns the "active" flag whereas the isActive() method can also embody rejoining to underlying transactions.
      Specified by:
      getIsActive in interface Transaction
      Overrides:
      getIsActive in class TransactionImpl
      Returns:
      The "active" flag
    • isActive

      public boolean isActive()
      Accessor for whether the transaction is active. The UserTransaction is considered active if its status is anything other than Status.STATUS_NO_TRANSACTION, i.e. when the current thread is associated with a JTA transaction. Note that this will attempt to join if not yet joined
      Specified by:
      isActive in interface Transaction
      Overrides:
      isActive in class TransactionImpl
      Returns:
      Whether the transaction is active.
    • begin

      public void begin()
      JDO spec "16.1.3 Stateless Session Bean with Bean Managed Transactions": "acquiring a PM without beginning a UserTransaction results in the PM being able to manage transaction boundaries via begin, commit, and rollback methods on JDO Transaction. The PM will automatically begin the User-Transaction during Transaction.begin and automatically commit the UserTransaction during Transaction.commit"
      Specified by:
      begin in interface Transaction
      Overrides:
      begin in class TransactionImpl
    • commit

      public void commit()
      Description copied from class: TransactionImpl
      Method to commit the transaction.
      Specified by:
      commit in interface Transaction
      Overrides:
      commit in class TransactionImpl
    • rollback

      public void rollback()
      Description copied from class: TransactionImpl
      Method to rollback the transaction.
      Specified by:
      rollback in interface Transaction
      Overrides:
      rollback in class TransactionImpl
    • setRollbackOnly

      public void setRollbackOnly()
      Description copied from class: TransactionImpl
      Mutator for the "rollback only" flag. Sets the transaction as for rollback only.
      Specified by:
      setRollbackOnly in interface Transaction
      Overrides:
      setRollbackOnly in class TransactionImpl
    • beforeCompletion

      public void beforeCompletion()
      The beforeCompletion method is called by the transaction manager prior to the start of the two-phase transaction commit process.
      Specified by:
      beforeCompletion in interface Synchronization
    • afterCompletion

      public void afterCompletion(int status)
      This method is called by the transaction manager after the transaction is committed or rolled back. Must be synchronised because some callers expect to be owner of this object's monitor (internalPostCommit() calls closeSQLConnection() which calls notifyAll()).
      Specified by:
      afterCompletion in interface Synchronization
      Parameters:
      status - The status