ResourceBean bean = xaResourceHolder.getResourceBean();
if (log.isDebugEnabled()) { log.debug("enlisting " + xaResourceHolder + " into " + currentTransaction); }
if (currentTransaction != null) {
if (currentTransaction.timedOut())
throw new BitronixSystemException("transaction timed out");
// in case multiple unjoined branches of the current transaction have run on the resource,
// only the last one counts as all the first ones are ended already
XAResourceHolderState alreadyEnlistedXAResourceHolderState = TransactionContextHelper.getLatestAlreadyEnlistedXAResourceHolderState(xaResourceHolder, currentTransaction);
if (alreadyEnlistedXAResourceHolderState == null || alreadyEnlistedXAResourceHolderState.isEnded()) {
currentTransaction.enlistResource(xaResourceHolder.getXAResource());
}
else if (log.isDebugEnabled()) { log.debug("avoiding re-enlistment of already enlisted but not ended resource " + alreadyEnlistedXAResourceHolderState); }
}
else {
if (bean.getAllowLocalTransactions()) {
if (log.isDebugEnabled()) { log.debug("in local transaction context, skipping enlistment"); }
}
else
throw new BitronixSystemException("resource '" + bean.getUniqueName() + "' cannot be used outside XA " +
"transaction scope. Set allowLocalTransactions to true if you want to allow this and you know " +
"your resource supports this.");
}
}