Package org.h2.jdbcx

Class JdbcXAConnection

  • All Implemented Interfaces:
    javax.sql.PooledConnection, javax.sql.XAConnection, javax.transaction.xa.XAResource

    public final class JdbcXAConnection
    extends TraceObject
    implements javax.sql.XAConnection, javax.transaction.xa.XAResource
    This class provides support for distributed transactions. An application developer usually does not use this interface. It is used by the transaction manager internally.
    • Field Detail

      • handleConn

        private volatile java.sql.Connection handleConn
      • listeners

        private final java.util.ArrayList<javax.sql.ConnectionEventListener> listeners
      • currentTransaction

        private javax.transaction.xa.Xid currentTransaction
      • prepared

        private boolean prepared
    • Method Detail

      • getXAResource

        public javax.transaction.xa.XAResource getXAResource()
        Get the XAResource object.
        Specified by:
        getXAResource in interface javax.sql.XAConnection
        Returns:
        itself
      • close

        public void close()
                   throws java.sql.SQLException
        Close the physical connection. This method is usually called by the connection pool.
        Specified by:
        close in interface javax.sql.PooledConnection
        Throws:
        java.sql.SQLException
      • getConnection

        public java.sql.Connection getConnection()
                                          throws java.sql.SQLException
        Get a connection that is a handle to the physical connection. This method is usually called by the connection pool. This method closes the last connection handle if one exists.
        Specified by:
        getConnection in interface javax.sql.PooledConnection
        Returns:
        the connection
        Throws:
        java.sql.SQLException
      • addConnectionEventListener

        public void addConnectionEventListener​(javax.sql.ConnectionEventListener listener)
        Register a new listener for the connection.
        Specified by:
        addConnectionEventListener in interface javax.sql.PooledConnection
        Parameters:
        listener - the event listener
      • removeConnectionEventListener

        public void removeConnectionEventListener​(javax.sql.ConnectionEventListener listener)
        Remove the event listener.
        Specified by:
        removeConnectionEventListener in interface javax.sql.PooledConnection
        Parameters:
        listener - the event listener
      • closedHandle

        void closedHandle()
        INTERNAL
      • getTransactionTimeout

        public int getTransactionTimeout()
        Get the transaction timeout.
        Specified by:
        getTransactionTimeout in interface javax.transaction.xa.XAResource
        Returns:
        0
      • setTransactionTimeout

        public boolean setTransactionTimeout​(int seconds)
        Set the transaction timeout.
        Specified by:
        setTransactionTimeout in interface javax.transaction.xa.XAResource
        Parameters:
        seconds - ignored
        Returns:
        false
      • isSameRM

        public boolean isSameRM​(javax.transaction.xa.XAResource xares)
        Checks if this is the same XAResource.
        Specified by:
        isSameRM in interface javax.transaction.xa.XAResource
        Parameters:
        xares - the other object
        Returns:
        true if this is the same object
      • recover

        public javax.transaction.xa.Xid[] recover​(int flag)
                                           throws javax.transaction.xa.XAException
        Get the list of prepared transaction branches. This method is called by the transaction manager during recovery.
        Specified by:
        recover in interface javax.transaction.xa.XAResource
        Parameters:
        flag - TMSTARTRSCAN, TMENDRSCAN, or TMNOFLAGS. If no other flags are set, TMNOFLAGS must be used.
        Returns:
        zero or more Xid objects
        Throws:
        javax.transaction.xa.XAException
      • prepare

        public int prepare​(javax.transaction.xa.Xid xid)
                    throws javax.transaction.xa.XAException
        Prepare a transaction.
        Specified by:
        prepare in interface javax.transaction.xa.XAResource
        Parameters:
        xid - the transaction id
        Returns:
        XA_OK
        Throws:
        javax.transaction.xa.XAException
      • forget

        public void forget​(javax.transaction.xa.Xid xid)
        Forget a transaction. This method does not have an effect for this database.
        Specified by:
        forget in interface javax.transaction.xa.XAResource
        Parameters:
        xid - the transaction id
      • rollback

        public void rollback​(javax.transaction.xa.Xid xid)
                      throws javax.transaction.xa.XAException
        Roll back a transaction.
        Specified by:
        rollback in interface javax.transaction.xa.XAResource
        Parameters:
        xid - the transaction id
        Throws:
        javax.transaction.xa.XAException
      • end

        public void end​(javax.transaction.xa.Xid xid,
                        int flags)
                 throws javax.transaction.xa.XAException
        End a transaction.
        Specified by:
        end in interface javax.transaction.xa.XAResource
        Parameters:
        xid - the transaction id
        flags - TMSUCCESS, TMFAIL, or TMSUSPEND
        Throws:
        javax.transaction.xa.XAException
      • start

        public void start​(javax.transaction.xa.Xid xid,
                          int flags)
                   throws javax.transaction.xa.XAException
        Start or continue to work on a transaction.
        Specified by:
        start in interface javax.transaction.xa.XAResource
        Parameters:
        xid - the transaction id
        flags - TMNOFLAGS, TMJOIN, or TMRESUME
        Throws:
        javax.transaction.xa.XAException
      • commit

        public void commit​(javax.transaction.xa.Xid xid,
                           boolean onePhase)
                    throws javax.transaction.xa.XAException
        Commit a transaction.
        Specified by:
        commit in interface javax.transaction.xa.XAResource
        Parameters:
        xid - the transaction id
        onePhase - use a one-phase protocol if true
        Throws:
        javax.transaction.xa.XAException
      • addStatementEventListener

        public void addStatementEventListener​(javax.sql.StatementEventListener listener)
        [Not supported] Add a statement event listener.
        Specified by:
        addStatementEventListener in interface javax.sql.PooledConnection
        Parameters:
        listener - the new statement event listener
      • removeStatementEventListener

        public void removeStatementEventListener​(javax.sql.StatementEventListener listener)
        [Not supported] Remove a statement event listener.
        Specified by:
        removeStatementEventListener in interface javax.sql.PooledConnection
        Parameters:
        listener - the statement event listener
      • toString

        public java.lang.String toString()
        INTERNAL
        Overrides:
        toString in class java.lang.Object
      • convertException

        private static javax.transaction.xa.XAException convertException​(java.sql.SQLException e)
      • quoteXid

        private static java.lang.String quoteXid​(javax.transaction.xa.Xid xid)
      • quoteFlags

        private static java.lang.String quoteFlags​(int flags)
      • checkOpen

        private void checkOpen()
                        throws javax.transaction.xa.XAException
        Throws:
        javax.transaction.xa.XAException