// already started local TX and registered in JTA
// make sure the JTA transaction hasn't changed (happens when TM.suspend() is called)
Transaction tx = transactionManager.getTransaction();
if (!BOUND_JTA_TRANSACTIONS.get().equals(tx)) {
throw new TransactionException("Invalid JTA transaction context, cache was first used in transaction ["
+ BOUND_JTA_TRANSACTIONS + "]" +
" but is now used in transaction [" + tx + "].");
}
} else {
Transaction tx = transactionManager.getTransaction();
if (tx == null) {
throw new TransactionException("no JTA transaction context started, xa caches cannot be used outside of" +
" JTA transactions");
}
BOUND_JTA_TRANSACTIONS.set(tx);
transactionController.begin();
// DEV-5376
if (Boolean.getBoolean(ALTERNATIVE_TERMINATION_MODE_SYS_PROPERTY_NAME)) {
JtaLocalEhcacheXAResource xaRes = new JtaLocalEhcacheXAResource(transactionController,
transactionController.getCurrentTransactionContext().getTransactionId());
transactionManagerLookup.register(xaRes);
tx.enlistResource(xaRes);
} else {
tx.registerSynchronization(new JtaLocalEhcacheSynchronization(transactionController,
transactionController.getCurrentTransactionContext().getTransactionId()));
}
}
} catch (SystemException e) {
throw new TransactionException("internal JTA transaction manager error, cannot bind xa cache with it", e);
} catch (RollbackException e) {
throw new TransactionException("JTA transaction rolled back, cannot bind xa cache with it", e);
}
}