org.jboss.minerva.xa
Class XAResourceImpl

java.lang.Object
  |
  +--org.jboss.minerva.xa.XAResourceImpl
All Implemented Interfaces:
javax.transaction.xa.XAResource

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

JTA resource implementation for JDBC 1.0 connections. This is somewhat limited in two respects. First, it does not support two-phase commits since JDBC 1.0 does not. It will operate in the presence of two-phase commits, but will throw heuristic exceptions if there is a failure during a commit or rollback. Second, it can only be associated with one transaction at a time, and will throw exceptions if a second transaction tries to attach before the first has called commit, rollback, or forget.

Warning:

This implementation assumes that forget will be called after a failed commit or rollback. Otherwise, the database connection will never be closed.

Version:
$Revision: 1.7 $
Author:
Aaron Mulder (ammulder@alumni.princeton.edu)

Fields inherited from interface javax.transaction.xa.XAResource
TMENDRSCAN, TMFAIL, TMJOIN, TMNOFLAGS, TMONEPHASE, TMRESUME, TMSTARTRSCAN, TMSUCCESS, TMSUSPEND, XA_OK, XA_RDONLY
 
Constructor Summary
XAResourceImpl(java.sql.Connection con)
          Creates a new instance as the transactional resource for the specified underlying connection.
 
Method Summary
 void close()
          Closes this instance permanently.
 void commit(javax.transaction.xa.Xid id, boolean twoPhase)
          Commits a transaction.
 void end(javax.transaction.xa.Xid id, int flags)
          Dissociates a resource from a global transaction.
 void forget(javax.transaction.xa.Xid id)
          Indicates that no further action will be taken on behalf of this transaction (after a heuristic failure).
 int getTransactionTimeout()
          Gets the transaction timeout.
 XAConnectionImpl getXAConnection()
           
 boolean isSameRM(javax.transaction.xa.XAResource res)
          Since the concept of resource managers does not really apply here (all JDBC connections must be managed individually), indicates whether the specified resource is the same as this one.
 boolean isTransaction()
          Gets whether there is outstanding work on behalf of a Transaction.
 int prepare(javax.transaction.xa.Xid id)
          Prepares a transaction to commit.
 javax.transaction.xa.Xid[] recover(int flag)
          Returns all transaction IDs where work was done with no corresponding commit, rollback, or forget.
 void rollback(javax.transaction.xa.Xid id)
          Rolls back the work, assuming it was done on behalf of the specified transaction.
 boolean setTransactionTimeout(int timeout)
          Sets the transaction timeout.
 void start(javax.transaction.xa.Xid id, int flags)
          Associates a JDBC connection with a global transaction.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XAResourceImpl

public XAResourceImpl(java.sql.Connection con)
Creates a new instance as the transactional resource for the specified underlying connection.
Method Detail

getXAConnection

public XAConnectionImpl getXAConnection()

isTransaction

public boolean isTransaction()
Gets whether there is outstanding work on behalf of a Transaction. If there is not, then a connection that is closed will cause the XAConnection to be closed or returned to a pool. If there is, then the XAConnection must be kept open until commit or rollback is called.

close

public void close()
Closes this instance permanently.

commit

public void commit(javax.transaction.xa.Xid id,
                   boolean twoPhase)
            throws javax.transaction.xa.XAException
Commits a transaction.
Specified by:
commit in interface javax.transaction.xa.XAResource
Throws:
javax.transaction.xa.XAException - Occurs when the state was not correct (end never called), the transaction ID is wrong, the connection was set to Auto-Commit, or the commit on the underlying connection fails. The error code differs depending on the exact situation.

end

public void end(javax.transaction.xa.Xid id,
                int flags)
         throws javax.transaction.xa.XAException
Dissociates a resource from a global transaction.
Specified by:
end in interface javax.transaction.xa.XAResource
Throws:
javax.transaction.xa.XAException - Occurs when the state was not correct (end called twice), or the transaction ID is wrong.

forget

public void forget(javax.transaction.xa.Xid id)
            throws javax.transaction.xa.XAException
Indicates that no further action will be taken on behalf of this transaction (after a heuristic failure). It is assumed this will be called after a failed commit or rollback.
Specified by:
forget in interface javax.transaction.xa.XAResource
Throws:
javax.transaction.xa.XAException - Occurs when the state was not correct (end never called), or the transaction ID is wrong.

getTransactionTimeout

public int getTransactionTimeout()
                          throws javax.transaction.xa.XAException
Gets the transaction timeout.
Specified by:
getTransactionTimeout in interface javax.transaction.xa.XAResource

isSameRM

public boolean isSameRM(javax.transaction.xa.XAResource res)
                 throws javax.transaction.xa.XAException
Since the concept of resource managers does not really apply here (all JDBC connections must be managed individually), indicates whether the specified resource is the same as this one.
Specified by:
isSameRM in interface javax.transaction.xa.XAResource

prepare

public int prepare(javax.transaction.xa.Xid id)
            throws javax.transaction.xa.XAException
Prepares a transaction to commit. Since JDBC 1.0 does not support 2-phase commits, this claims the commit is OK (so long as some work was done on behalf of the specified transaction).
Specified by:
prepare in interface javax.transaction.xa.XAResource
Throws:
javax.transaction.xa.XAException - Occurs when the state was not correct (end never called), the transaction ID is wrong, or the connection was set to Auto-Commit.

recover

public javax.transaction.xa.Xid[] recover(int flag)
                                   throws javax.transaction.xa.XAException
Returns all transaction IDs where work was done with no corresponding commit, rollback, or forget. Not really sure why this is useful in the context of JDBC drivers.
Specified by:
recover in interface javax.transaction.xa.XAResource

rollback

public void rollback(javax.transaction.xa.Xid id)
              throws javax.transaction.xa.XAException
Rolls back the work, assuming it was done on behalf of the specified transaction.
Specified by:
rollback in interface javax.transaction.xa.XAResource
Throws:
javax.transaction.xa.XAException - Occurs when the state was not correct (end never called), the transaction ID is wrong, the connection was set to Auto-Commit, or the rollback on the underlying connection fails. The error code differs depending on the exact situation.

setTransactionTimeout

public boolean setTransactionTimeout(int timeout)
                              throws javax.transaction.xa.XAException
Sets the transaction timeout. This is saved, but the value is not used by the current implementation.
Specified by:
setTransactionTimeout in interface javax.transaction.xa.XAResource

start

public void start(javax.transaction.xa.Xid id,
                  int flags)
           throws javax.transaction.xa.XAException
Associates a JDBC connection with a global transaction. We assume that end will be called followed by prepare, commit, or rollback. If start is called after end but before commit or rollback, there is no way to distinguish work done by different transactions on the same connection). If start is called more than once before end, either it's a duplicate transaction ID or illegal transaction ID (since you can't have two transactions associated with one DB connection).
Specified by:
start in interface javax.transaction.xa.XAResource
Throws:
javax.transaction.xa.XAException - Occurs when the state was not correct (start called twice), the transaction ID is wrong, or the instance has already been closed.


Copyright © 2000 The jBoss Organization. All Rights Reserved.