Transaction transaction = tm.getTransaction();
if (transaction == null) throw new IllegalStateException("This should only be called in an tx scope");
int status = transaction.getStatus();
if (isNotValid(status)) throw new IllegalStateException("Transaction " + transaction +
" is not in a valid state to be invoking cache operations on.");
LocalTransaction localTransaction = txTable.getOrCreateLocalTransaction(transaction, ctx);
if (!localTransaction.isEnlisted()) { //make sure that you only enlist it once
try {
transaction.enlistResource(new TransactionXaAdapter(localTransaction, txTable, commandsFactory, configuration, invoker, icc));
} catch (Exception e) {
Xid xid = localTransaction.getXid();
if (xid != null && !ctx.getLockedKeys().isEmpty()) {
log.debug("Attempting a rollback to clear stale resources!");
try {
TransactionXaAdapter.rollbackImpl(xid, commandsFactory, icc, invoker, txTable);
} catch (XAException xae) {