com.ibm.as400.access
Class AS400JDBCXAResource

com.ibm.as400.access.AS400JDBCXAResource

public class AS400JDBCXAResource

The AS400JDBCXAResource class represents a resource manager for use in XA transaction management.

This support is only available on V5R1 or later AS/400s.

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 Summary
 void commit(javax.transaction.xa.Xid xid, boolean onePhase)
          Commits a global transaction.
 void end(javax.transaction.xa.Xid xid, int flags)
          Ends the work performed on behalf of a transaction branch.
 void forget(javax.transaction.xa.Xid xid)
          Tells the resource manager to forget about a heuristically completed transaction branch.
 int getTransactionTimeout()
          Returns the current transaction timeout value.
 boolean isSameRM(javax.transaction.xa.XAResource xaResource)
          Indicates if the resource manager represented by this XA resource is the same resource manager represented by the specified XA resource.
 int prepare(javax.transaction.xa.Xid xid)
          Prepares for a transaction commit.
 javax.transaction.xa.Xid[] recover(int flags)
          Recovers a list of prepared transaction branches from the resource manager.
 void rollback(javax.transaction.xa.Xid xid)
          Rolls back a transaction branch.
 boolean setTransactionTimeout(int transactionTimeout)
          Sets the current transaction timeout value.
 void start(javax.transaction.xa.Xid xid, int flags)
          Starts the work on behalf of a transaction branch.
 java.lang.String toString()
          Returns the string representation of the XA resource.
 

Method Detail

commit

public void commit(javax.transaction.xa.Xid xid,
                   boolean onePhase)
            throws javax.transaction.xa.XAException
Commits a global transaction.
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(javax.transaction.xa.Xid xid,
                int flags)
         throws javax.transaction.xa.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.
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.)
Throws:
XAException - If an error occurs.

forget

public void forget(javax.transaction.xa.Xid xid)
            throws javax.transaction.xa.XAException
Tells the resource manager to forget about a heuristically completed transaction branch.
Parameters:
xid - The global transaction identifier.
Throws:
XAException - If an error occurs.

getTransactionTimeout

public int getTransactionTimeout()
                          throws javax.transaction.xa.XAException
Returns the current transaction timeout value.
Returns:
The current transaction timeout value. This always returns 0.
Throws:
XAException - If an error occurs.

isSameRM

public boolean isSameRM(javax.transaction.xa.XAResource xaResource)
                 throws javax.transaction.xa.XAException
Indicates if the resource manager represented by this XA resource is the same resource manager represented by the specified XA resource.
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(javax.transaction.xa.Xid xid)
            throws javax.transaction.xa.XAException
Prepares for a transaction commit.
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 javax.transaction.xa.Xid[] recover(int flags)
                                   throws javax.transaction.xa.XAException
Recovers a list of prepared transaction branches from the resource manager.
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(javax.transaction.xa.Xid xid)
              throws javax.transaction.xa.XAException
Rolls back a transaction branch.
Parameters:
xid - The global transaction identifier.
Throws:
XAException - If an error occurs.

setTransactionTimeout

public boolean setTransactionTimeout(int transactionTimeout)
                              throws javax.transaction.xa.XAException
Sets the current transaction timeout value. This is not supported.
Parameters:
transactionTimeout - The current transaction timeout value in seconds, or 0 to reset the timeout value to the default.
Returns:
true if the timeout value is set successfully, false if the resource manager does not support the transaction timeout value to be set. This method always returns false.
Throws:
XAException - If an error occurs.

start

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

toString

public java.lang.String toString()
Returns the string representation of the XA resource.
Returns:
The string representation.