mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-10-23 16:47:18 +00:00
Merge pull request #1835 from ebean-orm/feature/persistCascadeEscalate
Refactor JDBC batch escalation and detection of deferred persist relationship (circular imported ids)
This commit is contained in:
@@ -283,10 +283,12 @@ public final class PersistRequestBean<T> extends PersistRequest implements BeanP
|
||||
* Check for batch escalation on cascade.
|
||||
*/
|
||||
public void checkBatchEscalationOnCascade() {
|
||||
if (transaction.checkBatchEscalationOnCascade(this)) {
|
||||
// we escalated to use batch mode so flush when done
|
||||
// but if createdTransaction then commit will flush it
|
||||
batchOnCascadeSet = !createdTransaction;
|
||||
if (type == Type.UPDATE || beanDescriptor.isBatchEscalateOnCascade(type)) {
|
||||
if (transaction.checkBatchEscalationOnCascade(this)) {
|
||||
// we escalated to use batch mode so flush when done
|
||||
// but if createdTransaction then commit will flush it
|
||||
batchOnCascadeSet = !createdTransaction;
|
||||
}
|
||||
}
|
||||
persistCascade = transaction.isPersistCascade();
|
||||
}
|
||||
|
||||
@@ -140,6 +140,8 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType {
|
||||
private final short profileBeanId;
|
||||
|
||||
private final boolean multiValueSupported;
|
||||
private boolean batchEscalateOnCascadeInsert;
|
||||
private boolean batchEscalateOnCascadeDelete;
|
||||
|
||||
public enum EntityType {
|
||||
ORM, EMBEDDED, VIEW, SQL, DOC
|
||||
@@ -752,6 +754,24 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean hasCircularImportedId() {
|
||||
for (BeanPropertyAssocOne<?> assocOne : propertiesOneImportedSave) {
|
||||
if (assocOne.hasCircularImportedId(this)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean hasCircularImportedIdTo(BeanDescriptor sourceDesc) {
|
||||
for (BeanPropertyAssocOne<?> assocOne : propertiesOneImportedSave) {
|
||||
if (assocOne.getTargetDescriptor() == sourceDesc) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void registerColumn(String dbColumn, String path) {
|
||||
String key = dbColumn.toLowerCase();
|
||||
// check for clash with imported OneToOne PK
|
||||
@@ -812,6 +832,8 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType {
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
void initialiseDocMapping() {
|
||||
batchEscalateOnCascadeInsert = supportBatchEscalateOnInsert();
|
||||
batchEscalateOnCascadeDelete = supportBatchEscalateOnDelete();
|
||||
for (BeanPropertyAssocMany<?> many : propertiesMany) {
|
||||
many.initialisePostTarget();
|
||||
}
|
||||
@@ -826,6 +848,30 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType {
|
||||
cacheHelp.deriveNotifyFlags();
|
||||
}
|
||||
|
||||
private boolean supportBatchEscalateOnDelete() {
|
||||
if (softDelete) {
|
||||
return false;
|
||||
}
|
||||
for (BeanPropertyAssocMany<?> assocMany : propertiesManyDelete) {
|
||||
if (assocMany.isCascadeDeleteEscalate()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean supportBatchEscalateOnInsert() {
|
||||
return idType == IdType.IDENTITY || !hasCircularImportedId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return false if JDBC batch can't be implicitly escalated to.
|
||||
* This happens when we have circular import id situation (need to defer setting identity value).
|
||||
*/
|
||||
public boolean isBatchEscalateOnCascade(PersistRequest.Type type) {
|
||||
return type == PersistRequest.Type.INSERT ? batchEscalateOnCascadeInsert : batchEscalateOnCascadeDelete;
|
||||
}
|
||||
|
||||
void initInheritInfo() {
|
||||
if (inheritInfo != null) {
|
||||
// need to check every BeanDescriptor in the inheritance hierarchy
|
||||
|
||||
@@ -958,6 +958,10 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> implements ST
|
||||
return cascadeInfo.isDelete() || o2mJoinTable || ModifyListenMode.REMOVALS == modifyListenMode;
|
||||
}
|
||||
|
||||
public boolean isCascadeDeleteEscalate() {
|
||||
return !elementCollection && cascadeInfo.isDelete();
|
||||
}
|
||||
|
||||
public String insertElementCollection() {
|
||||
return sqlHelp.insertElementCollection();
|
||||
}
|
||||
|
||||
@@ -807,4 +807,8 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> implements STr
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasCircularImportedId(BeanDescriptor<?> sourceDesc) {
|
||||
return targetDescriptor.hasCircularImportedIdTo(sourceDesc);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -639,10 +639,6 @@ class JdbcTransaction implements SpiTransaction, TxnProfileEventCodes {
|
||||
*/
|
||||
@Override
|
||||
public boolean isBatchThisRequest() {
|
||||
if (!batchOnCascadeSet && !explicit && depth <= 0) {
|
||||
// implicit transaction, no gain by batching where depth <= 0
|
||||
return false;
|
||||
}
|
||||
return batchMode;
|
||||
}
|
||||
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
@@ -2,10 +2,12 @@ package org.tests.basic.one2one;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.Ebean;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
|
||||
public class TestOne2OneBookingInvoice extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
@@ -25,23 +27,23 @@ public class TestOne2OneBookingInvoice extends BaseTestCase {
|
||||
Ebean.save(b);
|
||||
|
||||
Invoice invoice = Ebean.find(Invoice.class, ai.getId());
|
||||
Assert.assertEquals(b.getId(), invoice.getBooking().getId());
|
||||
assertEquals(b.getId(), invoice.getBooking().getId());
|
||||
|
||||
Booking b1 = Ebean.find(Booking.class, b.getId());
|
||||
|
||||
Invoice ai1 = b1.getAgentInvoice();
|
||||
Assert.assertNotNull(ai1);
|
||||
assertNotNull(ai1);
|
||||
|
||||
Booking b2 = ai1.getBooking();
|
||||
Assert.assertNotNull(b2);
|
||||
Assert.assertEquals(b1.getId(), b2.getId());
|
||||
Assert.assertSame(b1, b2);
|
||||
assertNotNull(b2);
|
||||
assertEquals(b1.getId(), b2.getId());
|
||||
assertSame(b1, b2);
|
||||
|
||||
Invoice ci1 = b1.getClientInvoice();
|
||||
Booking b3 = ci1.getBooking();
|
||||
Assert.assertNotNull(b3);
|
||||
Assert.assertEquals(b1.getId(), b2.getId());
|
||||
Assert.assertSame(b1, b2);
|
||||
assertNotNull(b3);
|
||||
assertEquals(b1.getId(), b2.getId());
|
||||
assertSame(b1, b2);
|
||||
|
||||
// cleanup
|
||||
ai.setBooking(null);
|
||||
@@ -49,7 +51,5 @@ public class TestOne2OneBookingInvoice extends BaseTestCase {
|
||||
Ebean.save(ai);
|
||||
Ebean.save(ci);
|
||||
Ebean.delete(b);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package org.tests.iud;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.OneToMany;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static javax.persistence.CascadeType.ALL;
|
||||
|
||||
@Entity
|
||||
public class PcfCalendar extends PcfModel {
|
||||
|
||||
@OneToMany(cascade = ALL, orphanRemoval = true)
|
||||
private List<PcfEvent> events = new ArrayList<>();
|
||||
|
||||
public void addEvent(PcfEvent event) {
|
||||
events.add(event);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package org.tests.iud;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.OneToOne;
|
||||
|
||||
import static javax.persistence.CascadeType.ALL;
|
||||
|
||||
@Entity
|
||||
public class PcfCity extends PcfModel {
|
||||
|
||||
private final String name;
|
||||
|
||||
@OneToOne(cascade = ALL, optional = false)
|
||||
private PcfPerson mayor;
|
||||
|
||||
@OneToOne(cascade = ALL, optional = false)
|
||||
private PcfPerson viceMayor;
|
||||
|
||||
public PcfCity(String name, PcfPerson mayor, PcfPerson viceMayor) {
|
||||
this.name = name;
|
||||
this.mayor = mayor;
|
||||
this.viceMayor = viceMayor;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.tests.iud;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.OneToMany;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Entity
|
||||
public class PcfCountry extends PcfModel {
|
||||
|
||||
|
||||
@OneToMany(cascade = CascadeType.ALL)
|
||||
private List<PcfCity> cities = new ArrayList<>();
|
||||
|
||||
public void addCity(PcfCity city) {
|
||||
cities.add(city);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.tests.iud;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
|
||||
@Entity
|
||||
public class PcfEvent extends PcfModel {
|
||||
|
||||
final String name;
|
||||
|
||||
public PcfEvent(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package org.tests.iud;
|
||||
|
||||
import io.ebean.Model;
|
||||
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
import javax.persistence.Version;
|
||||
|
||||
@MappedSuperclass
|
||||
public class PcfModel extends Model {
|
||||
|
||||
@Id
|
||||
long id;
|
||||
|
||||
@Version
|
||||
long version;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package org.tests.iud;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.OneToMany;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static javax.persistence.CascadeType.ALL;
|
||||
|
||||
@Entity
|
||||
public class PcfPerson extends PcfModel {
|
||||
|
||||
private final String name;
|
||||
|
||||
@OneToMany(cascade = ALL, orphanRemoval = true)
|
||||
private List<PcfCalendar> calendars = new ArrayList<>();
|
||||
|
||||
public PcfPerson(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void addCalendar(PcfCalendar calendar) {
|
||||
calendars.add(calendar);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package org.tests.iud;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import org.avaje.moduuid.ModUUID;
|
||||
import org.ebeantest.LoggedSqlCollector;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class TestPersistCascade extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void insert() {
|
||||
|
||||
PcfCountry country = new PcfCountry();
|
||||
for (int a = 0; a < 3; a++) {
|
||||
PcfPerson mayor = createPerson();
|
||||
PcfPerson viceMayor = createPerson();
|
||||
country.addCity(new PcfCity("city_" + ModUUID.newShortId(), mayor, viceMayor));
|
||||
}
|
||||
|
||||
LoggedSqlCollector.start();
|
||||
country.save();
|
||||
|
||||
final List<String> sql = LoggedSqlCollector.stop();
|
||||
|
||||
if (isPersistBatchOnCascade()) {
|
||||
assertThat(sql.get(0)).contains("insert into pcf_country");
|
||||
assertThat(sql.get(1)).contains("insert into pcf_person");
|
||||
assertSqlBind(sql, 2, 7);
|
||||
assertThat(sql.get(8)).contains("insert into pcf_calendar");
|
||||
assertSqlBind(sql, 9, 20);
|
||||
assertThat(sql.get(21)).contains("insert into pcf_city");
|
||||
assertSqlBind(sql, 22, 24);
|
||||
assertThat(sql.get(25)).contains("insert into pcf_event");
|
||||
assertSqlBind(sql, 26, 45);
|
||||
assertThat(sql.get(46)).contains("insert into pcf_event");
|
||||
assertSqlBind(sql, 47, 66);
|
||||
assertThat(sql.get(67)).contains("insert into pcf_event");
|
||||
assertSqlBind(sql, 68, 87);
|
||||
}
|
||||
|
||||
country.deletePermanent();
|
||||
}
|
||||
|
||||
private static PcfPerson createPerson() {
|
||||
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++) {
|
||||
calendar.addEvent(new PcfEvent("evt_" + ModUUID.newShortId()));
|
||||
}
|
||||
person.addCalendar(calendar);
|
||||
}
|
||||
return person;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
+3
-3
@@ -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=?");
|
||||
|
||||
+4
-4
@@ -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=?");
|
||||
|
||||
+8
-6
@@ -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=?");
|
||||
|
||||
+5
-4
@@ -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())
|
||||
|
||||
+7
-6
@@ -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=?");
|
||||
|
||||
+9
-7
@@ -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");
|
||||
|
||||
@@ -81,7 +81,7 @@
|
||||
|
||||
<!-- <logger name="io.ebean.SQL" level="TRACE"/>-->
|
||||
<!-- <logger name="io.ebean.TXN" level="TRACE"/>-->
|
||||
<!-- <logger name="io.ebean.SUM" level="TRACE"/> -->
|
||||
<!-- <logger name="io.ebean.SUM" level="TRACE"/>-->
|
||||
|
||||
<!-- <logger name="io.ebean.cache" level="TRACE"/> -->
|
||||
<!-- <logger name="io.ebean.cache.REGION" level="TRACE"/>-->
|
||||
|
||||
Reference in New Issue
Block a user