org.apache.derby.impl.store.raw.xact
public class: XactXAResourceManager [javadoc |
source]
java.lang.Object
org.apache.derby.impl.store.raw.xact.XactXAResourceManager
All Implemented Interfaces:
XAResourceManager
The XactXAResourceManager implements the Access XAResource interface, which
provides offline control over two phase commit transactions. It is expected
to be used by TM's (transaction manager's), to recover if systems fail while
transactions are still in-doubt (prepared).
This interface allows access to commit,prepare,abort global transactions
as part of a two phase commit protocol. These interfaces have been chosen
to be exact implementations required to implement the XAResource interfaces
as part of the JTA standard extension.
It is expected that the following interfaces are only used during the
recovery portion of 2 phase commit, when the transaction manager is
cleaning up after a runtime crash - it is expected that no current context
managers exist for the Xid's being operated on. The "online" two phase commit
protocol will be implemented by calls directly on a TransactionController.
The XAResource interface is a Java mapping of the industry standard XA resource
manager interface. Please refer to: X/Open CAE Specification - Distributed
Transaction Processing: The XA Specification, X/Open Document No. XO/CAE/91/300
or ISBN 1 872630 24 3.
Methods from java.lang.Object: |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method from org.apache.derby.impl.store.raw.xact.XactXAResourceManager Detail: |
public void commit(ContextManager cm,
Xid xid,
boolean onePhase) throws StandardException {
Transaction rawtran =
rsf.findUserTransaction(cm, AccessFactoryGlobals.USER_TRANS_NAME);
// This may happen if somehow the transaction was committed between
// the find() call and now.
if (rawtran == null)
{
throw StandardException.newException(
SQLState.STORE_XA_PROTOCOL_VIOLATION);
}
if (SanityManager.DEBUG)
{
SanityManager.ASSERT(rawtran != null);
SanityManager.ASSERT(
(new GlobalXactId(
xid.getFormatId(),
xid.getGlobalTransactionId(),
xid.getBranchQualifier())).equals(rawtran.getGlobalId()));
}
rawtran.xa_commit(onePhase);
}
|
public ContextManager find(Xid xid) {
return(
transaction_table.findTransactionContextByGlobalId(
new GlobalXactId(
xid.getFormatId(),
xid.getGlobalTransactionId(),
xid.getBranchQualifier())));
}
Find the given Xid in the transaction table.
This routine is used to find a in-doubt transaction from the list
of Xid's returned from the recover() routine.
In the current implementation it is up to the calling routine
to make the returned ContextManager the "current" ContextManager
before calls to commit,abort, or forget. The caller is responsible
for error handling, ie. calling cleanupOnError() on the correct
ContextManager.
If the Xid is not in the system, "null" is returned.
RESOLVE - find out from sku if she wants a exception instead?
|
public void forget(ContextManager cm,
Xid xid) throws StandardException {
Transaction rawtran =
rsf.findUserTransaction(cm, AccessFactoryGlobals.USER_TRANS_NAME);
if (SanityManager.DEBUG)
{
SanityManager.ASSERT(
new GlobalXactId(
xid.getFormatId(),
xid.getGlobalTransactionId(),
xid.getBranchQualifier()).equals(rawtran.getGlobalId()));
}
// forget should only be called on heuristically completed xacts, which
// should not exist in our system.
throw StandardException.newException(
SQLState.STORE_XA_PROTOCOL_VIOLATION);
}
This method is called to remove the given transaction
from the transaction table/log.
Used to let the store remove all record from log and transaction
table of the given transaction. This should only be used to
clean up heuristically completed transactions, otherwise commit or
abort should be used to act on other transactions.
|
public Xid[] recover(int flags) throws StandardException {
XAXactId[] ret_xid_list;
if ((flags & XAResource.TMSTARTRSCAN) != 0)
{
Hashtable trans_hashtable = transaction_table.getTableForXA();
XAXactId[] xid_list = new XAXactId[trans_hashtable.size()];
int num_prepared = 0;
// Need to hold sync while linear searching the hash table.
synchronized (trans_hashtable)
{
int i = 0;
for (Enumeration e = trans_hashtable.elements();
e.hasMoreElements(); i++)
{
Xact xact =
((TransactionTableEntry) e.nextElement()).getXact();
if (xact.isPrepared())
{
GlobalTransactionId xa_id = xact.getGlobalId();
xid_list[i] =
new XAXactId(
xa_id.getFormat_Id(),
xa_id.getGlobalTransactionId(),
xa_id.getBranchQualifier());
num_prepared++;
}
}
}
// now need to squish the nulls out of the array to return.
ret_xid_list = new XAXactId[num_prepared];
int ret_index = 0;
for (int i = xid_list.length; i-- > 0; )
{
if (xid_list[i] != null)
ret_xid_list[ret_index++] = xid_list[i];
}
if (SanityManager.DEBUG)
{
SanityManager.ASSERT(ret_index == num_prepared);
}
}
else
{
ret_xid_list = new XAXactId[0];
}
return(ret_xid_list);
}
This method is called to obtain a list of prepared transactions.
This call returns a complete list of global transactions which are
either prepared or heuristically complete.
The XAResource interface expects a scan type interface, but our
implementation only returns a complete list of transactions. So to
simulate the scan the following state is maintained. If TMSTARTSCAN
is specified the complete list is returned. If recover is called with
TMNOFLAGS is ever called a 0 length array is returned. |
public void rollback(ContextManager cm,
Xid xid) throws StandardException {
Transaction rawtran =
rsf.findUserTransaction(cm, AccessFactoryGlobals.USER_TRANS_NAME);
// This may happen if somehow the transaction was committed between
// the find() call and now.
if (rawtran == null)
{
throw StandardException.newException(
SQLState.STORE_XA_PROTOCOL_VIOLATION);
}
if (SanityManager.DEBUG)
{
SanityManager.ASSERT(
new GlobalXactId(
xid.getFormatId(),
xid.getGlobalTransactionId(),
xid.getBranchQualifier()).equals(rawtran.getGlobalId()));
}
rawtran.xa_rollback();
}
rollback the transaction identified by Xid.
The given transaction is roll'ed back and it's history is not
maintained in the transaction table or long term log.
|