Class TransactionContext

  • All Implemented Interfaces:
    XAResource

    public class TransactionContext
    extends Object
    implements XAResource
    A TransactionContext provides the means to control a JMS transaction. It provides a local transaction interface and also an XAResource interface.

    An application server controls the transactional assignment of an XASession by obtaining its XAResource. It uses the XAResource to assign the session to a transaction, prepare and commit work on the transaction, and so on.

    An XAResource provides some fairly sophisticated facilities for interleaving work on multiple transactions, recovering a list of transactions in progress, and so on. A JTA aware JMS provider must fully implement this functionality. This could be done by using the services of a database that supports XA, or a JMS provider may choose to implement this functionality from scratch.

    See Also:
    Session, QueueSession, TopicSession, XASession
    • Constructor Detail

      • TransactionContext

        public TransactionContext()
    • Method Detail

      • isInXATransaction

        public boolean isInXATransaction()
      • setRollbackOnly

        public void setRollbackOnly​(boolean val)
      • isRollbackOnly

        public boolean isRollbackOnly()
      • isInLocalTransaction

        public boolean isInLocalTransaction()
      • isInTransaction

        public boolean isInTransaction()
      • getLocalTransactionEventListener

        public LocalTransactionEventListener getLocalTransactionEventListener()
        Returns:
        Returns the localTransactionEventListener.
      • setLocalTransactionEventListener

        public void setLocalTransactionEventListener​(LocalTransactionEventListener localTransactionEventListener)
        Used by the resource adapter to listen to transaction events.
        Parameters:
        localTransactionEventListener - The localTransactionEventListener to set.
      • addSynchronization

        public void addSynchronization​(Synchronization s)
      • begin

        public void begin()
                   throws javax.jms.JMSException
        Start a local transaction.
        Throws:
        javax.jms.JMSException - on internal error
      • rollback

        public void rollback()
                      throws javax.jms.JMSException
        Rolls back any work done in this transaction and releases any locks currently held.
        Throws:
        javax.jms.JMSException - if the JMS provider fails to roll back the transaction due to some internal error.
        javax.jms.IllegalStateException - if the method is not called by a transacted session.
      • commit

        public void commit()
                    throws javax.jms.JMSException
        Commits all work done in this transaction and releases any locks currently held.
        Throws:
        javax.jms.JMSException - if the JMS provider fails to commit the transaction due to some internal error.
        javax.jms.IllegalStateException - if the method is not called by a transacted session.
      • getResourceManagerId

        protected String getResourceManagerId()
                                       throws javax.jms.JMSException
        Throws:
        javax.jms.JMSException
      • toXAException

        public static XAException toXAException​(javax.jms.JMSException e)
        Converts a JMSException from the server to an XAException. if the JMSException contained a linked XAException that is returned instead.
        Parameters:
        e - JMSException to convert
        Returns:
        XAException wrapping original exception or its message
      • cleanup

        public void cleanup()