Class JTATransactionImpl

  • All Implemented Interfaces:
    javax.transaction.Synchronization, Transaction

    public class JTATransactionImpl
    extends TransactionImpl
    implements javax.transaction.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
    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 Detail

      • joinStatus

        protected org.datanucleus.transaction.jta.JTATransactionImpl.JoinStatus joinStatus
      • autoJoin

        protected boolean autoJoin
    • Constructor Detail

      • JTATransactionImpl

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

      • isJoined

        public boolean isJoined()
      • 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
        getIsActive in class TransactionImpl
        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
        isActive in class TransactionImpl
        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
        begin 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 javax.transaction.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 javax.transaction.Synchronization
        status - The status