use of org.apache.derby.iapi.store.access.xa.XAXactId in project derby by apache.
the class DRDAXAProtocol method rollbackCurrentTransaction.
/**
* This function rollbacks the current global transaction associated
* with the XAResource or a local transaction. The function should
* be called only in exceptional cases - like client socket
* is closed.
*/
void rollbackCurrentTransaction() {
if (xid != null) {
boolean local = (xid.getFormatId() == -1);
if (!local) {
try {
XAXactId xid_im = new XAXactId(xid);
getResourceAdapter().cancelXATransaction(xid_im, MessageId.CONN_CLOSE_XA_TRANSACTION_ROLLED_BACK);
} catch (XAException e) {
Monitor.logThrowable(e);
}
} else {
try {
rollbackTransaction(xid, false);
} catch (DRDAProtocolException e) {
// because we do not dump any DRDA stuff to the socket
// the exception can not be thrown in this case
// However, we will log the exception to the monitor
Monitor.logThrowable(e);
}
}
xid = null;
}
}
use of org.apache.derby.iapi.store.access.xa.XAXactId in project derby by apache.
the class EmbedXAResource method forget.
/**
* Tell the resource manager to forget about a heuristically completed
* transaction branch.
*
* @param xid A global transaction identifier
* @exception XAException An error has occurred. Possible exception values
* are XAER_RMERR, XAER_RMFAIL, XAER_NOTA, XAER_INVAL, or XAER_PROTO.
*/
public final synchronized void forget(Xid xid) throws XAException {
checkXAActive();
// ensure immtable and correct equals method.
XAXactId xid_im = new XAXactId(xid);
XATransactionState tranState = getTransactionState(xid_im);
if (tranState == null) {
XAResourceManager rm = ra.getXAResourceManager();
ContextManager inDoubtCM = rm.find(xid);
// RM also does not know about this xid.
if (inDoubtCM == null)
throw new XAException(XAException.XAER_NOTA);
ContextService csf = getContextService();
csf.setCurrentContextManager(inDoubtCM);
try {
rm.forget(inDoubtCM, xid_im);
// close the connection/transaction since it can never be used again.
inDoubtCM.cleanupOnError(StandardException.closeException(), false);
return;
} catch (StandardException se) {
// The rm threw an exception, clean it up in the approprate
// context. There is no transactionResource to handle the
// exception for us.
inDoubtCM.cleanupOnError(se, con.isActive());
throw wrapInXAException(se);
} finally {
csf.resetCurrentContextManager(inDoubtCM);
}
}
// DERBY-1016; if the transaction exists throw XAER_PROTO on forget
throw new XAException(XAException.XAER_PROTO);
}
use of org.apache.derby.iapi.store.access.xa.XAXactId in project derby by apache.
the class EmbedXAResource method rollback.
/**
* Inform the resource manager to roll back work done on behalf of a
* transaction branch
*
* @param xid A global transaction identifier
* @exception XAException - An error has occurred
*/
public final synchronized void rollback(Xid xid) throws XAException {
checkXAActive();
// ensure immtable and correct equals method.
XAXactId xid_im = new XAXactId(xid);
XATransactionState tranState = getTransactionState(xid_im);
if (tranState == null) {
XAResourceManager rm = ra.getXAResourceManager();
ContextManager inDoubtCM = rm.find(xid);
// RM also does not know about this xid.
if (inDoubtCM == null)
throw new XAException(XAException.XAER_NOTA);
ContextService csf = getContextService();
csf.setCurrentContextManager(inDoubtCM);
try {
rm.rollback(inDoubtCM, xid_im);
// close the connection/transaction since it can never be used again.
inDoubtCM.cleanupOnError(StandardException.closeException(), false);
return;
} catch (StandardException se) {
// The rm threw an exception, clean it up in the approprate
// context. There is no transactionResource to handle the
// exception for us.
inDoubtCM.cleanupOnError(se, con.isActive());
throw wrapInXAException(se);
} finally {
csf.resetCurrentContextManager(inDoubtCM);
}
}
synchronized (tranState) {
// any XAResource.
switch(tranState.associationState) {
case XATransactionState.T0_NOT_ASSOCIATED:
case XATransactionState.TRO_FAIL:
break;
default:
throw new XAException(XAException.XAER_PROTO);
}
if (tranState.suspendedList != null && tranState.suspendedList.size() != 0)
throw new XAException(XAException.XAER_PROTO);
checkUserCredentials(tranState.creatingResource);
try {
tranState.xa_rollback();
} catch (SQLException sqle) {
throw wrapInXAException(sqle);
} finally {
returnConnectionToResource(tranState, xid_im);
}
}
}
use of org.apache.derby.iapi.store.access.xa.XAXactId in project derby by apache.
the class ResourceAdapterImpl method boot.
/*
* Module control
*/
public void boot(boolean create, Properties properties) throws StandardException {
// we can only run on jdk1.2 or beyond with JTA and JAVA 20 extension
// loaded.
connectionTable = new Hashtable<XAXactId, XATransactionState>();
AccessFactory af = (AccessFactory) findServiceModule(this, AccessFactory.MODULE);
rm = (XAResourceManager) af.getXAResourceManager();
active = true;
}
use of org.apache.derby.iapi.store.access.xa.XAXactId in project derby by apache.
the class XactXAResourceManager method recover.
/**
* This method is called to obtain a list of prepared transactions.
* <p>
* This call returns a complete list of global transactions which are
* either prepared or heuristically complete.
* <p>
* 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.
*
* @return Return a array with 0 or more Xid's which are currently in
* prepared or heuristically completed state. If an error occurs
* during the operation, an appropriate error is thrown.
*
* @param flags combination of the following flags
* XAResource.{TMSTARTRSCAN,TMENDRSCAN,TMNOFLAGS}.
* TMNOFLAGS must be used when no other flags are used.
*
* @exception StandardException Standard exception policy.
*/
public Xid[] recover(int flags) throws StandardException {
XAXactId[] ret_xid_list;
if ((flags & XAResource.TMSTARTRSCAN) != 0) {
final ArrayList<XAXactId> xid_list = new ArrayList<XAXactId>();
// Create a visitor that adds each of the prepared transactions
// to xid_list.
final TransactionTable.EntryVisitor visitor = new TransactionTable.EntryVisitor() {
public boolean visit(TransactionTableEntry entry) {
Xact xact = entry.getXact();
if (xact.isPrepared()) {
GlobalXactId xa_id = (GlobalXactId) xact.getGlobalId();
xid_list.add(new XAXactId(xa_id.getFormat_Id(), xa_id.getGlobalTransactionId(), xa_id.getBranchQualifier()));
}
// scan the entire transaction table
return true;
}
};
// Collect the prepared transactions.
transaction_table.visitEntries(visitor);
// Convert the list to an array suitable for being returned.
ret_xid_list = new XAXactId[xid_list.size()];
ret_xid_list = (XAXactId[]) xid_list.toArray(ret_xid_list);
} else {
ret_xid_list = new XAXactId[0];
}
return (ret_xid_list);
}
Aggregations