mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#1504 - ENH: Add SqlUpdate executeNow() method ... that executes now regardless of transaction batch mode
This commit is contained in:
@@ -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() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user