#2110 Part2 - addBatch() does not auto flush (#2115)

This commit is contained in:
Rob Bygrave
2020-11-25 22:18:05 +13:00
committed by GitHub
parent cc637d56e1
commit 8e91268979
4 changed files with 14 additions and 16 deletions
@@ -104,7 +104,6 @@ public abstract class PersistRequest extends BeanRequest implements BatchPostExe
return transaction.isLogSummary();
}
/**
* Return true if this persist request should use JDBC batch.
*/
@@ -119,23 +118,22 @@ public abstract class PersistRequest extends BeanRequest implements BatchPostExe
return transaction.translate(e.getMessage(), e);
}
/**
* Execute the statement.
*/
int executeStatement() {
return executeStatement(false);
}
int executeStatement(boolean addBatch) {
boolean batch = isBatchThisRequest();
try {
int rows;
BatchControl control = transaction.getBatchControl();
if (control != null) {
rows = control.executeStatementOrBatch(this, batch);
rows = control.executeStatementOrBatch(this, batch, addBatch);
} else if (batch) {
// need to create the BatchControl
control = persistExecute.createBatchControl(transaction);
rows = control.executeStatementOrBatch(this, true);
rows = control.executeStatementOrBatch(this, true, addBatch);
} else {
rows = executeNow();
}
@@ -59,7 +59,7 @@ public final class PersistRequestUpdateSql extends PersistRequest {
*/
public int addBatch() {
this.addBatch = true;
return executeOrQueue();
return executeStatement(true);
}
/**
@@ -138,9 +138,8 @@ public final class BatchControl {
* These all go straight to jdbc and use addBatch(). Entity beans goto a queue
* and wait there so that the jdbc is executed in the correct order according
* to the depth.
* </p>
*/
public int executeStatementOrBatch(PersistRequest request, boolean batch) throws BatchedSqlException {
public int executeStatementOrBatch(PersistRequest request, boolean batch, boolean addBatch) throws BatchedSqlException {
if (!batch || (batchFlushOnMixed && !isBeansEmpty())) {
// flush when mixing beans and updateSql
flush();
@@ -149,7 +148,7 @@ public final class BatchControl {
// execute the request immediately without batching
return request.executeNow();
}
if (pstmtHolder.getMaxSize() >= batchSize) {
if (!addBatch && pstmtHolder.getMaxSize() >= batchSize) {
flush();
}
// for OrmUpdate, SqlUpdate, CallableSql there is no queue...