Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JBPM-10245] Make sure that thread is clean when commit/rollback #3070

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading