use of org.apache.derby.iapi.store.access.xa.XAResourceManager 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.XAResourceManager 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.XAResourceManager in project derby by apache.
the class EmbedXAResource method prepare.
/**
* 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.
*
* @exception XAException An error has occurred. Possible exception values
* are: XA_RB*, XAER_RMERR, XAER_RMFAIL, XAER_NOTA, XAER_INVAL, or
* XAER_PROTO.
*/
public final synchronized int prepare(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);
// cannot prepare in doubt transactions
throw new XAException(XAException.XAER_PROTO);
}
synchronized (tranState) {
checkUserCredentials(tranState.creatingResource);
// any XAResource.
switch(tranState.associationState) {
case XATransactionState.T0_NOT_ASSOCIATED:
break;
case XATransactionState.TRO_FAIL:
throw new XAException(tranState.rollbackOnlyCode);
default:
throw new XAException(XAException.XAER_PROTO);
}
if (tranState.suspendedList != null && tranState.suspendedList.size() != 0)
throw new XAException(XAException.XAER_PROTO);
if (tranState.isPrepared)
throw new XAException(XAException.XAER_PROTO);
try {
int ret = tranState.xa_prepare();
if (ret == XATransactionController.XA_OK) {
tranState.isPrepared = true;
return XAResource.XA_OK;
} else {
returnConnectionToResource(tranState, xid_im);
if (SanityManager.DEBUG) {
if (con.realConnection != null) {
SanityManager.ASSERT(con.realConnection.transactionIsIdle(), "real connection should have been idle." + "tranState = " + tranState + "ret = " + ret + "con.realConnection = " + con.realConnection);
}
}
return XAResource.XA_RDONLY;
}
} catch (SQLException sqle) {
XAException xe = wrapInXAException(sqle);
if (ExceptionUtil.isDeferredConstraintViolation(sqle.getSQLState())) {
// We are rolling back
returnConnectionToResource(tranState, xid_im);
}
throw xe;
}
}
}
use of org.apache.derby.iapi.store.access.xa.XAResourceManager in project derby by apache.
the class EmbedXAResource method commit.
/**
* 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.
*
* @exception XAException An error has occurred. Possible XAExceptions are
* XA_HEURHAZ, XA_HEURCOM, XA_HEURRB, XA_HEURMIX, XAER_RMERR,
* XAER_RMFAIL, XAER_NOTA, XAER_INVAL, or XAER_PROTO.
* <P>If the resource manager did not commit the transaction and
* the paramether onePhase is set to true, the resource manager
* may throw one of the XA_RB* exceptions. Upon return, the
* resource manager has rolled back the branch's work and has
* released all held resources.
*/
public final synchronized void commit(Xid xid, boolean onePhase) 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.commit(inDoubtCM, xid_im, onePhase);
// close the connection/transaction since it can never
// be used again. DERBY-4856 No extended diagnostic information needed.
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) {
checkUserCredentials(tranState.creatingResource);
// any XAResource.
switch(tranState.associationState) {
case XATransactionState.T0_NOT_ASSOCIATED:
break;
case XATransactionState.TRO_FAIL:
throw new XAException(tranState.rollbackOnlyCode);
default:
throw new XAException(XAException.XAER_PROTO);
}
if (tranState.suspendedList != null && tranState.suspendedList.size() != 0)
throw new XAException(XAException.XAER_PROTO);
if (tranState.isPrepared == onePhase)
throw new XAException(XAException.XAER_PROTO);
try {
tranState.xa_commit(onePhase);
} catch (SQLException sqle) {
throw wrapInXAException(sqle);
} finally {
returnConnectionToResource(tranState, xid_im);
}
}
}
Aggregations