{
if (tx != null && tx.getXid().equals(xid))
{
final String msg = "Cannot roll back, session is currently doing work in a transaction " + tx.getXid();
throw new HornetQXAException(XAException.XAER_PROTO, msg);
}
else
{
Transaction theTx = resourceManager.removeTransaction(xid);
if (theTx == null)
{
// checked heuristic committed transactions
if (resourceManager.getHeuristicCommittedTransactions().contains(xid))
{
throw new HornetQXAException(XAException.XA_HEURCOM,
"transaction has ben heuristically committed: " + xid);
}
// checked heuristic rolled back transactions
else if (resourceManager.getHeuristicRolledbackTransactions().contains(xid))
{
throw new HornetQXAException(XAException.XA_HEURRB,
"transaction has ben heuristically rolled back: " + xid);
}
else
{
throw new HornetQXAException(XAException.XAER_NOTA, "Cannot find xid in resource manager: " + xid);
}
}
else
{
if (theTx.getState() == Transaction.State.SUSPENDED)
{
// Put it back
resourceManager.putTransaction(xid, tx);
throw new HornetQXAException(XAException.XAER_PROTO,
"Cannot rollback transaction, it is suspended " + xid);
}
else
{
doRollback(false, theTx);