Skip to content

Commit

Permalink
#3538 Restoring batchMode etc with nested transaction scopes
Browse files Browse the repository at this point in the history
This change is a simplification such that these batch attributes are always stored and restored for nested ScopeTrans.

There are no expensive side effects of doing it this way.

This fixes issues where the batch attributes are changed after the ScopeTrans is created (like the test for this PR).
  • Loading branch information
rbygrave committed Jan 15, 2025
1 parent 5cf74f1 commit 723a12f
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions ebean-core/src/main/java/io/ebeaninternal/api/ScopeTrans.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public final class ScopeTrans {
* Explicit set of Exceptions that DO cause a rollback to occur.
*/
private final ArrayList<Class<? extends Throwable>> rollbackFor;
private Boolean restoreBatch;
private Boolean restoreBatchOnCascade;
private boolean restoreBatch;
private boolean restoreBatchOnCascade;
private int restoreBatchSize;
private Boolean restoreBatchGeneratedKeys;
private boolean restoreBatchFlushOnQuery;
Expand All @@ -61,7 +61,7 @@ public ScopeTrans(boolean rollbackOnChecked, boolean created, SpiTransaction tra
this.noRollbackFor = txScope.getNoRollbackFor();
this.rollbackFor = txScope.getRollbackFor();
if (transaction != null) {
if (!created && txScope.isBatchSet() || txScope.isBatchOnCascadeSet() || txScope.isBatchSizeSet()) {
if (!created) {
restoreBatch = transaction.isBatchMode();
restoreBatchOnCascade = transaction.isBatchOnCascade();
restoreBatchSize = transaction.getBatchSize();
Expand Down Expand Up @@ -143,15 +143,9 @@ void commitTransaction() {
} else {
nestedCommit = true;
transaction.setFlushOnQuery(restoreBatchFlushOnQuery);
if (restoreBatch != null) {
transaction.setBatchMode(restoreBatch);
}
if (restoreBatchOnCascade != null) {
transaction.setBatchOnCascade(restoreBatchOnCascade);
}
if (restoreBatchSize > 0) {
transaction.setBatchSize(restoreBatchSize);
}
transaction.setBatchMode(restoreBatch);
transaction.setBatchOnCascade(restoreBatchOnCascade);
transaction.setBatchSize(restoreBatchSize);
if (restoreBatchGeneratedKeys != null) {
transaction.setGetGeneratedKeys(restoreBatchGeneratedKeys);
}
Expand Down

0 comments on commit 723a12f

Please sign in to comment.