From 723a12fd666f45739d6fd4c640cb9381b263c507 Mon Sep 17 00:00:00 2001 From: Rob Bygrave Date: Thu, 16 Jan 2025 08:15:22 +1300 Subject: [PATCH] #3538 Restoring batchMode etc with nested transaction scopes 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). --- .../java/io/ebeaninternal/api/ScopeTrans.java | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/ebean-core/src/main/java/io/ebeaninternal/api/ScopeTrans.java b/ebean-core/src/main/java/io/ebeaninternal/api/ScopeTrans.java index 1dbedb6eb9..348f1e4a48 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/api/ScopeTrans.java +++ b/ebean-core/src/main/java/io/ebeaninternal/api/ScopeTrans.java @@ -34,8 +34,8 @@ public final class ScopeTrans { * Explicit set of Exceptions that DO cause a rollback to occur. */ private final ArrayList> rollbackFor; - private Boolean restoreBatch; - private Boolean restoreBatchOnCascade; + private boolean restoreBatch; + private boolean restoreBatchOnCascade; private int restoreBatchSize; private Boolean restoreBatchGeneratedKeys; private boolean restoreBatchFlushOnQuery; @@ -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(); @@ -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); }