Skip to content

Commit

Permalink
PR ebean-orm#3147 - FIX: Rethrow error in commit path of callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
rPraml committed Aug 10, 2023
1 parent a54721f commit 6cd356c
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ final void checkAutoCommit(Connection connection) throws SQLException {
}



@Override
public final void setAutoPersistUpdates(boolean autoPersistUpdates) {
this.autoPersistUpdates = autoPersistUpdates;
Expand Down Expand Up @@ -252,25 +251,35 @@ public final void register(TransactionCallback callback) {
callbackList.add(callback);
}

private void withEachCallback(Consumer<TransactionCallback> consumer) {
private void withEachCallbackFailSilent(Consumer<TransactionCallback> consumer) {
if (callbackList != null) {
// using old style loop to cater for case when new callbacks are added recursively (as otherwise iterator fails fast)
for (int i = 0; i < callbackList.size(); i++) {
try {
consumer.accept(callbackList.get(i));
} catch (Exception e) {
log.log(ERROR, "Error executing transaction callback", e);
throw wrapIfNeeded(e);
}
}
}
}

private void withEachCallback(Consumer<TransactionCallback> consumer) {
if (callbackList != null) {
// using old style loop to cater for case when new callbacks are added recursively (as otherwise iterator fails fast)
for (int i = 0; i < callbackList.size(); i++) {
consumer.accept(callbackList.get(i));
}
}
}

private void firePreRollback() {
withEachCallback(TransactionCallback::preRollback);
withEachCallbackFailSilent(TransactionCallback::preRollback);
}

private void firePostRollback() {
withEachCallback(TransactionCallback::postRollback);
withEachCallbackFailSilent(TransactionCallback::postRollback);
if (changeLogHolder != null) {
changeLogHolder.postRollback();
}
Expand Down

0 comments on commit 6cd356c

Please sign in to comment.