com.ibm.as400.access

Class AS400JDBCXAResource

  • All Implemented Interfaces:
    XAResource


    public class AS400JDBCXAResource
    extends Object
    implements XAResource
    The AS400JDBCXAResource class represents a resource manager for use in XA transaction management.

    This support is only available when connecting to systems running OS/400 V5R1 or later, or IBM i.

    The following example creates an AS400JDBCXAResource object that can be used to work with the XA resource manager.

    // Create an XA data source for making the XA connection. AS400JDBCXADataSource xaDataSource = new AS400JDBCXADataSource("myAS400"); xaDataSource.setUser("myUser"); xaDataSource.setPassword("myPasswd"); // Get an XAConnection and get the associated XAResource. // This provides access to the resource manager. XAConnection xaConnection = xaDataSource.getXAConnection(); XAResource xaResource = xaConnection.getXAResource(); // ... work with the XA resource. // Close the XA connection when done. This implicitly // closes the XA resource. xaConnection.close();
    See Also:
    AS400JDBCXAConnection, AS400JDBCXADataSource

    • Method Detail

      • commit

        public void commit(Xid xid,
                  boolean onePhase)
                    throws XAException
        Commits a global transaction.
        Specified by:
        commit in interface XAResource
        Parameters:
        xid - The global transaction identifier.
        onePhase - true if the resource manager should use a one-phase commit protocol to commit the work; false otherwise.
        Throws:
        XAException - If an error occurs.
      • end

        public void end(Xid xid,
               int flags)
                 throws XAException
        Ends the work performed on behalf of a transaction branch. The resource manager disassociates the XA resource from the transaction branch specified and lets the transaction be completed.
        Specified by:
        end in interface XAResource
        Parameters:
        xid - The global transaction identifier. This must correspond to the global transaction identifier previously passed to start().
        flags - The flags. Possible values are:
        • TMSUCCESS - The portion of work has completed successfully.
        • TMFAIL - The portion of work has failed. The resource manager may mark the transaction as rollback-only.
        • TMSUSPEND - The transaction branch is temporarily suspended in incomplete state. The transaction context is in suspend state and must be resumed via start() with TMRESUME. (This is not currently supported for V5R2 and earlier versions.)
        Throws:
        XAException - If an error occurs.
      • forget

        public void forget(Xid xid)
                    throws XAException
        Tells the resource manager to forget about a heuristically completed transaction branch.
        Specified by:
        forget in interface XAResource
        Parameters:
        xid - The global transaction identifier.
        Throws:
        XAException - If an error occurs.
      • getTransactionTimeout

        public int getTransactionTimeout()
                                  throws XAException
        Returns the current transaction timeout value.
        Specified by:
        getTransactionTimeout in interface XAResource
        Returns:
        The current transaction timeout value.
        Throws:
        XAException - If an error occurs.
      • isSameRM

        public boolean isSameRM(XAResource xaResource)
                         throws XAException
        Indicates if the resource manager represented by this XA resource is the same resource manager represented by the specified XA resource.
        Specified by:
        isSameRM in interface XAResource
        Parameters:
        xaResource - The XA resource.
        Returns:
        true if both XA resources represent the same resource manager, false otherwise.
        Throws:
        XAException - If an error occurs.
      • prepare

        public int prepare(Xid xid)
                    throws XAException
        Prepares for a transaction commit.
        Specified by:
        prepare in interface XAResource
        Parameters:
        xid - The global transaction identifier.
        Returns:
        One of the following values:
        • XA_OK - The transaction work has been prepared normally.
        • XA_RDONLY - The transaction branch has been read-only and has been committed.
        Throws:
        XAException - If an error occurs.
      • recover

        public Xid[] recover(int flags)
                      throws XAException
        Recovers a list of prepared transaction branches from the resource manager.
        Specified by:
        recover in interface XAResource
        Parameters:
        flags - The flags. Possible values are:
        • TMSTARTRSCAN - Start a recovery scan.
        • TMENDRSCAN - End a recovery scan.
        • TMNOFLAGS - No flags are set.
        Returns:
        The global transaction identifiers for the transaction branches that are currently in a prepared or heuristically completed state.
        Throws:
        XAException - If an error occurs.
      • rollback

        public void rollback(Xid xid)
                      throws XAException
        Rolls back a transaction branch.
        Specified by:
        rollback in interface XAResource
        Parameters:
        xid - The global transaction identifier.
        Throws:
        XAException - If an error occurs.
      • setTransactionTimeout

        public boolean setTransactionTimeout(int transactionTimeout)
                                      throws XAException
        Sets the current transaction timeout value. This is not supported.
        Specified by:
        setTransactionTimeout in interface XAResource
        Parameters:
        transactionTimeout - The current transaction timeout value in seconds, or 0 to reset the timeout value to the default. The transaction timeout will be set the next time start() is called.
        Returns:
        true if the timeout value can be set successfully, false if the resource manager does not support the transaction timeout value to be set.
        Throws:
        XAException - If an error occurs.
      • start

        public void start(Xid xid,
                 int flags)
                   throws XAException
        Starts the work on behalf of a transaction branch. The resource manager associates the XA resource from the transaction branch specified.
        Specified by:
        start in interface XAResource
        Parameters:
        xid - The global transaction identifier.
        flags - The flags. Possible values are:
        • TMJOIN - Joins a transaction previously seen by the resource manager.
        • TMRESUME - Resumes a suspended transaction. (This is not currently supported for V5R3 and earlier versions.)
        • TMNOFLAGS - No flags are set.
        Throws:
        XAException - If an error occurs.
      • setLockWait

        public void setLockWait(int lockWait)
                         throws SQLException
        Specifies the number of seconds that the system will wait on any lock request during this transaction.
        Parameters:
        lockWait - The time in seconds to wait.
        Throws:
        SQLException
      • toString

        public String toString()
        Returns the string representation of the XA resource.
        Overrides:
        toString in class Object
        Returns:
        The string representation.