boolean shouldRollback;
try {
shouldRollback = tx.getStatus() != Status.STATUS_ACTIVE;
} catch (javax.transaction.SystemException e) {
txLogger.error("The Transaction Manager has encountered an unexpected error condition while attempting to obtain transaction status: {}", e.getMessage());
throw new SystemException(e);
}
if (shouldRollback) {
rollbackTransaction(tx);
return;
}
try {
txLogger.debug("TX {}: Committing transaction {}", transactionType, tx);
if (tx.equals(transactionManager.getTransaction())) {
transactionManager.commit();
} else {
tx.commit();
}
} catch (RollbackException e) {
txLogger.debug("The transaction has been rolled back rather than commited: {}", e.getMessage());
Throwable txe = new TransactionRolledbackException("Transaction was rolled back, presumably because setRollbackOnly was called during a synchronization").initCause(e);
throw new ApplicationException(txe);
} catch (HeuristicMixedException e) {
txLogger.debug("A heuristic decision was made, some relevant updates have been committed while others have been rolled back: {}", e.getMessage());
throw new ApplicationException(new RemoteException("A heuristic decision was made, some relevant updates have been committed while others have been rolled back").initCause(e));
} catch (HeuristicRollbackException e) {
txLogger.debug("A heuristic decision was made while commiting the transaction, some relevant updates have been rolled back: {}", e.getMessage());
throw new ApplicationException(new RemoteException("A heuristic decision was made while commiting the transaction, some relevant updates have been rolled back").initCause(e));
} catch (SecurityException e) {
txLogger.error("The current thread is not allowed to commit the transaction: {}", e.getMessage());
throw new SystemException(e);
} catch (IllegalStateException e) {
txLogger.error("The current thread is not associated with a transaction: {}", e.getMessage());
throw new SystemException(e);
} catch (javax.transaction.SystemException e) {
txLogger.error("The Transaction Manager has encountered an unexpected error condition while attempting to commit the transaction: {}", e.getMessage());
throw new SystemException(e);
}
}