* @param xaStatefulHolder the {@link XAStatefulHolder} to requeue.
* @param bean the {@link ResourceBean} of the {@link XAResourceHolder}.
* @throws BitronixSystemException if an internal error happens.
*/
public static void requeue(XAStatefulHolder xaStatefulHolder, ResourceBean bean) throws BitronixSystemException {
BitronixTransaction currentTransaction = currentTransaction();
if (log.isDebugEnabled()) log.debug("requeuing " + xaStatefulHolder + " from " + currentTransaction);
if (!TransactionContextHelper.isInEnlistingGlobalTransactionContext(xaStatefulHolder, currentTransaction)) {
if (!TransactionContextHelper.isEnlistedInSomeTransaction(xaStatefulHolder)) {
// local mode, always requeue connection immediately
if (log.isDebugEnabled()) log.debug("resource not in enlisting global transaction context, immediately releasing to pool " + xaStatefulHolder);
xaStatefulHolder.setState(XAResourceHolder.STATE_IN_POOL);
} else {
throw new BitronixSystemException("cannot close a resource when its XAResource is taking part in an unfinished global transaction");
}
}
else if (bean.getDeferConnectionRelease()) {
// global mode, defer connection requeuing
if (log.isDebugEnabled()) log.debug("deferring release to pool of " + xaStatefulHolder);
if (!TransactionContextHelper.isAlreadyRegisteredForDeferredRelease(xaStatefulHolder, currentTransaction)) {
if (log.isDebugEnabled()) log.debug("registering DeferredReleaseSynchronization for " + xaStatefulHolder);
DeferredReleaseSynchronization synchronization = new DeferredReleaseSynchronization(xaStatefulHolder);
currentTransaction.getSynchronizationScheduler().add(synchronization, Scheduler.ALWAYS_LAST_POSITION);
}
else if (log.isDebugEnabled()) log.debug("already registered DeferredReleaseSynchronization for " + xaStatefulHolder);
xaStatefulHolder.setState(XAResourceHolder.STATE_NOT_ACCESSIBLE);
}