FileDocCategorySizeDatePackage
XAResourceImpl.javaAPI DocGlassfish v2 API8656Fri May 04 22:36:04 BST 2007com.sun.gjc.spi

XAResourceImpl

public class XAResourceImpl extends Object implements XAResource
XAResource wrapper for Generic JDBC Connector.
author
Evani Sai Surya Kiran
version
1.0, 02/08/23

Fields Summary
XAResource
xar
com.sun.gjc.spi.ManagedConnection
mc
Constructors Summary
public XAResourceImpl(XAResource xar, com.sun.gjc.spi.ManagedConnection mc)
Constructor for XAResourceImpl

param
xar XAResource
param
mc ManagedConnection

        this.xar = xar;
        this.mc = mc;
    
Methods Summary
public voidcommit(javax.transaction.xa.Xid xid, boolean onePhase)
Commit the global transaction specified by xid.

param
xid A global transaction identifier
param
onePhase If true, the resource manager should use a one-phase commit protocol to commit the work done on behalf of xid.

        //the mc.transactionCompleted call has come here becasue
        //the transaction *actually* completes after the flow
        //reaches here. the end() method might not really signal
        //completion of transaction in case the transaction is
        //suspended. In case of transaction suspension, the end
        //method is still called by the transaction manager
        try {
            xar.commit(xid, onePhase);
        } catch (XAException xae) {
            throw xae;
        } catch (Exception e) {
            throw new XAException(e.getMessage());
        } finally {
            mc.transactionCompleted();
        }
    
public voidend(javax.transaction.xa.Xid xid, int flags)
Ends the work performed on behalf of a transaction branch.

param
xid A global transaction identifier that is the same as what was used previously in the start method.
param
flags One of TMSUCCESS, TMFAIL, or TMSUSPEND

        xar.end(xid, flags);
        //GJCINT
        //mc.transactionCompleted();
    
public voidforget(javax.transaction.xa.Xid xid)
Tell the resource manager to forget about a heuristically completed transaction branch.

param
xid A global transaction identifier

        xar.forget(xid);
    
public intgetTransactionTimeout()
Obtain the current transaction timeout value set for this XAResource instance.

return
the transaction timeout value in seconds

        return xar.getTransactionTimeout();
    
public booleanisSameRM(javax.transaction.xa.XAResource xares)
This method is called to determine if the resource manager instance represented by the target object is the same as the resouce manager instance represented by the parameter xares.

param
xares An XAResource object whose resource manager instance is to be compared with the resource
return
true if it's the same RM instance; otherwise false.

        return xar.isSameRM(xares);
    
public intprepare(javax.transaction.xa.Xid xid)
Ask the resource manager to prepare for a transaction commit of the transaction specified in xid.

param
xid A global transaction identifier
return
A value indicating the resource manager's vote on the outcome of the transaction. The possible values are: XA_RDONLY or XA_OK. If the resource manager wants to roll back the transaction, it should do so by raising an appropriate XAException in the prepare method.

        try {
            int result = xar.prepare(xid);
            //When the VOTE from resource manager is XA_RDONLY , we will not get commit() call from TxManager.
            //Hence calling txCompleted.
            if (result == XAResource.XA_RDONLY) {
                mc.transactionCompleted();
            }
            return result;
        } catch (XAException xae) {
            mc.transactionCompleted();
            throw xae;
        } catch (Exception e) {
            mc.transactionCompleted();
            throw new XAException(e.getMessage());
        }
    
public javax.transaction.xa.Xid[]recover(int flag)
Obtain a list of prepared transaction branches from a resource manager.

param
flag One of TMSTARTRSCAN, TMENDRSCAN, TMNOFLAGS. TMNOFLAGS must be used when no other flags are set in flags.
return
The resource manager returns zero or more XIDs for the transaction branches that are currently in a prepared or heuristically completed state. If an error occurs during the operation, the resource manager should throw the appropriate XAException.

        return xar.recover(flag);
    
public voidrollback(javax.transaction.xa.Xid xid)
Inform the resource manager to roll back work done on behalf of a transaction branch

param
xid A global transaction identifier

        //the mc.transactionCompleted call has come here becasue
        //the transaction *actually* completes after the flow
        //reaches here. the end() method might not really signal
        //completion of transaction in case the transaction is
        //suspended. In case of transaction suspension, the end
        //method is still called by the transaction manager
        try {
            xar.rollback(xid);
        } catch (XAException xae) {
            throw xae;
        } catch (Exception e) {
            throw new XAException(e.getMessage());
        } finally {
            mc.transactionCompleted();
        }
    
public booleansetTransactionTimeout(int seconds)
Set the current transaction timeout value for this XAResource instance.

param
seconds the transaction timeout value in seconds.
return
true if transaction timeout value is set successfully; otherwise false.

        return xar.setTransactionTimeout(seconds);
    
public voidstart(javax.transaction.xa.Xid xid, int flags)
Start work on behalf of a transaction branch specified in xid.

param
xid A global transaction identifier to be associated with the resource
return
flags One of TMNOFLAGS, TMJOIN, or TMRESUME

        //GJCINT
        mc.transactionStarted();
        xar.start(xid, flags);