#1504 - ENH: Add SqlUpdate executeNow() method ... that executes now regardless of transaction batch mode

This commit is contained in:
rob bygrave
2018-10-12 18:49:20 +13:00
parent 82e68d7756
commit b87e360ac7
9 changed files with 90 additions and 6 deletions
@@ -854,6 +854,11 @@ public class TDSpiEbeanServer implements SpiEbeanServer {
return 0;
}
@Override
public int executeNow(SpiSqlUpdate sqlUpdate) {
return 0;
}
@Override
public void addBatch(SpiSqlUpdate sqlUpdate, SpiTransaction transaction) {
@@ -3,6 +3,7 @@ package org.tests.update;
import io.ebean.BaseTestCase;
import io.ebean.Ebean;
import io.ebean.SqlUpdate;
import io.ebean.Transaction;
import io.ebean.meta.MetaTimedMetric;
import org.junit.Assert;
import org.junit.Test;
@@ -38,6 +39,41 @@ public class TestSqlUpdateInTxn extends BaseTestCase {
}
}
@Test
public void testExecute_inTransaction_withBatch() {
try (Transaction transaction = Ebean.beginTransaction()) {
transaction.setBatchMode(true);
int row = Ebean.createSqlUpdate("update audit_log set description = description where id = ?")
.setParameter(1, 999999)
.execute();
// update statement using JDBC batch so not executed yet
assertThat(row).isEqualTo(-1);
transaction.commit();
}
}
@Test
public void testExecuteNow_inTransaction_withBatch() {
try (Transaction transaction = Ebean.beginTransaction()) {
transaction.setBatchMode(true);
int row = Ebean.createSqlUpdate("update audit_log set description = description where id = ?")
.setParameter(1, 999999)
.executeNow();
// update statement executed even though JDBC batch mode is on
assertThat(row).isEqualTo(0);
transaction.commit();
}
}
@Test
public void testSqlUpdateWithWhitespace() {