mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#1644 - ENH: Improve batch flush when multiple "top level" (unrelated) types are persisted
This commit is contained in:
@@ -1,10 +1,19 @@
|
||||
package org.tests.transaction;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import io.ebean.Ebean;
|
||||
import io.ebean.Transaction;
|
||||
import io.ebean.annotation.Transactional;
|
||||
import org.ebeantest.LoggedSqlCollector;
|
||||
import org.junit.Test;
|
||||
import org.tests.model.m2m.MnyB;
|
||||
import org.tests.model.m2m.MnyTopic;
|
||||
import org.tests.model.m2m.Role;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class TestBatchModelFlush extends BaseTestCase {
|
||||
|
||||
@@ -30,4 +39,59 @@ public class TestBatchModelFlush extends BaseTestCase {
|
||||
// the rest is flushed on commit
|
||||
new MnyB("TestBatchModelFlush_5").save();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipleTopLevel_expect_singleFlush() {
|
||||
|
||||
LoggedSqlCollector.start();
|
||||
|
||||
// 2 unrelated "top level" beans being persisted
|
||||
MnyB m0 = new MnyB("BatchMultipleTop_0");
|
||||
MnyB m1 = new MnyB("BatchMultipleTop_1");
|
||||
Role r0 = new Role("Role_0");
|
||||
Role r1 = new Role("Role_1");
|
||||
|
||||
MnyTopic t0 = new MnyTopic("MnyTopic_0");
|
||||
MnyTopic t1 = new MnyTopic("MnyTopic_1");
|
||||
|
||||
try (Transaction transaction = DB.beginTransaction()) {
|
||||
transaction.setBatchMode(true);
|
||||
|
||||
m0.save();
|
||||
DB.save(r0);
|
||||
DB.save(t0);
|
||||
DB.save(t1);
|
||||
|
||||
m1.save();
|
||||
DB.save(r1);
|
||||
|
||||
transaction.commit();
|
||||
}
|
||||
|
||||
List<String> sql = LoggedSqlCollector.stop();
|
||||
|
||||
// DEBUG io.ebean.SUM - txn[1001] BatchControl flush [MnyB:100 i:2, Role:101 i:2, MnyTopic:102 i:2]
|
||||
|
||||
assertThat(sql).hasSize(9);
|
||||
|
||||
// first saved to batch - (depth 100)
|
||||
assertThat(sql.get(0)).contains("insert into mny_b");
|
||||
assertThat(sql.get(1)).contains(" -- bind(BatchMultipleTop_0");
|
||||
assertThat(sql.get(2)).contains(" -- bind(BatchMultipleTop_1");
|
||||
// second saved to batch - (depth 101)
|
||||
assertThat(sql.get(3)).contains("insert into mt_role");
|
||||
assertThat(sql.get(4)).contains(" -- bind(");
|
||||
assertThat(sql.get(5)).contains(" -- bind(");
|
||||
// third saved to batch - (depth 102)
|
||||
assertThat(sql.get(6)).contains("insert into mny_topic");
|
||||
assertThat(sql.get(7)).contains(" -- bind(MnyTopic_0");
|
||||
assertThat(sql.get(8)).contains(" -- bind(MnyTopic_1");
|
||||
|
||||
DB.delete(t0);
|
||||
DB.delete(t1);
|
||||
DB.delete(r0);
|
||||
DB.delete(r1);
|
||||
DB.delete(m0);
|
||||
DB.delete(m1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user