Skip to content

Commit

Permalink
[JBPM-10245] Make sure that thread is clean when commit/rollback
Browse files Browse the repository at this point in the history
  • Loading branch information
fjtirado committed Dec 12, 2024
1 parent b2c1cec commit 47da21b
Showing 1 changed file with 18 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public boolean begin() {
// RHBPMS-4621 - transaction can be marked as rollback
// and still be associated with current thread
// See WFLY-4327
if ( getStatus() == TransactionManager.STATUS_ROLLEDBACK ) {
logger.debug("Cleanup of transaction that has been rolled back previously");
if (getStatus() == TransactionManager.STATUS_ROLLEDBACK) {
logger.warn("Cleaning up rolledback transaction");
rollback(true);
}
if (getStatus() == TransactionManager.STATUS_NO_TRANSACTION) {
Expand Down Expand Up @@ -82,33 +82,34 @@ public void commit(boolean transactionOwner) {
try {
// if we didn't begin this transaction, then do nothing
this.ptm.commit(currentTransaction);
currentTransaction = null;
if (TransactionSynchronizationManager.hasResource(KieSpringTransactionManager.RESOURCE_CONTAINER)) {
TransactionSynchronizationManager.unbindResource(KieSpringTransactionManager.RESOURCE_CONTAINER);
}
} catch (Exception e) {
logger.warn("Unable to commit transaction",
e);
throw new RuntimeException("Unable to commit transaction",
e);
} finally {
cleanupTransaction();
}

}

public void rollback(boolean transactionOwner) {
try {
if (transactionOwner) {
if (transactionOwner) {
try {
this.ptm.rollback(currentTransaction);
currentTransaction = null;
if (TransactionSynchronizationManager.hasResource(KieSpringTransactionManager.RESOURCE_CONTAINER)) {
TransactionSynchronizationManager.unbindResource(KieSpringTransactionManager.RESOURCE_CONTAINER);
}
} catch (Exception e) {
logger.warn("Unable to rollback transaction", e);
throw new RuntimeException("Unable to rollback transaction", e);
} finally {
cleanupTransaction();
}
} catch (Exception e) {
logger.warn("Unable to rollback transaction",
e);
throw new RuntimeException("Unable to rollback transaction",
e);
}
}

private void cleanupTransaction() {
currentTransaction = null;
if (TransactionSynchronizationManager.hasResource(KieSpringTransactionManager.RESOURCE_CONTAINER)) {
TransactionSynchronizationManager.unbindResource(KieSpringTransactionManager.RESOURCE_CONTAINER);
}
}

Expand Down

0 comments on commit 47da21b

Please sign in to comment.