try {
InitialContext initialContext = new InitialContext();
transactionSynchronizationRegistry =
(TransactionSynchronizationRegistry) initialContext.lookup(TRANSACTION_SYNCHRONIZATION_REGISTRY_JNDI_NAME);
} catch (NamingException ne) {
throw new ContextNotActiveException("Could not get TransactionSynchronizationRegistry", ne);
}
int status = transactionSynchronizationRegistry.getTransactionStatus();
if (status == Status.STATUS_ACTIVE ||
status == Status.STATUS_MARKED_ROLLBACK ||
status == Status.STATUS_PREPARED ||
status == Status.STATUS_UNKNOWN ||
status == Status.STATUS_PREPARING ||
status == Status.STATUS_COMMITTING ||
status == Status.STATUS_ROLLING_BACK) {
return transactionSynchronizationRegistry;
}
throw new ContextNotActiveException("TransactionSynchronizationRegistry status is not active.");
}