com.ibm.as400.access
Class AS400JDBCXAResource

java.lang.Object
  |
  +--com.ibm.as400.access.AS400JDBCXAResource
All Implemented Interfaces:
javax.transaction.xa.XAResource

public class AS400JDBCXAResource
extends java.lang.Object
implements javax.transaction.xa.XAResource

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

This support is only available when connecting to servers running OS/400 V5R1 or later.

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

Fields inherited from interface javax.transaction.xa.XAResource
TMENDRSCAN, TMFAIL, TMJOIN, TMNOFLAGS, TMONEPHASE, TMRESUME, TMSTARTRSCAN, TMSUCCESS, TMSUSPEND, XA_OK, XA_RDONLY
 
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

commit

public void commit(javax.transaction.xa.Xid xid,
                   boolean onePhase)
            throws javax.transaction.xa.XAException
Commits a global transaction.
Specified by:
commit in interface javax.transaction.xa.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:
javax.transaction.xa.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.
Specified by:
end in interface javax.transaction.xa.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.)
Throws:
javax.transaction.xa.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.
Specified by:
forget in interface javax.transaction.xa.XAResource
Parameters:
xid - The global transaction identifier.
Throws:
javax.transaction.xa.XAException - If an error occurs.

getTransactionTimeout

public int getTransactionTimeout()
                          throws javax.transaction.xa.XAException
Returns the current transaction timeout value.
Specified by:
getTransactionTimeout in interface javax.transaction.xa.XAResource
Returns:
The current transaction timeout value. This always returns 0.
Throws:
javax.transaction.xa.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.
Specified by:
isSameRM in interface javax.transaction.xa.XAResource
Parameters:
xaResource - The XA resource.
Returns:
true if both XA resources represent the same resource manager, false otherwise.
Throws:
javax.transaction.xa.XAException - If an error occurs.

prepare

public int prepare(javax.transaction.xa.Xid xid)
            throws javax.transaction.xa.XAException
Prepares for a transaction commit.
Specified by:
prepare in interface javax.transaction.xa.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:
javax.transaction.xa.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.
Specified by:
recover in interface javax.transaction.xa.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:
javax.transaction.xa.XAException - If an error occurs.

rollback

public void rollback(javax.transaction.xa.Xid xid)
              throws javax.transaction.xa.XAException
Rolls back a transaction branch.
Specified by:
rollback in interface javax.transaction.xa.XAResource
Parameters:
xid - The global transaction identifier.
Throws:
javax.transaction.xa.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.
Specified by:
setTransactionTimeout in interface javax.transaction.xa.XAResource
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:
javax.transaction.xa.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.
Specified by:
start in interface javax.transaction.xa.XAResource
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:
javax.transaction.xa.XAException - If an error occurs.

toString

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