#1835 Refactor JDBC batch escalation

This commit is contained in:
rob bygrave
2019-10-09 00:17:34 +13:00
parent 6621c5dfbb
commit 80a764a448
28 changed files with 179 additions and 153 deletions
+4
View File
@@ -114,6 +114,10 @@ public abstract class BaseTestCase {
return trimSql(query.getGeneratedSql(), columns);
}
protected void assertSqlBind(String sql) {
assertThat(sql).contains("-- bind");
}
protected void assertSqlBind(List<String> sql, int i) {
assertThat(sql.get(i)).contains("-- bind");
}
@@ -48,9 +48,7 @@ public class TestOrderedList extends BaseTestCase {
assertThat(sql).hasSize(1);
assertThat(sql.get(0)).contains("update om_ordered_master set name=?, version=?");
fetchAndReorder(master.getId());
}
private void fetchAndReorder(Long id) {
@@ -96,8 +94,9 @@ public class TestOrderedList extends BaseTestCase {
Ebean.delete(fresh);
sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(2);
assertThat(sql).hasSize(3);
assertThat(sql.get(0)).contains("delete from om_ordered_detail where master_id = ?");
assertThat(sql.get(1)).contains("delete from om_ordered_master where id=? and version=?");
assertSqlBind(sql.get(1));
assertThat(sql.get(2)).contains("delete from om_ordered_master where id=? and version=?");
}
}
@@ -71,8 +71,9 @@ public class TestPrivateOwned extends BaseTestCase {
Ebean.save(m0);
List<String> loggedSql = LoggedSqlCollector.stop();
assertThat(loggedSql).hasSize(1);
assertThat(loggedSql).hasSize(2);
assertThat(loggedSql.get(0)).contains("delete from t_detail_with_other_namexxxyy where id=?");
assertSqlBind(loggedSql.get(1));
TSMaster masterReload = Ebean.find(TSMaster.class, m0.getId());
assertThat(masterReload.getDetails()).hasSize(1);
@@ -79,9 +79,10 @@ public class TestForeignKeyModes extends BaseTestCase {
Ebean.delete(none);
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(2);
assertThat(sql).hasSize(3);
assertThat(sql.get(0)).contains("delete from dfk_none_via_mto_m_dfk_one where dfk_none_via_mto_m_id = ?");
assertThat(sql.get(1)).contains("delete from dfk_none_via_mto_m where id=?");
assertSqlBind(sql.get(1));
assertThat(sql.get(2)).contains("delete from dfk_none_via_mto_m where id=?");
}
@IgnorePlatform(Platform.NUODB)
@@ -27,13 +27,13 @@ public class TestDeleteCascadeWithListener extends BaseTestCase {
Ebean.delete(found);
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(5);
assertThat(sql.get(0)).contains("select t0.id from dc_detail t0 where master_id=?");
assertThat(sql.get(1)).contains("delete from dc_detail where id=?");
assertThat(sql.get(3)).contains("delete from dc_detail where id=?");
assertThat(sql.get(4)).contains("delete from dc_master where id=? and version=?");
if (isPersistBatchOnCascade()) {
assertThat(sql).hasSize(6);
assertThat(sql.get(0)).contains("select t0.id from dc_detail t0 where master_id=?");
assertThat(sql.get(1)).contains("delete from dc_detail where id=?");
assertSqlBind(sql, 2, 4);
assertThat(sql.get(5)).contains("delete from dc_master where id=? and version=?");
}
awaitListenerPropagation();
List<Object> beans = DcListener.deletedBeans();
@@ -1,8 +1,6 @@
package org.tests.iud;
import io.ebean.BaseTestCase;
import io.ebean.DB;
import io.ebean.Transaction;
import org.avaje.moduuid.ModUUID;
import org.junit.Test;
@@ -15,7 +13,7 @@ public class TestPersistCascade extends BaseTestCase {
for (int a = 0; a < 3; a++) {
PcfPerson mayor = createPerson();
PcfPerson viceMayor = createPerson();
country.addCity(new PcfCity("c_" + ModUUID.newShortId(), mayor, viceMayor));
country.addCity(new PcfCity("city_" + ModUUID.newShortId(), mayor, viceMayor));
}
// try (Transaction txn = DB.beginTransaction()) {
// txn.setBatchSize(20);
@@ -32,7 +30,7 @@ public class TestPersistCascade extends BaseTestCase {
}
private static PcfPerson createPerson() {
PcfPerson person = new PcfPerson("per_" + ModUUID.newShortId());
PcfPerson person = new PcfPerson("person_" + ModUUID.newShortId());
for (int a = 0; a < 2; a++) {
PcfCalendar calendar = new PcfCalendar();
for (int b = 0; b < 10; b++) {
@@ -79,7 +79,6 @@ public class TestMergeCustomer extends BaseTestCase {
@Test
public void customerWithAddresses_setClientGeneratedIds_expect_selectAndUpdate() {
MCustomer mCustomer = partial("cust3", "(id,name,version,shippingAddress(*),billingAddress(*))");
mCustomer.setName("NotCust3");
mCustomer.getBillingAddress().setStreet("modBillStreet");
@@ -96,11 +95,11 @@ public class TestMergeCustomer extends BaseTestCase {
server().merge(mCustomer, options);
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(4);
assertThat(sql).hasSize(5);
assertThat(sql.get(0)).contains("select t0.id, t2.id, t1.id from mcustomer t0 left join maddress t2 on t2.id = t0.shipping_address_id left join maddress t1 on t1.id = t0.billing_address_id where t0.id = ?");
assertThat(sql.get(1)).contains("update maddress set street=?, city=?, version=? where id=? and version=?");
assertThat(sql.get(2)).contains("update maddress set street=?, city=?, version=? where id=? and version=?");
assertThat(sql.get(3)).contains("update mcustomer set name=?, version=?, shipping_address_id=?, billing_address_id=? where id=? and version=?");
assertSqlBind(sql, 2, 3);
assertThat(sql.get(4)).contains("update mcustomer set name=?, version=?, shipping_address_id=?, billing_address_id=? where id=? and version=?");
}
@Test
@@ -125,11 +124,13 @@ public class TestMergeCustomer extends BaseTestCase {
server().merge(mCustomer, options);
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(4);
assertThat(sql).hasSize(6);
assertThat(sql.get(0)).contains("select t0.id, t2.id, t1.id from mcustomer t0 left join maddress t2 on t2.id = t0.shipping_address_id left join maddress t1 on t1.id = t0.billing_address_id where t0.id = ?");
assertThat(sql.get(1)).contains("update maddress set street=?, city=?, version=? where id=? and version=?");
assertThat(sql.get(2)).contains("insert into maddress (id, street, city, version) values (?,?,?,?);");
assertThat(sql.get(3)).contains("update mcustomer set name=?, version=?, shipping_address_id=?, billing_address_id=? where id=? and version=?");
assertThat(sql.get(1)).contains("insert into maddress (id, street, city, version) values (?,?,?,?)");
assertSqlBind(sql.get(2));
assertThat(sql.get(3)).contains("update maddress set street=?, city=?, version=? where id=? and version=?");
assertSqlBind(sql.get(4));
assertThat(sql.get(5)).contains("update mcustomer set name=?, version=?, shipping_address_id=?, billing_address_id=? where id=? and version=?");
}
@Test
@@ -156,15 +157,16 @@ public class TestMergeCustomer extends BaseTestCase {
server().merge(mCustomer, options);
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(5);
assertThat(sql).hasSize(7);
assertThat(sql.get(0)).contains("select t0.id, t2.id, t1.id from mcustomer t0 left join maddress t2 on t2.id = t0.shipping_address_id left join maddress t1 on t1.id = t0.billing_address_id where t0.id = ?");
// Additional check to see if the address with the unknown UUID is 'insert' or 'update'
assertThat(sql.get(1)).contains("select t0.id from maddress t0 where t0.id = ?");
assertThat(sql.get(2)).contains("update maddress set street=?, city=?, version=? where id=? and version=?");
assertThat(sql.get(3)).contains("insert into maddress (id, street, city, version) values (?,?,?,?);");
assertThat(sql.get(4)).contains("update mcustomer set name=?, version=?, shipping_address_id=?, billing_address_id=? where id=? and version=?");
assertThat(sql.get(2)).contains("insert into maddress (id, street, city, version) values (?,?,?,?)");
assertSqlBind(sql.get(3));
assertThat(sql.get(4)).contains("update maddress set street=?, city=?, version=? where id=? and version=?");
assertSqlBind(sql.get(5));
assertThat(sql.get(6)).contains("update mcustomer set name=?, version=?, shipping_address_id=?, billing_address_id=? where id=? and version=?");
}
@Test
@@ -212,11 +214,13 @@ public class TestMergeCustomer extends BaseTestCase {
server().merge(mCustomer, options);
List<String> sql = LoggedSqlCollector.stop();
if (isPersistBatchOnCascade()) {
assertThat(sql).hasSize(20);
}
assertThat(sql.get(0)).contains("select t0.id, t1.id from mcustomer t0 left join mcontact t1 on t1.customer_id = t0.id where t0.id = ?");
assertThat(sql.get(1)).contains("delete from mcontact_message where contact_id = ?");
assertThat(sql.get(2)).contains("delete from mcontact where id=?");
assertThat(sql.get(13)).contains("update mcustomer set name=?, version=?, shipping_address_id=?, billing_address_id=? where id=? and version=?");
assertThat(sql.get(3)).contains("delete from mcontact where id=?");
assertThat(sql.get(19)).contains("update mcustomer set name=?, version=?, shipping_address_id=?, billing_address_id=? where id=? and version=?");
}
@@ -236,11 +240,13 @@ public class TestMergeCustomer extends BaseTestCase {
server().merge(mCustomer, options);
List<String> sql = LoggedSqlCollector.stop();
if (isPersistBatchOnCascade()) {
assertThat(sql).hasSize(20);
}
assertThat(sql.get(0)).contains("select t0.id, t1.id from mcustomer t0 left join mcontact t1 on t1.customer_id = t0.id where t0.id = ?");
assertThat(sql.get(1)).contains("delete from mcontact_message where contact_id = ?");
assertThat(sql.get(2)).contains("delete from mcontact where id=?");
assertThat(sql.get(13)).contains("update mcustomer set name=?, version=?, shipping_address_id=?, billing_address_id=? where id=? and version=?");
assertThat(sql.get(3)).contains("delete from mcontact where id=?");
assertThat(sql.get(19)).contains("update mcustomer set name=?, version=?, shipping_address_id=?, billing_address_id=? where id=? and version=?");
}
@Test
@@ -272,15 +278,18 @@ public class TestMergeCustomer extends BaseTestCase {
server().merge(mCustomer, options);
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql.get(0)).contains("select t0.id, t1.id from mcustomer t0 left join mcontact t1 on t1.customer_id = t0.id where t0.id = ?");
assertThat(sql.get(1)).contains("delete from mcontact_message where contact_id = ?");
assertThat(sql.get(2)).contains("delete from mcontact where id=?");
assertThat(sql.get(5)).contains("update mcustomer set name=?, version=?, shipping_address_id=?, billing_address_id=? where id=? and version=?");
if (isPersistBatchOnCascade()) {
assertThat(sql.get(6)).contains("insert into mcontact");
assertThat(sql.get(7)).contains("-- bind(");
assertThat(sql.get(9)).contains("update mcontact set email=?, first_name=?, last_name=?, version=?, customer_id=? where id=? and version=?");
assertThat(sql).hasSize(16);
assertThat(sql.get(0)).contains("select t0.id, t1.id from mcustomer t0 left join mcontact t1 on t1.customer_id = t0.id where t0.id = ?");
assertThat(sql.get(1)).contains("delete from mcontact_message where contact_id = ?");
assertThat(sql.get(3)).contains("delete from mcontact where id=?");
assertThat(sql.get(7)).contains("update mcustomer set name=?, version=?, shipping_address_id=?, billing_address_id=? where id=? and version=?");
}
if (isPersistBatchOnCascade()) {
assertThat(sql.get(8)).contains("insert into mcontact");
assertThat(sql.get(9)).contains("-- bind(");
assertThat(sql.get(11)).contains("update mcontact set email=?, first_name=?, last_name=?, version=?, customer_id=? where id=? and version=?");
} else {
assertThat(sql.get(6)).contains("update mcontact set email=?, first_name=?, last_name=?, version=?, customer_id=? where id=? and version=?");
assertThat(sql.get(7)).contains("update mcontact set email=?, first_name=?, last_name=?, version=?, customer_id=? where id=? and version=?");
@@ -305,35 +314,28 @@ public class TestMergeCustomer extends BaseTestCase {
.setDeletePermanent()
.build();
LoggedSqlCollector.start();
server().merge(cust1, options);
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql.get(0)).contains("select t0.id, t3.id, t1.id, t2.id from mcustomer t0 left join maddress t3 on t3.id = t0.shipping_address_id left join maddress t1 on t1.id = t0.billing_address_id left join mcontact t2 on t2.customer_id = t0.id where t0.id = ?");
if (isH2() || isHana()) {
// with nested OneToMany .. we need a second query to read the contact message ids
assertThat(sql.get(1)).contains("select t0.contact_id, t0.id from mcontact_message t0 where (t0.contact_id) in (?,?,?,?,?,?,?,?,?,?)");
}
assertThat(sql.get(2)).contains("delete from mcontact_message where contact_id = ?");
assertThat(sql.get(3)).contains("delete from mcontact where id=?");
assertThat(sql.get(4)).contains("delete from mcontact_message where contact_id = ?");
assertThat(sql.get(5)).contains("delete from mcontact where id=?");
assertThat(sql.get(6)).contains("update maddress set street=?, city=?, version=? where id=? and version=?");
assertThat(sql.get(7)).contains("update mcustomer set name=?, notes=?, version=?, shipping_address_id=?, billing_address_id=? where id=? and version=?");
if (isPersistBatchOnCascade()) {
assertThat(sql.get(8)).contains("insert into mcontact");
assertThat(sql.get(10)).contains("update mcontact set email=?, first_name=?, last_name=?, version=?, customer_id=? where id=? and version=?");
assertThat(sql.get(15)).contains("update mcontact_message set title=?, subject=?, notes=?, version=?, contact_id=? where id=? and version=?");
} else {
assertThat(sql.get(8)).contains("update mcontact set email=?, first_name=?, last_name=?, version=?, customer_id=? where id=? and version=?");
assertThat(sql.get(9)).contains("update mcontact_message set title=?, subject=?, notes=?, version=?, contact_id=? where id=? and version=?");
assertThat(sql.get(sql.size()-1)).contains("insert into mcontact");
assertThat(sql.get(0)).contains("select t0.id, t3.id, t1.id, t2.id from mcustomer t0 left join maddress t3 on t3.id = t0.shipping_address_id left join maddress t1 on t1.id = t0.billing_address_id left join mcontact t2 on t2.customer_id = t0.id where t0.id = ?");
if (isH2() || isHana()) {
// with nested OneToMany .. we need a second query to read the contact message ids
assertThat(sql.get(1)).contains("select t0.contact_id, t0.id from mcontact_message t0 where (t0.contact_id) in (?,?,?,?,?,?,?,?,?,?)");
}
assertThat(sql.get(2)).contains("delete from mcontact_message where contact_id = ?");
assertThat(sql.get(4)).contains("delete from mcontact where id=?");
assertThat(sql.get(5)).contains("delete from mcontact_message where contact_id = ?");
assertThat(sql.get(7)).contains("delete from mcontact where id=?");
assertThat(sql.get(8)).contains("update maddress set street=?, city=?, version=? where id=? and version=?");
assertThat(sql.get(13)).contains("update mcontact set email=?, first_name=?, last_name=?, version=?, customer_id=? where id=? and version=?");
assertSqlBind(sql, 14, 17);
assertThat(sql.get(18)).contains("update mcontact_message set title=?, subject=?, notes=?, version=?, contact_id=? where id=? and version=?");
assertSqlBind(sql, 19, 22);
}
}
private void modify(MCustomer cust) {
@@ -131,11 +131,12 @@ public class TestElementCollectionBasic extends BaseTestCase {
List<String> sql = LoggedSqlCollector.current();
if (isPersistBatchOnCascade()) {
assertThat(sql).hasSize(6);
assertThat(sql).hasSize(7);
assertThat(sql.get(0)).contains("update ec_person set name=?, version=? where id=? and version=?");
assertThat(sql.get(1)).contains("delete from ec_person_phone where owner_id=?");
assertThat(sql.get(2)).contains("insert into ec_person_phone (owner_id,phone) values (?,?)");
assertSqlBind(sql, 3, 5);
assertSqlBind(sql.get(2));
assertThat(sql.get(3)).contains("insert into ec_person_phone (owner_id,phone) values (?,?)");
assertSqlBind(sql, 4, 6);
} else {
assertThat(sql).hasSize(5);
@@ -214,10 +215,11 @@ public class TestElementCollectionBasic extends BaseTestCase {
List<String> sql = LoggedSqlCollector.current();
if (isPersistBatchOnCascade()) {
assertThat(sql).hasSize(8);
assertThat(sql).hasSize(9);
assertThat(sql.get(0)).contains("delete from ec_person_phone where owner_id=?");
assertThat(sql.get(1)).contains("insert into ec_person_phone (owner_id,phone) values (?,?)");
assertSqlBind(sql, 2, 7);
assertSqlBind(sql.get(1));
assertThat(sql.get(2)).contains("insert into ec_person_phone (owner_id,phone) values (?,?)");
assertSqlBind(sql, 3, 8);
} else {
assertThat(sql).hasSize(7);
@@ -43,8 +43,8 @@ public class TestElementCollectionBasicCache extends BaseTestCase {
sql = LoggedSqlCollector.current();
if (isPersistBatchOnCascade()) {
assertThat(sql).hasSize(6);
assertSqlBind(sql, 3, 5);
assertThat(sql).hasSize(7);
assertSqlBind(sql, 4, 6);
} else {
assertThat(sql).hasSize(5);
}
@@ -69,7 +69,7 @@ public class TestElementCollectionBasicCache extends BaseTestCase {
sql = LoggedSqlCollector.current();
if (isPersistBatchOnCascade()) {
assertThat(sql).hasSize(6); // cache hit
assertThat(sql).hasSize(7); // cache hit
} else {
assertThat(sql).hasSize(5); // cache hit
}
@@ -105,11 +105,12 @@ public class TestElementCollectionBasicMap extends BaseTestCase {
List<String> sql = LoggedSqlCollector.current();
if (isPersistBatchOnCascade()) {
assertThat(sql).hasSize(6);
assertThat(sql).hasSize(7);
assertThat(sql.get(0)).contains("update ecm_person set name=?, version=? where id=? and version=?");
assertThat(sql.get(1)).contains("delete from ecm_person_phone_numbers where ecm_person_id=?");
assertThat(sql.get(2)).contains("insert into ecm_person_phone_numbers (ecm_person_id,type,number) values (?,?,?)");
assertSqlBind(sql, 3, 5);
assertSqlBind(sql.get(2));
assertThat(sql.get(3)).contains("insert into ecm_person_phone_numbers (ecm_person_id,type,number) values (?,?,?)");
assertSqlBind(sql, 4, 6);
} else {
assertThat(sql).hasSize(5);
assertThat(sql.get(0)).contains("update ecm_person set name=?, version=? where id=? and version=?");
@@ -139,10 +140,11 @@ public class TestElementCollectionBasicMap extends BaseTestCase {
List<String> sql = LoggedSqlCollector.current();
if (isPersistBatchOnCascade()) {
assertThat(sql).hasSize(6);
assertThat(sql).hasSize(7);
assertThat(sql.get(0)).contains("delete from ecm_person_phone_numbers where ecm_person_id=?");
assertThat(sql.get(1)).contains("insert into ecm_person_phone_numbers (ecm_person_id,type,number) values (?,?,?)");
assertSqlBind(sql, 2, 5);
assertSqlBind(sql.get(1));
assertThat(sql.get(2)).contains("insert into ecm_person_phone_numbers (ecm_person_id,type,number) values (?,?,?)");
assertSqlBind(sql, 3, 6);
} else {
assertThat(sql).hasSize(5);
assertThat(sql.get(0)).contains("delete from ecm_person_phone_numbers where ecm_person_id=?");
@@ -45,8 +45,8 @@ public class TestElementCollectionBasicMapCache extends BaseTestCase {
sql = LoggedSqlCollector.current();
if (isPersistBatchOnCascade()) {
assertThat(sql).hasSize(6);
assertSqlBind(sql, 3, 5);
assertThat(sql).hasSize(7);
assertSqlBind(sql, 4, 6);
} else {
assertThat(sql).hasSize(5);
}
@@ -73,8 +73,8 @@ public class TestElementCollectionBasicMapCache extends BaseTestCase {
sql = LoggedSqlCollector.current();
if (isPersistBatchOnCascade()) {
assertThat(sql).hasSize(4); // cache hit
assertSqlBind(sql, 2, 3);
assertThat(sql).hasSize(5); // cache hit
assertSqlBind(sql, 3, 4);
} else {
assertThat(sql).hasSize(3); // cache hit
}
@@ -103,11 +103,12 @@ public class TestElementCollectionBasicSet extends BaseTestCase {
List<String> sql = LoggedSqlCollector.current();
if (isPersistBatchOnCascade()) {
assertThat(sql).hasSize(6);
assertThat(sql).hasSize(7);
assertThat(sql.get(0)).contains("update ecs_person set name=?, version=? where id=? and version=?");
assertThat(sql.get(1)).contains("delete from ecs_person_phone where ecs_person_id=?");
assertThat(sql.get(2)).contains("insert into ecs_person_phone (ecs_person_id,phone) values (?,?)");
assertSqlBind(sql, 3, 5);
assertSqlBind(sql.get(2));
assertThat(sql.get(3)).contains("insert into ecs_person_phone (ecs_person_id,phone) values (?,?)");
assertSqlBind(sql, 4, 6);
} else {
assertThat(sql).hasSize(5);
assertThat(sql.get(0)).contains("update ecs_person set name=?, version=? where id=? and version=?");
@@ -137,10 +138,11 @@ public class TestElementCollectionBasicSet extends BaseTestCase {
List<String> sql = LoggedSqlCollector.current();
if (isPersistBatchOnCascade()) {
assertThat(sql).hasSize(6);
assertThat(sql).hasSize(7);
assertThat(sql.get(0)).contains("delete from ecs_person_phone where ecs_person_id=?");
assertThat(sql.get(1)).contains("insert into ecs_person_phone (ecs_person_id,phone) values (?,?)");
assertSqlBind(sql, 2, 5);
assertSqlBind(sql.get(1));
assertThat(sql.get(2)).contains("insert into ecs_person_phone (ecs_person_id,phone) values (?,?)");
assertSqlBind(sql, 3, 6);
} else {
assertThat(sql).hasSize(5);
assertThat(sql.get(0)).contains("delete from ecs_person_phone where ecs_person_id=?");
@@ -103,11 +103,12 @@ public class TestElementCollectionEmbeddedList extends BaseTestCase {
List<String> sql = LoggedSqlCollector.current();
if (isPersistBatchOnCascade()) {
assertThat(sql).hasSize(6);
assertThat(sql).hasSize(7);
assertThat(sql.get(0)).contains("update ecbl_person set name=?, version=? where id=? and version=?");
assertThat(sql.get(1)).contains("delete from ecbl_person_phone_numbers where person_id=?");
assertThat(sql.get(2)).contains("insert into ecbl_person_phone_numbers (person_id,country_code,area,number) values (?,?,?,?)");
assertSqlBind(sql, 3, 5);
assertSqlBind(sql.get(2));
assertThat(sql.get(3)).contains("insert into ecbl_person_phone_numbers (person_id,country_code,area,number) values (?,?,?,?)");
assertSqlBind(sql, 4, 6);
} else {
assertThat(sql).hasSize(5);
assertThat(sql.get(0)).contains("update ecbl_person set name=?, version=? where id=? and version=?");
@@ -137,10 +138,11 @@ public class TestElementCollectionEmbeddedList extends BaseTestCase {
List<String> sql = LoggedSqlCollector.current();
if (isPersistBatchOnCascade()) {
assertThat(sql).hasSize(6);
assertThat(sql).hasSize(7);
assertThat(sql.get(0)).contains("delete from ecbl_person_phone_numbers where person_id=?");
assertThat(sql.get(1)).contains("insert into ecbl_person_phone_numbers (person_id,country_code,area,number) values (?,?,?,?)");
assertSqlBind(sql, 2, 5);
assertSqlBind(sql.get(1));
assertThat(sql.get(2)).contains("insert into ecbl_person_phone_numbers (person_id,country_code,area,number) values (?,?,?,?)");
assertSqlBind(sql, 3, 6);
} else {
assertThat(sql).hasSize(5);
assertThat(sql.get(0)).contains("delete from ecbl_person_phone_numbers where person_id=?");
@@ -48,10 +48,11 @@ public class TestElementCollectionEmbeddedListCache extends BaseTestCase {
sql = LoggedSqlCollector.current();
if (isPersistBatchOnCascade()) {
assertThat(sql).hasSize(4); // update of collection only
assertThat(sql).hasSize(5); // update of collection only
assertThat(sql.get(0)).contains("delete from ecbl_person_phone_numbers where person_id=?");
assertThat(sql.get(1)).contains("insert into ecbl_person_phone_numbers (person_id,country_code,area,number) values (?,?,?,?)");
assertSqlBind(sql, 2, 3);
assertSqlBind(sql.get(1));
assertThat(sql.get(2)).contains("insert into ecbl_person_phone_numbers (person_id,country_code,area,number) values (?,?,?,?)");
assertSqlBind(sql, 3, 4);
} else {
assertThat(sql).hasSize(3); // update of collection only
assertThat(sql.get(0)).contains("delete from ecbl_person_phone_numbers where person_id=?");
@@ -76,7 +77,7 @@ public class TestElementCollectionEmbeddedListCache extends BaseTestCase {
Ebean.save(three);
sql = LoggedSqlCollector.current();
assertThat(sql).hasSize(4);
assertThat(sql).hasSize(5);
EcblPerson four = Ebean.find(EcblPerson.class)
.setId(person.getId())
@@ -96,11 +96,11 @@ public class TestElementCollectionEmbeddedMap extends BaseTestCase {
List<String> sql = LoggedSqlCollector.current();
if (isPersistBatchOnCascade()) {
assertThat(sql).hasSize(6);
assertThat(sql).hasSize(7);
assertThat(sql.get(0)).contains("update ecbm_person set name=?, version=? where id=? and version=?");
assertThat(sql.get(1)).contains("delete from ecbm_person_phone_numbers where person_id=?");
assertThat(sql.get(2)).contains("insert into ecbm_person_phone_numbers (person_id,mkey,country_code,area,number)");
assertSqlBind(sql, 3, 5);
assertThat(sql.get(3)).contains("insert into ecbm_person_phone_numbers (person_id,mkey,country_code,area,number)");
assertSqlBind(sql, 4, 6);
} else {
assertThat(sql).hasSize(5);
assertThat(sql.get(0)).contains("update ecbm_person set name=?, version=? where id=? and version=?");
@@ -130,10 +130,11 @@ public class TestElementCollectionEmbeddedMap extends BaseTestCase {
List<String> sql = LoggedSqlCollector.current();
if (isPersistBatchOnCascade()) {
assertThat(sql).hasSize(6);
assertThat(sql).hasSize(7);
assertThat(sql.get(0)).contains("delete from ecbm_person_phone_numbers where person_id=?");
assertThat(sql.get(1)).contains("insert into ecbm_person_phone_numbers (person_id,mkey,country_code,area,number) values (?,?,?,?,?)");
assertSqlBind(sql, 2, 5);
assertSqlBind(sql.get(1));
assertThat(sql.get(2)).contains("insert into ecbm_person_phone_numbers (person_id,mkey,country_code,area,number) values (?,?,?,?,?)");
assertSqlBind(sql, 3, 6);
} else {
assertThat(sql).hasSize(5);
assertThat(sql.get(0)).contains("delete from ecbm_person_phone_numbers where person_id=?");
@@ -49,15 +49,17 @@ public class TestElementCollectionEmbeddedMapCache extends BaseTestCase {
sql = LoggedSqlCollector.current();
if (isPersistBatchOnCascade()) {
assertThat(sql).hasSize(5); // update of collection only
assertThat(sql.get(0)).contains("delete from ecbm_person_phone_numbers where person_id=?");
assertSqlBind(sql.get(1));
assertThat(sql.get(2)).contains("insert into ecbm_person_phone_numbers (person_id,mkey,country_code,area,number) values (?,?,?,?,?)");
assertSqlBind(sql, 3, 4);
} else {
assertThat(sql).hasSize(4); // update of collection only
assertThat(sql.get(0)).contains("delete from ecbm_person_phone_numbers where person_id=?");
assertThat(sql.get(1)).contains("insert into ecbm_person_phone_numbers (person_id,mkey,country_code,area,number) values (?,?,?,?,?)");
assertSqlBind(sql, 2, 3);
} else {
assertThat(sql).hasSize(3); // update of collection only
assertThat(sql.get(0)).contains("delete from ecbm_person_phone_numbers where person_id=?");
assertThat(sql.get(1)).contains("insert into ecbm_person_phone_numbers (person_id,mkey,country_code,area,number) values (?,?,?,?,?)");
assertSqlBind(sql.get(1));
assertThat(sql.get(2)).contains("insert into ecbm_person_phone_numbers (person_id,mkey,country_code,area,number) values (?,?,?,?,?)");
assertThat(sql.get(3)).contains("insert into ecbm_person_phone_numbers (person_id,mkey,country_code,area,number) values (?,?,?,?,?)");
}
EcbmPerson three = Ebean.find(EcbmPerson.class)
@@ -77,7 +79,7 @@ public class TestElementCollectionEmbeddedMapCache extends BaseTestCase {
Ebean.save(three);
sql = LoggedSqlCollector.current();
assertThat(sql).hasSize(4);
assertThat(sql).hasSize(5);
EcbmPerson four = Ebean.find(EcbmPerson.class)
.setId(person.getId())
@@ -34,19 +34,21 @@ public class TestOneToOneOrphanRemove extends BaseTestCase {
Ebean.save(jack);
List<String> sql = LoggedSqlCollector.current();
assertThat(sql).hasSize(4);
assertThat(sql).hasSize(5);
assertThat(sql.get(0)).contains("delete from oto_cust_address where aid=? and version=?");
assertThat(sql.get(1)).contains("update oto_cust set version=? where cid=? and version=?");
assertThat(sql.get(2)).contains("insert into oto_cust_address ");
assertThat(sql.get(3)).contains("-- bind(other1");
assertSqlBind(sql.get(1));
assertThat(sql.get(2)).contains("update oto_cust set version=? where cid=? and version=?");
assertThat(sql.get(3)).contains("insert into oto_cust_address ");
assertThat(sql.get(4)).contains("-- bind(other1");
jack.setAddress(null);
Ebean.save(jack);
sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(2);
assertThat(sql).hasSize(3);
assertThat(sql.get(0)).contains("delete from oto_cust_address where aid=? and version=?");
assertThat(sql.get(1)).contains("update oto_cust set version=? where cid=? and version=?");
assertSqlBind(sql.get(1));
assertThat(sql.get(2)).contains("update oto_cust set version=? where cid=? and version=?");
OtoCustAddress foundAddress = Ebean.find(OtoCustAddress.class, address2.getAid());
assertThat(foundAddress).isNull();
@@ -25,9 +25,10 @@ public class TestOneToOneOrphanStringId extends BaseTestCase {
Ebean.save(b);
List<String> update = LoggedSqlCollector.current();
assertThat(update).hasSize(2);
assertThat(update).hasSize(3);
assertThat(update.get(0)).contains("insert into oto_aone");
assertThat(update.get(1)).contains("update oto_atwo set aone_id=? where id=?");
assertSqlBind(update.get(1));
assertThat(update.get(2)).contains("update oto_atwo set aone_id=? where id=?");
Ebean.delete(b);
@@ -50,9 +51,10 @@ public class TestOneToOneOrphanStringId extends BaseTestCase {
Ebean.save(b);
List<String> inserts = LoggedSqlCollector.current();
assertThat(inserts).hasSize(2);
assertThat(inserts).hasSize(3);
assertThat(inserts.get(0)).contains("insert into oto_aone");
assertThat(inserts.get(1)).contains("insert into oto_atwo");
assertSqlBind(inserts.get(1));
assertThat(inserts.get(2)).contains("insert into oto_atwo");
Ebean.delete(b);
@@ -80,10 +82,12 @@ public class TestOneToOneOrphanStringId extends BaseTestCase {
Ebean.save(b);
List<String> sql = LoggedSqlCollector.current();
assertThat(sql).hasSize(3);
assertThat(sql).hasSize(5);
assertThat(sql.get(0)).contains("insert into oto_aone");
assertThat(sql.get(1)).contains("update oto_atwo set aone_id=? where id=?");
assertThat(sql.get(2)).contains("delete from oto_aone where id=?");
assertSqlBind(sql.get(1));
assertThat(sql.get(2)).contains("update oto_atwo set aone_id=? where id=?");
assertThat(sql.get(3)).contains("delete from oto_aone where id=?");
assertSqlBind(sql.get(4));
Ebean.delete(b);
@@ -91,7 +95,6 @@ public class TestOneToOneOrphanStringId extends BaseTestCase {
assertThat(deletes).hasSize(2);
assertThat(deletes.get(0)).contains("delete from oto_atwo");
assertThat(deletes.get(1)).contains("delete from oto_aone");
}
}
@@ -12,7 +12,6 @@ import static org.assertj.core.api.Assertions.assertThat;
public class TestOneToOnePrimaryKeyJoin extends BaseTestCase {
private OtoPrime insert(String desc) {
OtoPrime prime = new OtoPrime("p" + desc);
OtoPrimeExtra extra = new OtoPrimeExtra("e" + desc);
@@ -50,7 +49,6 @@ public class TestOneToOnePrimaryKeyJoin extends BaseTestCase {
assertThat(sqlOf(queryWithFetch, 10)).contains("select t0.pid, t0.name, t0.version, t1.eid, t1.extra, t1.version from oto_prime t0 join oto_prime_extra t1 on t1.eid = t0.pid where t0.pid = ?")
.as("we join to oto_prime_extra");
assertThat(oneWith.getExtra().getExtra()).isEqualTo("e" + desc);
thenUpdate(oneWith);
@@ -72,7 +70,6 @@ public class TestOneToOnePrimaryKeyJoin extends BaseTestCase {
private void thenDelete(OtoPrime found) {
OtoPrime bean = Ebean.find(OtoPrime.class, found.getPid());
LoggedSqlCollector.start();
@@ -82,6 +79,5 @@ public class TestOneToOnePrimaryKeyJoin extends BaseTestCase {
assertThat(sql).hasSize(2);
assertThat(sql.get(0)).contains("delete from oto_prime_extra where");
assertThat(sql.get(1)).contains("delete from oto_prime where");
}
}
@@ -12,7 +12,6 @@ import static org.assertj.core.api.Assertions.assertThat;
public class TestOneToOnePrimaryKeyJoinBidi extends BaseTestCase {
private OtoUBPrime insert(String desc) {
OtoUBPrime prime = new OtoUBPrime("u" + desc);
OtoUBPrimeExtra extra = new OtoUBPrimeExtra("v" + desc);
@@ -29,7 +28,6 @@ public class TestOneToOnePrimaryKeyJoinBidi extends BaseTestCase {
assertThat(p1.getExtra().getEid()).isEqualTo(p1.getPid()).as("Same id values");
Query<OtoUBPrime> query = Ebean.find(OtoUBPrime.class).setId(p1.getPid());
OtoUBPrime found = query.findOne();
@@ -50,7 +48,6 @@ public class TestOneToOnePrimaryKeyJoinBidi extends BaseTestCase {
assertThat(sqlOf(queryWithFetch, 10)).contains("select t0.pid, t0.name, t0.version, t1.eid, t1.extra, t1.version, t1.eid from oto_ubprime t0 left join oto_ubprime_extra t1 on t1.eid = t0.pid where t0.pid = ?")
.as("we join to oto_prime_extra");
assertThat(oneWith.getExtra().getExtra()).isEqualTo("v" + desc);
thenUpdate(oneWith);
@@ -72,7 +69,6 @@ public class TestOneToOnePrimaryKeyJoinBidi extends BaseTestCase {
private void thenDelete(OtoUBPrime found) {
OtoUBPrime bean = Ebean.find(OtoUBPrime.class, found.getPid());
LoggedSqlCollector.start();
@@ -82,6 +78,5 @@ public class TestOneToOnePrimaryKeyJoinBidi extends BaseTestCase {
assertThat(sql).hasSize(2);
assertThat(sql.get(0)).contains("delete from oto_ubprime_extra where");
assertThat(sql.get(1)).contains("delete from oto_ubprime where");
}
}
@@ -101,6 +101,5 @@ public class TestOneToOnePrimaryKeyJoinOptional extends BaseTestCase {
assertThat(sql).hasSize(2);
assertThat(sql.get(0)).contains("delete from oto_uprime_extra where");
assertThat(sql.get(1)).contains("delete from oto_uprime where");
}
}
@@ -30,8 +30,9 @@ public class TestOrphanRemoveO2M extends BaseTestCase {
assertThat(Ebean.find(OrpDetail.class, "d1")).isNull();
assertThat(Ebean.find(OrpDetail.class, "d2")).isNull();
assertThat(sql).hasSize(2);
assertThat(sql).hasSize(3);
assertThat(sql.get(0)).contains("delete from orp_detail where id=?");
assertSqlBind(sql, 1, 2);
}
@Test
@@ -40,7 +40,7 @@ public class TestSoftDeleteStatelessUpdate extends BaseTestCase {
DB.update(upd);
List<String> sql = LoggedSql.collect();
assertThat(sql).hasSize(5);
assertThat(sql).hasSize(6);
assertThat(sql.get(0)).contains("update esd_master set name=? where id=?");
if (isPlatformBooleanNative()) {
assertThat(sql.get(1)).contains("update esd_detail set deleted=true where master_id = ? and not");