Refactor tests using assertSql() helper method

This helper method trims column alias from the sql (for Oracle)
This commit is contained in:
rob bygrave
2020-02-20 15:08:43 +13:00
parent 78b9066345
commit de42655bbd
123 changed files with 767 additions and 743 deletions
+15 -3
View File
@@ -17,6 +17,7 @@ import io.ebeaninternal.server.deploy.BeanDescriptor;
import io.ebeaninternal.server.expression.platform.DbExpressionHandler;
import io.ebeaninternal.server.expression.platform.DbExpressionHandlerFactory;
import io.ebeaninternal.server.transaction.TransactionScopeManager;
import org.assertj.core.api.AbstractCharSequenceAssert;
import org.junit.After;
import org.junit.Rule;
import org.junit.rules.TestName;
@@ -133,13 +134,24 @@ public abstract class BaseTestCase {
}
}
protected String trimSql(String sql) {
protected AbstractCharSequenceAssert<?, String> assertSql(Query<?> query, int count) {
return org.assertj.core.api.Assertions.assertThat(sqlOf(query, count));
}
if (sql.contains(" c1,")) {
protected AbstractCharSequenceAssert<?, String> assertSql(Query<?> query) {
return org.assertj.core.api.Assertions.assertThat(sqlOf(query));
}
protected AbstractCharSequenceAssert<?, String> assertSql(String sql) {
return org.assertj.core.api.Assertions.assertThat(trimSql(sql));
}
protected String trimSql(String sql) {
if (sql.contains(" c0,") || sql.contains(" c0 ") || sql.contains(" c1,") || sql.contains(" c1 ")) {
// for oracle we include column alias so lets remove those
return trimSql(sql, 10);
}
return trimSql(sql, 0);
return sql;//trimSql(sql, 0);
}
/**
+10 -10
View File
@@ -88,7 +88,7 @@ public class DtoQueryFromOrmTest extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(1);
assertThat(sql.get(0)).contains("select t0.id, t0.email, concat(t0.last_name, ISO_WEEK(?)) lastName from contact");
assertSql(sql.get(0)).contains("select t0.id, t0.email, concat(t0.last_name, ISO_WEEK(?)) lastName from contact");
}
// @ForPlatform(Platform.H2)
@@ -110,7 +110,7 @@ public class DtoQueryFromOrmTest extends BaseTestCase {
//
// List<String> sql = LoggedSqlCollector.stop();
// assertThat(sql).hasSize(2);
// assertThat(sql.get(0)).contains("select t0.id, t0.email, concat(t0.last_name, ISO_WEEK(?)) lastName from contact");
// assertSql(sql.get(0)).contains("select t0.id, t0.email, concat(t0.last_name, ISO_WEEK(?)) lastName from contact");
// }
@Test
@@ -136,7 +136,7 @@ public class DtoQueryFromOrmTest extends BaseTestCase {
}
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql.get(0)).contains("select t0.id, t0.email, " + concat("t0.last_name", ", ", "t0.first_name")
assertSql(sql.get(0)).contains("select t0.id, t0.email, " + concat("t0.last_name", ", ", "t0.first_name")
+ " fullName from contact t0 where t0.email is not null and t0.last_name is not null order by t0.last_name");
}
@@ -161,7 +161,7 @@ public class DtoQueryFromOrmTest extends BaseTestCase {
}
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql.get(0)).contains("select t0.email, " + concat("t0.last_name", ", ", "t0.first_name")
assertSql(sql.get(0)).contains("select t0.email, " + concat("t0.last_name", ", ", "t0.first_name")
+ " fullName from contact t0 where t0.email is not null and t0.last_name is not null order by t0.last_name");
}
@@ -186,11 +186,11 @@ public class DtoQueryFromOrmTest extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
if (isSqlServer()) {
assertThat(sql.get(0)).contains("select top 10 t0.email, " + concat("t0.last_name", ", ", "t0.first_name")
assertSql(sql.get(0)).contains("select top 10 t0.email, " + concat("t0.last_name", ", ", "t0.first_name")
+ " fullName from contact t0 where t0.email is not null and t0.last_name is not null order by t0.last_name");
} else {
assertThat(sql.get(0)).contains("select t0.email, " + concat("t0.last_name", ", ", "t0.first_name")
assertSql(sql.get(0)).contains("select t0.email, " + concat("t0.last_name", ", ", "t0.first_name")
+ " fullName from contact t0 where t0.email is not null and t0.last_name is not null order by t0.last_name");
}
}
@@ -216,11 +216,11 @@ public class DtoQueryFromOrmTest extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
if (isSqlServer()) {
assertThat(sql.get(0)).contains("select top 10 t0.id, t0.email, "
assertSql(sql.get(0)).contains("select top 10 t0.id, t0.email, "
+ concat("t0.last_name", ", ", "t0.first_name")
+ " fullName from contact t0 where t0.email is not null and t0.last_name is not null order by t0.last_name");
} else {
assertThat(sql.get(0)).contains("select t0.id, t0.email, " + concat("t0.last_name", ", ", "t0.first_name")
assertSql(sql.get(0)).contains("select t0.id, t0.email, " + concat("t0.last_name", ", ", "t0.first_name")
+ " fullName from contact t0 where t0.email is not null and t0.last_name is not null order by t0.last_name");
}
}
@@ -245,7 +245,7 @@ public class DtoQueryFromOrmTest extends BaseTestCase {
}
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql.get(0)).contains("select " + concat("t0.last_name", ", ", "t0.first_name") + " fullName from contact t0 where");
assertSql(sql.get(0)).contains("select " + concat("t0.last_name", ", ", "t0.first_name") + " fullName from contact t0 where");
}
@Test
@@ -267,7 +267,7 @@ public class DtoQueryFromOrmTest extends BaseTestCase {
}
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql.get(0)).contains("select t0.last_name, count(*) totalCount from contact t0 where t0.last_name is not null group by t0.last_name having count(*) > ?");
assertSql(sql.get(0)).contains("select t0.last_name, count(*) totalCount from contact t0 where t0.last_name is not null group by t0.last_name having count(*) > ?");
}
@Test
+2 -2
View File
@@ -58,7 +58,7 @@ public class DtoQueryTest extends BaseTestCase {
.findEach(it -> log.info("got " + it.getId() + " " + it.getName()));
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql.get(0)).contains("select id, name from o_customer where id > ?");
assertSql(sql.get(0)).contains("select id, name from o_customer where id > ?");
}
@Test
@@ -75,7 +75,7 @@ public class DtoQueryTest extends BaseTestCase {
});
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql.get(0)).contains("select id, name from o_customer where id > ?");
assertSql(sql.get(0)).contains("select id, name from o_customer where id > ?");
}
@Test
+32 -32
View File
@@ -24,12 +24,12 @@ public class EbeanServer_eqlTest extends BaseTestCase {
query.findList();
if (isSqlServer()) {
assertThat(query.getGeneratedSql()).startsWith("select top 100 ");
assertThat(query.getGeneratedSql()).endsWith("order by t0.id");
assertSql(query).startsWith("select top 100 ");
assertSql(query).endsWith("order by t0.id");
} else if (isOracle()) {
assertThat(query.getGeneratedSql()).contains("where rownum <= 100");
assertSql(query).contains("where rownum <= 100");
} else {
assertThat(query.getGeneratedSql()).endsWith("order by t0.id limit 100");
assertSql(query).endsWith("order by t0.id limit 100");
}
}
@@ -42,12 +42,12 @@ public class EbeanServer_eqlTest extends BaseTestCase {
query.findList();
if (isSqlServer()) {
assertThat(query.getGeneratedSql()).startsWith("select top 10 ");
assertThat(query.getGeneratedSql()).endsWith("order by t0.id");
assertSql(query).startsWith("select top 10 ");
assertSql(query).endsWith("order by t0.id");
} else if (isOracle()) {
assertThat(query.getGeneratedSql()).contains("where rownum <= 10");
assertSql(query).contains("where rownum <= 10");
} else {
assertThat(query.getGeneratedSql()).endsWith("order by t0.id limit 10");
assertSql(query).endsWith("order by t0.id limit 10");
}
}
@@ -60,12 +60,12 @@ public class EbeanServer_eqlTest extends BaseTestCase {
query.findList();
if (isSqlServer()) {
assertThat(query.getGeneratedSql()).endsWith("order by t0.id offset 3 rows fetch next 10 rows only");
assertSql(query).endsWith("order by t0.id offset 3 rows fetch next 10 rows only");
} else if (isOracle()) {
assertThat(query.getGeneratedSql()).contains("where rownum <= 13");
assertThat(query.getGeneratedSql()).contains("where rn_ > 3");
assertSql(query).contains("where rownum <= 13");
assertSql(query).contains("where rn_ > 3");
} else {
assertThat(query.getGeneratedSql()).endsWith("order by t0.id limit 10 offset 3");
assertSql(query).endsWith("order by t0.id limit 10 offset 3");
}
}
@@ -81,12 +81,12 @@ public class EbeanServer_eqlTest extends BaseTestCase {
query.findList();
if (isSqlServer()) {
assertThat(query.getGeneratedSql()).endsWith("order by t0.name offset 3 rows fetch next 10 rows only");
assertSql(query).endsWith("order by t0.name offset 3 rows fetch next 10 rows only");
} else if (isOracle()) {
assertThat(query.getGeneratedSql()).contains("where rownum <= 13");
assertThat(query.getGeneratedSql()).contains("where rn_ > 3");
assertSql(query).contains("where rownum <= 13");
assertSql(query).contains("where rn_ > 3");
} else {
assertThat(query.getGeneratedSql()).endsWith("order by t0.name limit 10 offset 3");
assertSql(query).endsWith("order by t0.name limit 10 offset 3");
}
// check also select count(*)
@@ -108,12 +108,12 @@ public class EbeanServer_eqlTest extends BaseTestCase {
query.findList();
if (isSqlServer()) {
assertThat(query.getGeneratedSql()).endsWith("order by t0.name, t0.id offset 3 rows fetch next 10 rows only");
assertSql(query).endsWith("order by t0.name, t0.id offset 3 rows fetch next 10 rows only");
} else if (isOracle()) {
assertThat(query.getGeneratedSql()).contains("where rownum <= 13");
assertThat(query.getGeneratedSql()).contains("where rn_ > 3");
assertSql(query).contains("where rownum <= 13");
assertSql(query).contains("where rn_ > 3");
} else {
assertThat(query.getGeneratedSql()).endsWith("order by t0.name, t0.id limit 10 offset 3");
assertSql(query).endsWith("order by t0.name, t0.id limit 10 offset 3");
}
// check also select count(*)
@@ -138,12 +138,12 @@ public class EbeanServer_eqlTest extends BaseTestCase {
query.findList();
if (isSqlServer()) {
assertThat(query.getGeneratedSql()).endsWith("from o_customer t0 order by t0.id offset 3 rows fetch next 10 rows only");
assertSql(query).endsWith("from o_customer t0 order by t0.id offset 3 rows fetch next 10 rows only");
} else if (isOracle()) {
assertThat(query.getGeneratedSql()).contains("where rownum <= 13");
assertThat(query.getGeneratedSql()).contains("where rn_ > 3");
assertSql(query).contains("where rownum <= 13");
assertSql(query).contains("where rn_ > 3");
} else {
assertThat(query.getGeneratedSql()).endsWith("from o_customer t0 limit 10 offset 3");
assertSql(query).endsWith("from o_customer t0 limit 10 offset 3");
}
}
@@ -157,11 +157,11 @@ public class EbeanServer_eqlTest extends BaseTestCase {
query.findList();
if (isSqlServer()) {
assertThat(query.getGeneratedSql()).startsWith("select top 10 ");
assertSql(query).startsWith("select top 10 ");
} else if (isOracle()) {
assertThat(query.getGeneratedSql()).contains(" a where rownum <= 10");
assertSql(query).contains(" a where rownum <= 10");
} else {
assertThat(query.getGeneratedSql()).endsWith("limit 10");
assertSql(query).endsWith("limit 10");
}
}
@@ -176,7 +176,7 @@ public class EbeanServer_eqlTest extends BaseTestCase {
query.orderBy().clear().asc("name");
query.findList();
assertThat(query.getGeneratedSql()).contains("order by t0.name");
assertSql(query).contains("order by t0.name");
}
@@ -189,7 +189,7 @@ public class EbeanServer_eqlTest extends BaseTestCase {
query.setParameter("name", "Ro");
query.findList();
assertThat(query.getGeneratedSql()).contains("where t0.name like ");
assertSql(query).contains("where t0.name like ");
}
@Test(expected = PersistenceException.class)
@@ -234,7 +234,7 @@ public class EbeanServer_eqlTest extends BaseTestCase {
query.setUseCache(false);
query.findOne();
assertThat(query.getGeneratedSql()).contains("from o_customer t0 left join contact t1 on t1.customer_id = t0.id ");
assertSql(query).contains("from o_customer t0 left join contact t1 on t1.customer_id = t0.id ");
}
@Test
@@ -249,7 +249,7 @@ public class EbeanServer_eqlTest extends BaseTestCase {
query.setUseCache(false);
query.findOne();
assertThat(query.getGeneratedSql()).contains("from o_customer t0 left join contact t1 on t1.customer_id = t0.id ");
assertSql(query).contains("from o_customer t0 left join contact t1 on t1.customer_id = t0.id ");
}
@Test
@@ -264,6 +264,6 @@ public class EbeanServer_eqlTest extends BaseTestCase {
query.setUseCache(false);
query.findOne();
assertThat(query.getGeneratedSql()).contains("from o_customer t0 left join contact t1 on t1.customer_id = t0.id ");
assertSql(query).contains("from o_customer t0 left join contact t1 on t1.customer_id = t0.id ");
}
}
+6 -6
View File
@@ -52,8 +52,8 @@ public class FetchGroupTest extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(2);
assertThat(sql.get(0)).contains("select t0.id, t0.name, t0.status from o_customer");
assertThat(sql.get(1)).contains("select t0.customer_id, t0.id, t0.first_name, t0.last_name, t0.email from contact");
assertSql(sql.get(0)).contains("select t0.id, t0.name, t0.status from o_customer");
assertSql(sql.get(1)).contains("select t0.customer_id, t0.id, t0.first_name, t0.last_name, t0.email from contact");
}
@@ -80,8 +80,8 @@ public class FetchGroupTest extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(2);
assertThat(sql.get(0)).contains("select t0.id, t0.name from o_customer");
assertThat(sql.get(1)).contains(" from contact");
assertSql(sql.get(0)).contains("select t0.id, t0.name from o_customer");
assertSql(sql.get(1)).contains(" from contact");
}
@Test
@@ -110,7 +110,7 @@ public class FetchGroupTest extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(1);
assertThat(sql.get(0)).contains("select t0.id, t0.name, t0.version, t1.id, t1.line_1, t1.line_2, t1.city, t2.code, t2.name from o_customer t0 left join o_address t1 on t1.id = t0.billing_address_id left join o_country t2 on t2.code = t1.country_code ");
assertSql(sql.get(0)).contains("select t0.id, t0.name, t0.version, t1.id, t1.line_1, t1.line_2, t1.city, t2.code, t2.name from o_customer t0 left join o_address t1 on t1.id = t0.billing_address_id left join o_country t2 on t2.code = t1.country_code ");
}
@Test
@@ -133,6 +133,6 @@ public class FetchGroupTest extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(1);
assertThat(trimSql(sql.get(0))).contains("select t0.id, t0.name from o_customer t0 where");
assertSql(sql.get(0)).contains("select t0.id, t0.name from o_customer t0 where");
}
}
@@ -41,7 +41,7 @@ public class NamedDtoQueryTest extends BaseTestCase {
.findEach(it -> log.info("got " + it.getId() + " " + it.getName()));
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql.get(0)).contains("select id, name from o_customer where id > ?");
assertSql(sql.get(0)).contains("select id, name from o_customer where id > ?");
}
@Test
@@ -58,7 +58,7 @@ public class NamedDtoQueryTest extends BaseTestCase {
});
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql.get(0)).contains("select id, name from o_customer where id > ?");
assertSql(sql.get(0)).contains("select id, name from o_customer where id > ?");
}
@Test
@@ -118,6 +118,6 @@ public class TestUnsetLoadedProperties extends BaseTestCase {
updUser.save();
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql.get(0)).contains("where id=?;");
assertSql(sql.get(0)).contains("where id=?;");
}
}
+7 -7
View File
@@ -36,7 +36,7 @@ public class UpdateQueryTest extends BaseTestCase {
query.update();
assertThat(query.getGeneratedSql()).contains("update o_customer set status=?, updtime=? where status = ? and id > ?");
assertSql(query).contains("update o_customer set status=?, updtime=? where status = ? and id > ?");
ServerMetrics metrics = collectMetrics();
List<MetaQueryMetric> ormQueryMetrics = metrics.getQueryMetrics();
@@ -66,7 +66,7 @@ public class UpdateQueryTest extends BaseTestCase {
assertThat(sql).hasSize(1);
assertThat(rows).isGreaterThan(0);
assertThat(sql.get(0)).contains("update o_customer set status = status");
assertSql(sql.get(0)).contains("update o_customer set status = status");
ServerMetrics metrics = collectMetrics();
List<MetaQueryMetric> ormQueryMetrics = metrics.getQueryMetrics();
@@ -95,7 +95,7 @@ public class UpdateQueryTest extends BaseTestCase {
assertThat(sql).hasSize(1);
assertThat(rows).isEqualTo(0);
assertThat(sql.get(0)).contains("update o_customer set status = status where id > ?");
assertSql(sql.get(0)).contains("update o_customer set status = status where id > ?");
}
@Test
@@ -140,7 +140,7 @@ public class UpdateQueryTest extends BaseTestCase {
query.alias("cust");
query.update();
assertThat(query.getGeneratedSql()).contains("update o_customer cust set status=?, updtime=? where id > ?");
assertSql(query).contains("update o_customer cust set status=?, updtime=? where id > ?");
}
@IgnorePlatform(Platform.MYSQL)
@@ -186,7 +186,7 @@ public class UpdateQueryTest extends BaseTestCase {
.update();
final List<String> sql = LoggedSqlCollector.stop();
assertThat(sql.get(0)).contains("update o_customer set status=? where id in (select t0.id from o_customer t0 left join o_address t1 on t1.id = t0.billing_address_id where t1.country_code = ? and t0.id > ? limit 100)");
assertSql(sql.get(0)).contains("update o_customer set status=? where id in (select t0.id from o_customer t0 left join o_address t1 on t1.id = t0.billing_address_id where t1.country_code = ? and t0.id > ? limit 100)");
}
@ForPlatform({Platform.H2, Platform.POSTGRES, Platform.MYSQL})
@@ -206,9 +206,9 @@ public class UpdateQueryTest extends BaseTestCase {
final List<String> sql = LoggedSqlCollector.stop();
if (isMySql() || isH2()) {
assertThat(sql.get(0)).contains("update o_customer set status=? where id > ? limit 100");
assertSql(sql.get(0)).contains("update o_customer set status=? where id > ? limit 100");
} else {
assertThat(sql.get(0)).contains("update o_customer set status=? where id in (select t0.id from o_customer t0 where t0.id > ? limit 100)");
assertSql(sql.get(0)).contains("update o_customer set status=? where id in (select t0.id from o_customer t0 where t0.id > ? limit 100)");
}
}
@@ -45,11 +45,11 @@ public class IsEmptyExpressionQueryTest extends BaseTestCase {
assertThat(sql).hasSize(1);
if (isPlatformSupportsDeleteTableAlias()) {
assertThat(sql.get(0)).contains("delete from euser_no_fk t0 where not exists (select 1 from efile_no_fk x where x.owner_user_id = t0.user_id)");
assertSql(sql.get(0)).contains("delete from euser_no_fk t0 where not exists (select 1 from efile_no_fk x where x.owner_user_id = t0.user_id)");
} else if (isMySql()) {
assertThat(sql.get(0)).contains("delete t0 from euser_no_fk t0 where not exists (select 1 from efile_no_fk x where x.owner_user_id = t0.user_id)");
assertSql(sql.get(0)).contains("delete t0 from euser_no_fk t0 where not exists (select 1 from efile_no_fk x where x.owner_user_id = t0.user_id)");
} else {
assertThat(sql.get(0)).contains("delete from euser_no_fk where not exists (select 1 from efile_no_fk x where x.owner_user_id = user_id)");
assertSql(sql.get(0)).contains("delete from euser_no_fk where not exists (select 1 from efile_no_fk x where x.owner_user_id = user_id)");
}
}
@@ -40,7 +40,7 @@ public class NoopExpressionTest extends BaseExpressionTest {
query.findCount();
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql.get(0)).contains("select count(*) from cover t0 where 1=1 and");
assertSql(sql.get(0)).contains("select count(*) from cover t0 where 1=1 and");
}
@Test
@@ -36,7 +36,7 @@ public class EqlParserTest extends BaseTestCase {
Query<Customer> query = parse("where name eq 'Rob'");
query.findList();
assertThat(query.getGeneratedSql()).contains("where t0.name = ?");
assertSql(query).contains("where t0.name = ?");
}
@Test
@@ -44,7 +44,7 @@ public class EqlParserTest extends BaseTestCase {
Query<Customer> query = parse("where name eqOrNull 'Rob'");
query.findList();
assertThat(query.getGeneratedSql()).contains("where (t0.name = ? or t0.name is null)");
assertSql(query).contains("where (t0.name = ? or t0.name is null)");
}
@Test
@@ -53,7 +53,7 @@ public class EqlParserTest extends BaseTestCase {
query.setParameter("name", "Rob");
query.findList();
assertThat(query.getGeneratedSql()).contains("where (t0.name = ? or t0.name is null)");
assertSql(query).contains("where (t0.name = ? or t0.name is null)");
}
@Test
@@ -62,7 +62,7 @@ public class EqlParserTest extends BaseTestCase {
final Query<Customer> query = where("name eqOrNull ?", "Rob");
query.findList();
if (isH2()) {
assertThat(query.getGeneratedSql()).contains("where (t0.name = ? or t0.name is null)");
assertSql(query).contains("where (t0.name = ? or t0.name is null)");
}
}
@@ -72,7 +72,7 @@ public class EqlParserTest extends BaseTestCase {
final Query<Customer> query = where("name eqOrNull ?", (String)null);
query.findList();
if (isH2()) {
assertThat(query.getGeneratedSql()).contains("(t0.name is null or t0.name is null)");
assertSql(query).contains("(t0.name is null or t0.name is null)");
}
}
@@ -82,7 +82,7 @@ public class EqlParserTest extends BaseTestCase {
final Query<Customer> query = where("name gtOrNull ?", "Rob");
query.findList();
if (isH2()) {
assertThat(query.getGeneratedSql()).contains("where (t0.name > ? or t0.name is null)");
assertSql(query).contains("where (t0.name > ? or t0.name is null)");
}
}
@@ -92,7 +92,7 @@ public class EqlParserTest extends BaseTestCase {
final Query<Customer> query = where("name ltOrNull ?", "Rob");
query.findList();
if (isH2()) {
assertThat(query.getGeneratedSql()).contains("where (t0.name < ? or t0.name is null)");
assertSql(query).contains("where (t0.name < ? or t0.name is null)");
}
}
@@ -102,7 +102,7 @@ public class EqlParserTest extends BaseTestCase {
Query<Customer> query = parse("where 'Rob' eq name");
query.findList();
assertThat(query.getGeneratedSql()).contains("where t0.name = ?");
assertSql(query).contains("where t0.name = ?");
}
@Test
@@ -110,7 +110,7 @@ public class EqlParserTest extends BaseTestCase {
Query<Customer> query = parse("where 'Rob' > name");
query.findList();
assertThat(query.getGeneratedSql()).contains("where t0.name < ?");
assertSql(query).contains("where t0.name < ?");
}
@Test
@@ -118,7 +118,7 @@ public class EqlParserTest extends BaseTestCase {
Query<Customer> query = parse("where 'Rob' >= name");
query.findList();
assertThat(query.getGeneratedSql()).contains("where t0.name <= ?");
assertSql(query).contains("where t0.name <= ?");
}
@Test
@@ -126,7 +126,7 @@ public class EqlParserTest extends BaseTestCase {
Query<Customer> query = parse("where 'Rob' < name");
query.findList();
assertThat(query.getGeneratedSql()).contains("where t0.name > ?");
assertSql(query).contains("where t0.name > ?");
}
@Test
@@ -134,7 +134,7 @@ public class EqlParserTest extends BaseTestCase {
Query<Customer> query = parse("where 'Rob' <= name");
query.findList();
assertThat(query.getGeneratedSql()).contains("where t0.name >= ?");
assertSql(query).contains("where t0.name >= ?");
}
@Test
@@ -143,7 +143,7 @@ public class EqlParserTest extends BaseTestCase {
Query<Customer> query = parse("where name ieq 'Rob'");
query.findList();
assertThat(query.getGeneratedSql()).contains("where lower(t0.name) = ?");
assertSql(query).contains("where lower(t0.name) = ?");
}
@Test
@@ -152,7 +152,7 @@ public class EqlParserTest extends BaseTestCase {
Query<Customer> query = parse("where name ine 'Rob'");
query.findList();
assertThat(query.getGeneratedSql()).contains("where lower(t0.name) != ?");
assertSql(query).contains("where lower(t0.name) != ?");
}
@Test
@@ -160,7 +160,7 @@ public class EqlParserTest extends BaseTestCase {
Query<Customer> query = parse("where 'Rob' ieq name");
query.findList();
assertThat(query.getGeneratedSql()).contains("where lower(t0.name) = ?");
assertSql(query).contains("where lower(t0.name) = ?");
}
@Test
@@ -169,7 +169,7 @@ public class EqlParserTest extends BaseTestCase {
Query<Customer> query = parse("where 'Rob' ine name");
query.findList();
assertThat(query.getGeneratedSql()).contains("where lower(t0.name) != ?");
assertSql(query).contains("where lower(t0.name) != ?");
}
@Test
@@ -178,7 +178,7 @@ public class EqlParserTest extends BaseTestCase {
Query<Customer> query = parse("where name = 'Rob'");
query.findList();
assertThat(query.getGeneratedSql()).contains("where t0.name = ?");
assertSql(query).contains("where t0.name = ?");
}
@Test
@@ -188,7 +188,7 @@ public class EqlParserTest extends BaseTestCase {
query.setParameter("name", "Rob");
query.findList();
assertThat(query.getGeneratedSql()).contains("where t0.name = ?");
assertSql(query).contains("where t0.name = ?");
}
@Test
@@ -197,7 +197,7 @@ public class EqlParserTest extends BaseTestCase {
query.setParameter("nm", "Rob");
query.findList();
assertThat(query.getGeneratedSql()).contains("where t0.name > ?");
assertSql(query).contains("where t0.name > ?");
}
@Test
@@ -207,7 +207,7 @@ public class EqlParserTest extends BaseTestCase {
query.setParameter("name", "Rob");
query.findList();
assertThat(query.getGeneratedSql()).contains("where t0.name like ");
assertSql(query).contains("where t0.name like ");
}
@Test
@@ -217,7 +217,7 @@ public class EqlParserTest extends BaseTestCase {
Query<Customer> query = parse("where name = 'Rob' or (status = 'NEW' and smallnote is null)");
query.findList();
assertThat(query.getGeneratedSql()).contains("where (t0.name = ? or (t0.status = ? and t0.smallnote is null))");
assertSql(query).contains("where (t0.name = ? or (t0.status = ? and t0.smallnote is null))");
}
@Test
@@ -227,7 +227,7 @@ public class EqlParserTest extends BaseTestCase {
Query<Customer> query = parse("where name = 'Rob' or (status = 'N' and smallnote is null)");
query.findList();
assertThat(query.getGeneratedSql()).contains("where (t0.name = ? or (t0.status = ? and t0.smallnote is null ) )");
assertSql(query).contains("where (t0.name = ? or (t0.status = ? and t0.smallnote is null ) )");
}
@Test
@@ -237,7 +237,7 @@ public class EqlParserTest extends BaseTestCase {
Query<Customer> query = parse("where (name = 'Rob' or status = 'NEW') and smallnote is null");
query.findList();
assertThat(query.getGeneratedSql()).contains("where ((t0.name = ? or t0.status = ?) and t0.smallnote is null)");
assertSql(query).contains("where ((t0.name = ? or t0.status = ?) and t0.smallnote is null)");
}
@Test
@@ -247,7 +247,7 @@ public class EqlParserTest extends BaseTestCase {
Query<Customer> query = parse("where (name = 'Rob' or status = 'N') and smallnote is null");
query.findList();
assertThat(query.getGeneratedSql()).contains("where ((t0.name = ? or t0.status = ? ) and t0.smallnote is null )");
assertSql(query).contains("where ((t0.name = ? or t0.status = ? ) and t0.smallnote is null )");
}
@Test
@@ -256,15 +256,15 @@ public class EqlParserTest extends BaseTestCase {
Query<Customer> query = parse("where not (name = 'Rob' and status = 'NEW')");
query.findList();
assertThat(query.getGeneratedSql()).contains("where not (t0.name = ? and t0.status = ?)");
assertSql(query).contains("where not (t0.name = ? and t0.status = ?)");
query = parse("where not ((name = 'Rob' and status = 'NEW'))");
query.findList();
assertThat(query.getGeneratedSql()).contains("where not (t0.name = ? and t0.status = ?)");
assertSql(query).contains("where not (t0.name = ? and t0.status = ?)");
query = parse("where not (((name = 'Rob') and (status = 'NEW')))");
query.findList();
assertThat(query.getGeneratedSql()).contains("where not (t0.name = ? and t0.status = ?)");
assertSql(query).contains("where not (t0.name = ? and t0.status = ?)");
}
@Test
@@ -273,15 +273,15 @@ public class EqlParserTest extends BaseTestCase {
Query<Customer> query = parse("where not (name = 'Rob' and status = 'N')");
query.findList();
assertThat(query.getGeneratedSql()).contains("where not (t0.name = ? and t0.status = ? )");
assertSql(query).contains("where not (t0.name = ? and t0.status = ? )");
query = parse("where not ((name = 'Rob' and status = 'N'))");
query.findList();
assertThat(query.getGeneratedSql()).contains("where not (t0.name = ? and t0.status = ? )");
assertSql(query).contains("where not (t0.name = ? and t0.status = ? )");
query = parse("where not (((name = 'Rob') and (status = 'N')))");
query.findList();
assertThat(query.getGeneratedSql()).contains("where not (t0.name = ? and t0.status = ? )");
assertSql(query).contains("where not (t0.name = ? and t0.status = ? )");
}
@Test
@@ -357,7 +357,7 @@ public class EqlParserTest extends BaseTestCase {
final Query<Customer> query = where("name inOrEmpty ?", new ArrayList());
query.findList();
assertThat(query.getGeneratedSql()).doesNotContain("where");
assertSql(query).doesNotContain("where");
}
@Test
@@ -366,7 +366,7 @@ public class EqlParserTest extends BaseTestCase {
List<String> names = null;
final Query<Customer> query = where("name inOrEmpty ?", names);
query.findList();
assertThat(query.getGeneratedSql()).doesNotContain("where");
assertSql(query).doesNotContain("where");
}
@Test(expected = IllegalArgumentException.class)
@@ -389,7 +389,7 @@ public class EqlParserTest extends BaseTestCase {
query.setParameter("names", new ArrayList<>());
query.findList();
assertThat(query.getGeneratedSql()).doesNotContain("where");
assertSql(query).doesNotContain("where");
}
@Test
@@ -398,7 +398,7 @@ public class EqlParserTest extends BaseTestCase {
Query<Customer> query = parse("where name inrange 'As' to 'B'");
query.findList();
assertThat(query.getGeneratedSql()).contains("where (t0.name >= ? and t0.name < ?)");
assertSql(query).contains("where (t0.name >= ? and t0.name < ?)");
}
@Test
@@ -409,7 +409,7 @@ public class EqlParserTest extends BaseTestCase {
query.setParameter("two", "b");
query.findList();
assertThat(query.getGeneratedSql()).contains("where (t0.name >= ? and t0.name < ?)");
assertSql(query).contains("where (t0.name >= ? and t0.name < ?)");
}
@Test
@@ -418,7 +418,7 @@ public class EqlParserTest extends BaseTestCase {
Query<Customer> query = parse("where name between 'As' and 'B'");
query.findList();
assertThat(query.getGeneratedSql()).contains("where t0.name between ? and ?");
assertSql(query).contains("where t0.name between ? and ?");
}
@Test
@@ -429,7 +429,7 @@ public class EqlParserTest extends BaseTestCase {
query.setParameter("two", "b");
query.findList();
assertThat(query.getGeneratedSql()).contains("where t0.name between ? and ?");
assertSql(query).contains("where t0.name between ? and ?");
}
@Test
@@ -438,7 +438,7 @@ public class EqlParserTest extends BaseTestCase {
Query<Customer> query = parse("where 'x' between name and smallnote");
query.findList();
assertThat(query.getGeneratedSql()).contains("where ? between t0.name and t0.smallnote");
assertSql(query).contains("where ? between t0.name and t0.smallnote");
}
@Test
@@ -448,7 +448,7 @@ public class EqlParserTest extends BaseTestCase {
query.setParameter("some", "A");
query.findList();
assertThat(query.getGeneratedSql()).contains("where ? between t0.name and t0.smallnote");
assertSql(query).contains("where ? between t0.name and t0.smallnote");
}
@Test
@@ -457,7 +457,7 @@ public class EqlParserTest extends BaseTestCase {
Query<Customer> query = parse("select name fetch billingAddress");
query.findList();
assertThat(query.getGeneratedSql()).contains("select t0.id, t0.name, t1.id, t1.line_1, t1.line_2, t1.city, t1.cretime, t1.updtime, t1.country_code from o_customer t0 left join o_address t1 on t1.id = t0.billing_address_id");
assertSql(query).contains("select t0.id, t0.name, t1.id, t1.line_1, t1.line_2, t1.city, t1.cretime, t1.updtime, t1.country_code from o_customer t0 left join o_address t1 on t1.id = t0.billing_address_id");
}
@Test
@@ -468,7 +468,7 @@ public class EqlParserTest extends BaseTestCase {
Query<Customer> query = parse("select name, status fetch billingAddress");
query.findList();
assertThat(query.getGeneratedSql()).contains("select t0.id, t0.name, t0.status, t1.id, t1.line_1, t1.line_2, t1.city, t1.cretime, t1.updtime, t1.country_code from o_customer t0 left join o_address t1 on t1.id = t0.billing_address_id");
assertSql(query).contains("select t0.id, t0.name, t0.status, t1.id, t1.line_1, t1.line_2, t1.city, t1.cretime, t1.updtime, t1.country_code from o_customer t0 left join o_address t1 on t1.id = t0.billing_address_id");
}
@Test
@@ -477,7 +477,7 @@ public class EqlParserTest extends BaseTestCase {
Query<Customer> query = parse("select name fetch billingAddress (line1, city) ");
query.findList();
assertThat(sqlOf(query, 12)).contains("select t0.id, t0.name, t1.id, t1.line_1, t1.city from o_customer t0 left join o_address t1 on t1.id = t0.billing_address_id");
assertSql(query, 12).contains("select t0.id, t0.name, t1.id, t1.line_1, t1.city from o_customer t0 left join o_address t1 on t1.id = t0.billing_address_id");
}
@Test
@@ -487,7 +487,7 @@ public class EqlParserTest extends BaseTestCase {
Query<Customer> query = parse("select name fetch billingAddress (line1, city) fetch shippingAddress (line1) limit 10");
query.findList();
assertThat(sqlOf(query, 12)).contains("select t0.id, t0.name, t1.id, t1.line_1, t1.city, t2.id, t2.line_1 from o_customer t0 left join o_address t1 on t1.id = t0.billing_address_id left join o_address t2 on t2.id = t0.shipping_address_id");
assertSql(query, 12).contains("select t0.id, t0.name, t1.id, t1.line_1, t1.city, t2.id, t2.line_1 from o_customer t0 left join o_address t1 on t1.id = t0.billing_address_id left join o_address t2 on t2.id = t0.shipping_address_id");
}
@Test
@@ -496,7 +496,7 @@ public class EqlParserTest extends BaseTestCase {
Query<Customer> query = parse("select name fetch billingAddress (line1, city) fetch contacts");
query.findList();
assertThat(sqlOf(query, 12)).contains("select t0.id, t0.name, t1.id, t1.line_1, t1.city, t2.id, t2.first_name, t2.last_name, t2.phone, t2.mobile, t2.email, t2.is_member, t2.cretime, t2.updtime, t2.customer_id, t2.group_id from o_customer t0");
assertSql(query, 16).contains("select t0.id, t0.name, t1.id, t1.line_1, t1.city, t2.id, t2.first_name, t2.last_name, t2.phone, t2.mobile, t2.email, t2.is_member, t2.cretime, t2.updtime, t2.customer_id, t2.group_id from o_customer t0");
}
@@ -506,7 +506,7 @@ public class EqlParserTest extends BaseTestCase {
Query<Customer> query = parse("select name fetch billingAddress (line1, city) fetch contacts (email)");
query.findList();
assertThat(sqlOf(query, 12)).contains("select t0.id, t0.name, t1.id, t1.line_1, t1.city, t2.id, t2.email from o_customer t0");
assertSql(query, 12).contains("select t0.id, t0.name, t1.id, t1.line_1, t1.city, t2.id, t2.email from o_customer t0");
}
@Test
@@ -522,8 +522,8 @@ public class EqlParserTest extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(2);
assertThat(sql.get(0)).contains("select t0.id, t0.name, t1.id, t1.line_1, t1.city from o_customer t0 left join o_address");
assertThat(sql.get(1)).contains("select t0.customer_id, t0.id, t0.email from contact t0 where (t0.customer_id)");
assertSql(sql.get(0)).contains("select t0.id, t0.name, t1.id, t1.line_1, t1.city from o_customer t0 left join o_address");
assertSql(sql.get(1)).contains("select t0.customer_id, t0.id, t0.email from contact t0 where (t0.customer_id)");
}
@Test
@@ -532,7 +532,7 @@ public class EqlParserTest extends BaseTestCase {
Query<Customer> query = parse("fetch billingAddress");
query.findList();
assertThat(query.getGeneratedSql()).contains(", t1.id");
assertSql(query).contains(", t1.id");
}
@Test
@@ -541,7 +541,7 @@ public class EqlParserTest extends BaseTestCase {
Query<Customer> query = parse("fetch billingAddress (city)");
query.findList();
assertThat(sqlOf(query, 10)).contains(", t1.id, t1.city");
assertSql(query, 10).contains(", t1.id, t1.city");
}
@Test
@@ -550,7 +550,7 @@ public class EqlParserTest extends BaseTestCase {
Query<Customer> query = parse("fetch billingAddress(city)");
query.findList();
assertThat(sqlOf(query, 10)).contains(", t1.id, t1.city");
assertSql(query, 10).contains(", t1.id, t1.city");
}
@Test
@@ -559,8 +559,8 @@ public class EqlParserTest extends BaseTestCase {
Query<Customer> query = parse("fetch billingAddress fetch shippingAddress");
query.findList();
assertThat(query.getGeneratedSql()).contains(", t1.city");
assertThat(query.getGeneratedSql()).contains(", t2.city");
assertSql(query).contains(", t1.city");
assertSql(query).contains(", t2.city");
}
@Test
@@ -569,7 +569,7 @@ public class EqlParserTest extends BaseTestCase {
Query<Customer> query = parse("fetch billingAddress (city) fetch shippingAddress (city)");
query.findList();
assertThat(sqlOf(query, 12)).contains(", t1.id, t1.city, t2.id, t2.city");
assertSql(query, 12).contains(", t1.id, t1.city, t2.id, t2.city");
}
@Test
@@ -578,7 +578,7 @@ public class EqlParserTest extends BaseTestCase {
Query<Customer> query = parse("fetch lazy billingAddress");
query.findList();
assertThat(query.getGeneratedSql()).doesNotContain(", t1.city");
assertSql(query).doesNotContain(", t1.city");
}
@Test
@@ -587,7 +587,7 @@ public class EqlParserTest extends BaseTestCase {
Query<Customer> query = parse("fetch lazy(50) billingAddress");
query.findList();
assertThat(query.getGeneratedSql()).doesNotContain(", t1.city");
assertSql(query).doesNotContain(", t1.city");
}
@Test
@@ -597,7 +597,7 @@ public class EqlParserTest extends BaseTestCase {
Query<Customer> query = parse("fetch query(50) billingAddress");
query.findList();
assertThat(query.getGeneratedSql()).doesNotContain(", t1.city");
assertSql(query).doesNotContain(", t1.city");
}
@Test
@@ -607,7 +607,7 @@ public class EqlParserTest extends BaseTestCase {
Query<Customer> query = parse("fetch billingAddress (+query(50),city)");
query.findList();
assertThat(query.getGeneratedSql()).doesNotContain(", t1.city");
assertSql(query).doesNotContain(", t1.city");
}
@Test
@@ -617,7 +617,7 @@ public class EqlParserTest extends BaseTestCase {
Query<Customer> query = parse("fetch billingAddress (+lazy(50),city) order by id");
List<Customer> list = query.findList();
assertThat(query.getGeneratedSql()).doesNotContain(", t1.city");
assertSql(query).doesNotContain(", t1.city");
Customer customer = list.get(0);
customer.getBillingAddress().getCity();
@@ -630,11 +630,11 @@ public class EqlParserTest extends BaseTestCase {
Query<Customer> query = parse("select (name)");
query.findList();
assertThat(sqlOf(query, 1)).contains("select t0.id, t0.name from o_customer t0");
assertSql(query).contains("select t0.id, t0.name from o_customer t0");
Query<Customer> query2 = parse("select name");
query2.findList();
assertThat(sqlOf(query2, 1)).contains("select t0.id, t0.name from o_customer t0");
assertSql(query2).contains("select t0.id, t0.name from o_customer t0");
}
@Test
@@ -644,7 +644,7 @@ public class EqlParserTest extends BaseTestCase {
Query<Customer> query = parse("select (sum(id))");
query.findSingleAttribute();
assertThat(sqlOf(query, 1)).contains("select sum(t0.id) from o_customer t0");
assertSql(query).contains("select sum(t0.id) from o_customer t0");
}
@Test
@@ -654,11 +654,11 @@ public class EqlParserTest extends BaseTestCase {
Query<Customer> query = parse("select (max(cretime))");
query.findSingleAttribute();
assertThat(sqlOf(query, 1)).contains("select max(t0.cretime) from o_customer t0");
assertSql(query).contains("select max(t0.cretime) from o_customer t0");
Query<Customer> query2 = parse("select max(cretime)");
query2.findSingleAttribute();
assertThat(sqlOf(query2, 1)).contains("select max(t0.cretime) from o_customer t0");
assertSql(query2).contains("select max(t0.cretime) from o_customer t0");
}
@Test
@@ -670,7 +670,7 @@ public class EqlParserTest extends BaseTestCase {
List<Customer> customers = query.findList();
assertThat(customers).isNotEmpty();
assertThat(sqlOf(query, 1)).contains("select t0.status, max(t0.cretime) from o_customer t0 group by t0.status");
assertSql(query).contains("select t0.status, max(t0.cretime) from o_customer t0 group by t0.status");
}
@Test
@@ -682,7 +682,7 @@ public class EqlParserTest extends BaseTestCase {
List<OrderDetail> details = query.findList();
assertThat(details).isNotEmpty();
assertThat(sqlOf(query, 1)).contains("select sum(t0.order_qty), t1.id from o_order_detail t0 join o_order t1 on t1.id = t0.order_id group by t1.id");
assertSql(query).contains("select sum(t0.order_qty), t1.id from o_order_detail t0 join o_order t1 on t1.id = t0.order_id group by t1.id");
}
@Test
@@ -692,7 +692,7 @@ public class EqlParserTest extends BaseTestCase {
Query<Customer> query = parse("select distinct (name)");
query.findList();
assertThat(sqlOf(query, 1)).contains("select distinct t0.name from o_customer t0");
assertSql(query).contains("select distinct t0.name from o_customer t0");
}
@@ -704,7 +704,7 @@ public class EqlParserTest extends BaseTestCase {
Query<Customer> query = parse("limit 10");
query.findList();
if (isH2()) {
assertThat(query.getGeneratedSql()).contains(" limit 10");
assertSql(query).contains(" limit 10");
}
}
@@ -716,7 +716,7 @@ public class EqlParserTest extends BaseTestCase {
Query<Customer> query = parse("order by name limit 10 offset 5");
query.findList();
if (isH2()) {
assertThat(query.getGeneratedSql()).contains(" limit 10 offset 5");
assertSql(query).contains(" limit 10 offset 5");
}
}
@@ -728,7 +728,7 @@ public class EqlParserTest extends BaseTestCase {
Query<Customer> query = parse("order by id");
query.findList();
if (isH2()) {
assertThat(query.getGeneratedSql()).contains("from o_customer t0 order by t0.id");
assertSql(query).contains("from o_customer t0 order by t0.id");
}
}
@@ -740,7 +740,7 @@ public class EqlParserTest extends BaseTestCase {
Query<Customer> query = parse("order by id desc");
query.findList();
if (isH2()) {
assertThat(query.getGeneratedSql()).contains("from o_customer t0 order by t0.id desc");
assertSql(query).contains("from o_customer t0 order by t0.id desc");
}
}
@@ -756,7 +756,7 @@ public class EqlParserTest extends BaseTestCase {
Query<Customer> query = parse("order by id desc nulls last");
query.findList();
if (isH2()) {
assertThat(query.getGeneratedSql()).contains(" from o_customer t0 order by t0.id desc nulls last");
assertSql(query).contains(" from o_customer t0 order by t0.id desc nulls last");
}
}
@@ -771,7 +771,7 @@ public class EqlParserTest extends BaseTestCase {
Query<Customer> query = parse("order by id nulls first");
query.findList();
if (isH2()) {
assertThat(query.getGeneratedSql()).contains(" from o_customer t0 order by t0.id nulls first");
assertSql(query).contains(" from o_customer t0 order by t0.id nulls first");
}
}
@@ -786,7 +786,7 @@ public class EqlParserTest extends BaseTestCase {
Query<Customer> query = parse("order by billingAddress.city desc nulls last, name, id desc nulls last");
query.findList();
if (isH2()) {
assertThat(query.getGeneratedSql()).contains(" order by t1.city desc nulls last, t0.name, t0.id desc nulls last");
assertSql(query).contains(" order by t1.city desc nulls last, t0.name, t0.id desc nulls last");
}
}
@@ -803,7 +803,7 @@ public class EqlParserTest extends BaseTestCase {
final Query<Customer> query = where("name isNotNull");
query.findList();
if (isH2()) {
assertThat(query.getGeneratedSql()).contains(" from o_customer t0 where t0.name is not null");
assertSql(query).contains(" from o_customer t0 where t0.name is not null");
}
}
@@ -813,7 +813,7 @@ public class EqlParserTest extends BaseTestCase {
final Query<Customer> query = where("id isNotNull and name = ? and smallnote istartsWith ?", "Rob", "Foo");
query.findList();
if (isH2()) {
assertThat(query.getGeneratedSql()).contains("where (t0.id is not null and t0.name = ? and lower(t0.smallnote) like ? escape'|' )");
assertSql(query).contains("where (t0.id is not null and t0.name = ? and lower(t0.smallnote) like ? escape'|' )");
}
}
@@ -823,7 +823,7 @@ public class EqlParserTest extends BaseTestCase {
final Query<Customer> query = where("name = ?1 and smallnote istartsWith ?2 and name like ?1", "Rob", "Foo");
query.findList();
if (isH2()) {
assertThat(query.getGeneratedSql()).contains(" where (t0.name = ? and lower(t0.smallnote) like ? escape'|' and t0.name like ? escape'' )");
assertSql(query).contains(" where (t0.name = ? and lower(t0.smallnote) like ? escape'|' and t0.name like ? escape'' )");
}
}
@@ -833,7 +833,7 @@ public class EqlParserTest extends BaseTestCase {
final Query<Customer> query = where("id isNotNull or name = ?", "Rob", "Foo");
query.findList();
if (isH2()) {
assertThat(query.getGeneratedSql()).contains("where (t0.id is not null or t0.name = ?)");
assertSql(query).contains("where (t0.id is not null or t0.name = ?)");
}
}
@@ -843,7 +843,7 @@ public class EqlParserTest extends BaseTestCase {
final Query<Customer> query = where("(id isNotNull or name = ?) and smallnote istartsWith ?", "Rob", "Foo");
query.findList();
if (isH2()) {
assertThat(query.getGeneratedSql()).contains("where ((t0.id is not null or t0.name = ?) and lower(t0.smallnote) like ? escape'|' )");
assertSql(query).contains("where ((t0.id is not null or t0.name = ?) and lower(t0.smallnote) like ? escape'|' )");
}
}
@@ -853,7 +853,7 @@ public class EqlParserTest extends BaseTestCase {
final Query<Customer> query = where("anniversary inrange ? to ?", LocalDate.now().minusDays(7), LocalDate.now());
query.findList();
if (isH2()) {
assertThat(query.getGeneratedSql()).contains("where (t0.anniversary >= ? and t0.anniversary < ?)");
assertSql(query).contains("where (t0.anniversary >= ? and t0.anniversary < ?)");
}
}
@@ -863,7 +863,7 @@ public class EqlParserTest extends BaseTestCase {
final Query<Customer> query = where("anniversary inRange ? to ?", LocalDate.now().minusDays(7), LocalDate.now());
query.findList();
if (isH2()) {
assertThat(query.getGeneratedSql()).contains("where (t0.anniversary >= ? and t0.anniversary < ?)");
assertSql(query).contains("where (t0.anniversary >= ? and t0.anniversary < ?)");
}
}
+17
View File
@@ -0,0 +1,17 @@
package main;
import io.ebean.docker.commands.OracleConfig;
import io.ebean.docker.commands.OracleContainer;
public class StartOracle {
public static void main(String[] args) {
OracleConfig config = new OracleConfig();
// config.setImage("quillbuilduser/oracle-18-xe:latest");
config.setUser("test_ebean");
OracleContainer container = new OracleContainer(config);
container.start();//WithDropCreate();
}
}
@@ -1,5 +1,6 @@
package org.multitenant.partition;
import io.ebean.BaseTestCase;
import io.ebean.EbeanServer;
import io.ebean.EbeanServerFactory;
import io.ebean.config.ServerConfig;
@@ -13,7 +14,7 @@ import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
public class MultiTenantPartitionTest {
public class MultiTenantPartitionTest extends BaseTestCase {
private static String[] names = {"Ace", "Base", "Case", "Dae", "Eva"};
@@ -41,18 +42,18 @@ public class MultiTenantPartitionTest {
server.save(content);
List<String> sql = LoggedSqlCollector.current();
assertThat(sql.get(0)).contains("insert into mt_content (title, body, when_modified, when_created, version, tenant_id) values (?,?,?,?,?,?)");
assertSql(sql.get(0)).contains("insert into mt_content (title, body, when_modified, when_created, version, tenant_id) values (?,?,?,?,?,?)");
content.setBody("some body");
server.save(content);
sql = LoggedSqlCollector.current();
assertThat(sql.get(0)).contains("update mt_content set body=?, when_modified=?, version=? where id=? and tenant_id=? and version=?");
assertSql(sql.get(0)).contains("update mt_content set body=?, when_modified=?, version=? where id=? and tenant_id=? and version=?");
server.delete(content);
sql = LoggedSqlCollector.current();
assertThat(sql.get(0)).contains("delete from mt_content where id=? and tenant_id=? and version=?");
assertSql(sql.get(0)).contains("delete from mt_content where id=? and tenant_id=? and version=?");
LoggedSqlCollector.stop();
}
@@ -69,7 +70,7 @@ public class MultiTenantPartitionTest {
int rows = server.delete(MtContent.class, content.getId());
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql.get(0)).contains("delete from mt_content where id=? and tenant_id=?");
assertSql(sql.get(0)).contains("delete from mt_content where id=? and tenant_id=?");
assertThat(rows).isEqualTo(1);
rows = server.delete(MtContent.class, 99999);
@@ -92,7 +93,7 @@ public class MultiTenantPartitionTest {
assertThat(rows).isEqualTo(2);
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql.get(0)).contains("delete from mt_content where id=? and tenant_id=?");
assertSql(sql.get(0)).contains("delete from mt_content where id=? and tenant_id=?");
}
private MtContent newContent(String title) {
@@ -34,7 +34,7 @@ public class TestAggregateFormula extends BaseTestCase {
.findList();
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql.get(0)).contains("select distinct t0.last_name, min(t0.customer_id) from contact t0 group by t0.last_name order by min(t0.customer_id) nulls last");
assertSql(sql.get(0)).contains("select distinct t0.last_name, min(t0.customer_id) from contact t0 group by t0.last_name order by min(t0.customer_id) nulls last");
assertThat(contacts).isNotEmpty();
@@ -56,7 +56,7 @@ public class TestAggregateFormula extends BaseTestCase {
.findList();
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql.get(0)).contains("select t0.last_name, min(t0.customer_id) from contact t0 group by t0.last_name");
assertSql(sql.get(0)).contains("select t0.last_name, min(t0.customer_id) from contact t0 group by t0.last_name");
assertThat(contacts).isNotEmpty();
@@ -86,8 +86,8 @@ public class TestAggregateFormula extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(2);
assertThat(sql.get(0)).contains("select t0.last_name, min(t0.customer_id) from contact t0 group by t0.last_name");
assertThat(sql.get(1)).contains("select t0.id, t0.name, t0.status from o_customer t0 where");
assertSql(sql.get(0)).contains("select t0.last_name, min(t0.customer_id) from contact t0 group by t0.last_name");
assertSql(sql.get(1)).contains("select t0.id, t0.name, t0.status from o_customer t0 where");
assertThat(contacts).isNotEmpty();
@@ -121,8 +121,8 @@ public class TestAggregateFormula extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(2);
assertThat(sql.get(0)).contains("select t0.last_name, min(t0.customer_id) from contact t0 group by t0.last_name");
assertThat(sql.get(1)).contains("select t0.id, t0.name, t0.status, t1.id, t1.city, t1.country_code from o_customer t0 left join o_address t1 on t1.id = t0.billing_address_id where");
assertSql(sql.get(0)).contains("select t0.last_name, min(t0.customer_id) from contact t0 group by t0.last_name");
assertSql(sql.get(1)).contains("select t0.id, t0.name, t0.status, t1.id, t1.city, t1.country_code from o_customer t0 left join o_address t1 on t1.id = t0.billing_address_id where");
assertThat(contacts).isNotEmpty();
@@ -144,7 +144,7 @@ public class TestAggregateFormula extends BaseTestCase {
.findList();
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql.get(0)).contains("select t0.status, sum(t0.id) from o_order t0 group by t0.status");
assertSql(sql.get(0)).contains("select t0.status, sum(t0.id) from o_order t0 group by t0.status");
assertThat(orders).isNotEmpty();
for (Order order : orders) {
@@ -165,7 +165,7 @@ public class TestAggregateFormula extends BaseTestCase {
.findList();
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql.get(0)).contains("select t0.status, sum(t0.id) id from o_order t0 group by t0.status");
assertSql(sql.get(0)).contains("select t0.status, sum(t0.id) id from o_order t0 group by t0.status");
assertThat(orders).isNotEmpty();
for (Order order : orders) {
@@ -186,7 +186,7 @@ public class TestAggregateFormula extends BaseTestCase {
.findList();
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql.get(0)).contains("select t0.customer_id, min(t0.cretime) from contact t0 group by t0.customer_id");
assertSql(sql.get(0)).contains("select t0.customer_id, min(t0.cretime) from contact t0 group by t0.customer_id");
assertThat(contacts).isNotEmpty();
}
@@ -203,7 +203,7 @@ public class TestAggregateFormula extends BaseTestCase {
.findList();
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql.get(0)).contains("select t0.customer_id, min(t0.cretime), max(t0.updtime) from contact t0 group by t0.customer_id");
assertSql(sql.get(0)).contains("select t0.customer_id, min(t0.cretime), max(t0.updtime) from contact t0 group by t0.customer_id");
assertThat(contacts).isNotEmpty();
}
@@ -1,5 +1,6 @@
package org.tests.aggregateformula;
import io.ebean.BaseTestCase;
import io.ebean.DB;
import org.ebeantest.LoggedSqlCollector;
import org.junit.Test;
@@ -9,7 +10,7 @@ import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
public class TestAggregateInheritFormula {
public class TestAggregateInheritFormula extends BaseTestCase {
@Test
public void test() {
@@ -34,6 +35,6 @@ public class TestAggregateInheritFormula {
final List<String> sql = LoggedSqlCollector.stop();
assertThat(segments).hasSize(1);
assertThat(sql.get(0)).contains("select t0.segment_id_zat, min(t0.status_id) from iaf_segment t0 where t0.ptype = 'target' and t0.segment_id_zat = ? group by t0.segment_id_zat");
assertSql(sql.get(0)).contains("select t0.segment_id_zat, min(t0.status_id) from iaf_segment t0 where t0.ptype = 'target' and t0.segment_id_zat = ? group by t0.segment_id_zat");
}
}
@@ -20,7 +20,7 @@ public class TestInEmpty extends BaseTestCase {
.query();
List<Order> list = query.findList();
assertThat(query.getGeneratedSql()).contains("1=0");
assertSql(query).contains("1=0");
assertEquals(0, list.size());
}
@@ -31,7 +31,7 @@ public class TestInEmpty extends BaseTestCase {
.query();
List<Order> list = query.findList();
assertThat(query.getGeneratedSql()).contains("1=0");
assertSql(query).contains("1=0");
assertEquals(0, list.size());
}
@@ -42,7 +42,7 @@ public class TestInEmpty extends BaseTestCase {
.query();
query.findList();
assertThat(query.getGeneratedSql()).contains("1=1");
assertSql(query).contains("1=1");
}
}
@@ -68,7 +68,7 @@ public class TestOrderTotalAmountReportBean extends BaseTestCase {
query.findList();
assertThat(query.getGeneratedSql()).contains("count(*) as total_items, sum(order_qty*unit_price) as total_amount");
assertSql(query).contains("count(*) as total_items, sum(order_qty*unit_price) as total_amount");
}
@Test
@@ -90,7 +90,7 @@ public class TestOrderTotalAmountReportBean extends BaseTestCase {
query.findList();
assertThat(query.getGeneratedSql()).contains("count(*) as totalItems, sum(order_qty*unit_price) as totalAmount");
assertSql(query).contains("count(*) as totalItems, sum(order_qty*unit_price) as totalAmount");
}
@Test
@@ -99,7 +99,7 @@ public class TestOrderTotalAmountReportBean extends BaseTestCase {
Query<OrderAggregate> query = Ebean.find(OrderAggregate.class);
List<OrderAggregate> list = query.findList();
assertThat(query.getGeneratedSql()).contains("count(*) as total_items, sum(order_qty*unit_price) as total_amount");
assertSql(query).contains("count(*) as total_items, sum(order_qty*unit_price) as total_amount");
assertNotNull(list);
}
@@ -111,7 +111,7 @@ public class TestOrderTotalAmountReportBean extends BaseTestCase {
Query<OrderAggregate> query = Ebean.getDefaultServer().createNamedQuery(OrderAggregate.class, "withMax");
List<OrderAggregate> list = query.findList();
assertThat(query.getGeneratedSql()).contains("count(*) as total_items, sum(order_qty*unit_price) as total_amount, max(order_qty*unit_price) as maxAmount from o_order_detail");
assertSql(query).contains("count(*) as total_items, sum(order_qty*unit_price) as total_amount, max(order_qty*unit_price) as maxAmount from o_order_detail");
assertNotNull(list);
}
@@ -127,8 +127,8 @@ public class TestOrderTotalAmountReportBean extends BaseTestCase {
.order().desc("totalAmount")
.findList();
assertThat(query.getGeneratedSql()).contains("count(*) as total_items, sum(order_qty*unit_price) as total_amount, max(order_qty*unit_price) as maxAmount from o_order_detail");
assertThat(query.getGeneratedSql()).contains("from o_order_detail where order_id > ? group by order_id having count(*) > ? order by sum(order_qty*unit_price) desc");
assertSql(query).contains("count(*) as total_items, sum(order_qty*unit_price) as total_amount, max(order_qty*unit_price) as maxAmount from o_order_detail");
assertSql(query).contains("from o_order_detail where order_id > ? group by order_id having count(*) > ? order by sum(order_qty*unit_price) desc");
assertNotNull(list);
}
@@ -146,8 +146,8 @@ public class TestOrderTotalAmountReportBean extends BaseTestCase {
.setMaxRows(10)
.findList();
assertThat(query.getGeneratedSql()).contains("count(*) as totalItems, sum(order_qty*unit_price) as totalAmount, max(order_qty*unit_price) as maxAmount from o_order_detail");
assertThat(query.getGeneratedSql()).contains("from o_order_detail where id > ? and order_id is not null group by order_id having sum(order_qty*unit_price) < ? order by sum(order_qty*unit_price) desc");
assertSql(query).contains("count(*) as totalItems, sum(order_qty*unit_price) as totalAmount, max(order_qty*unit_price) as maxAmount from o_order_detail");
assertSql(query).contains("from o_order_detail where id > ? and order_id is not null group by order_id having sum(order_qty*unit_price) < ? order by sum(order_qty*unit_price) desc");
assertNotNull(list);
}
}
@@ -69,9 +69,9 @@ public class TestQueryForUpdate extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(2);
if (isH2() || isPostgres()) {
assertThat(sql.get(0)).contains("from e_basic t0 where t0.id =");
assertThat(sql.get(1)).contains("from e_basic t0 where t0.id =");
assertThat(sql.get(1)).contains("for update");
assertSql(sql.get(0)).contains("from e_basic t0 where t0.id =");
assertSql(sql.get(1)).contains("from e_basic t0 where t0.id =");
assertSql(sql.get(1)).contains("for update");
}
transaction.end();
@@ -43,7 +43,7 @@ public class TestQueryWhereInRange extends BaseTestCase {
query.findList();
assertThat(query.getGeneratedSql()).contains("where (t0.order_date = ? or t0.order_date is null)");
assertSql(query).contains("where (t0.order_date = ? or t0.order_date is null)");
}
@Test
@@ -59,7 +59,7 @@ public class TestQueryWhereInRange extends BaseTestCase {
query.findList();
assertThat(query.getGeneratedSql()).contains("where (t0.order_date > ? or t0.order_date is null)");
assertSql(query).contains("where (t0.order_date > ? or t0.order_date is null)");
}
@Test
@@ -75,7 +75,7 @@ public class TestQueryWhereInRange extends BaseTestCase {
query.findList();
assertThat(query.getGeneratedSql()).contains(" where (t0.order_date < ? or t0.order_date is null)");
assertSql(query).contains(" where (t0.order_date < ? or t0.order_date is null)");
}
@Test
@@ -91,6 +91,6 @@ public class TestQueryWhereInRange extends BaseTestCase {
query.findList();
assertThat(query.getGeneratedSql()).contains("(t0.order_date <= ? and (t0.ship_date > ? or t0.ship_date is null))");
assertSql(query).contains("(t0.order_date <= ? and (t0.ship_date > ? or t0.ship_date is null))");
}
}
@@ -67,7 +67,7 @@ public class TestQueryWithCache extends BaseTestCase {
Query<Country> query = Ebean.find(Country.class).setId("NZ").setUseCache(false);
query.findOne();
assertThat(query.getGeneratedSql()).isNotNull();
assertSql(query).isNotNull();
}
}
@@ -43,14 +43,14 @@ public class TestQueryAdapter extends BaseTestCase {
.update();
List<String> sql = LoggedSqlCollector.current();
assertThat(sql.get(0)).contains(" 2=2");
assertSql(sql.get(0)).contains(" 2=2");
Ebean.find(TOne.class)
.where().idEq(o.getId())
.delete();
sql = LoggedSqlCollector.stop();
assertThat(sql.get(0)).contains(" 3=3");
assertSql(sql.get(0)).contains(" 3=3");
}
}
@@ -66,8 +66,8 @@ public class TestBatchInsertFlush extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
// we get the 2 master inserts first
assertThat(sql.get(0)).contains("insert into t_atable_thatisrelatively");
assertThat(sql.get(1)).contains("-- bind(");
assertSql(sql.get(0)).contains("insert into t_atable_thatisrelatively");
assertSql(sql.get(1)).contains("-- bind(");
// detail
assertThat(sql.get(3)).contains("insert into t_detail_with_other_namexxxyy");
@@ -102,7 +102,7 @@ public class TestBatchInsertFlush extends BaseTestCase {
Ebean.find(Customer.class).findCount();
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql.get(0)).contains("select count(*)");
assertSql(sql.get(0)).contains("select count(*)");
}
@Test
@@ -118,7 +118,7 @@ public class TestBatchInsertFlush extends BaseTestCase {
Ebean.find(Customer.class).findCount();
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql.get(0)).contains("insert into e_basicver");
assertSql(sql.get(0)).contains("insert into e_basicver");
}
@Test
@@ -71,7 +71,7 @@ public class TestBatchLazyWithCacheHits extends BaseTestCase {
System.out.println("sql:" + sql);
assertThat(sql).hasSize(2);
assertThat(sql.get(0)).contains("from uuone t0 where t0.name like ");
assertSql(sql.get(0)).contains("from uuone t0 where t0.name like ");
platformAssertIn(sql.get(1), "from uuone t0 where t0.id");
// not lazy loading into bean cache
@@ -119,7 +119,7 @@ public class TestSecondaryQueries extends TransactionalTestCase {
assertThat(generatedSql).contains("from o_customer t0 where t0.id = ?");
assertEquals(2, sql.size());
assertThat(sql.get(1)).contains("from contact t0 where (t0.customer_id) ");
assertSql(sql.get(1)).contains("from contact t0 where (t0.customer_id) ");
platformAssertIn(sql.get(1), " where (t0.customer_id)");
}
+3 -3
View File
@@ -76,7 +76,7 @@ public class TestBeanCache extends BaseTestCase {
List<String> sql = LoggedSqlCollector.current();
assertThat(sql).hasSize(1);
if (isH2()) {
assertThat(sql.get(0)).contains("from o_cached_bean t0 where t0.id in (?,?,?,?,?)");
assertSql(sql.get(0)).contains("from o_cached_bean t0 where t0.id in (?,?,?,?,?)");
}
log.info("All hits (3 of 3) ...");
@@ -105,7 +105,7 @@ public class TestBeanCache extends BaseTestCase {
assertThat(sql).hasSize(1);
if (isH2()) {
// fetch the miss from DB
assertThat(sql.get(0)).contains("from o_cached_bean t0 where t0.id in (?)");
assertSql(sql.get(0)).contains("from o_cached_bean t0 where t0.id in (?)");
}
// remove beans so that we get a "partial" hit (1 out of 3 in cache)
@@ -124,7 +124,7 @@ public class TestBeanCache extends BaseTestCase {
assertThat(sql).hasSize(1);
if (isH2()) {
// fetch the misses from DB
assertThat(sql.get(0)).contains("from o_cached_bean t0 where t0.id in (?,?,?,?,?)");
assertSql(sql.get(0)).contains("from o_cached_bean t0 where t0.id in (?,?,?,?,?)");
}
}
+2 -2
View File
@@ -181,8 +181,8 @@ public class TestBeanFetchJoinCache extends BaseTestCase {
final List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(2);
assertThat(sql.get(0)).contains(" from o_order ");
assertThat(sql.get(1)).contains(" from o_customer ");
assertSql(sql.get(0)).contains(" from o_order ");
assertSql(sql.get(1)).contains(" from o_customer ");
}
private void initDataClearCache() {
@@ -50,8 +50,8 @@ public class TestMultiCascadeBatch extends BaseTestCase {
final List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(5);
assertThat(sql.get(0)).contains("insert into site (id, name");
assertThat(sql.get(1)).contains("insert into site (id, name");
assertSql(sql.get(0)).contains("insert into site (id, name");
assertSql(sql.get(1)).contains("insert into site (id, name");
assertSqlBind(sql.get(2));
assertThat(sql.get(3)).contains("insert into site (id, name");
assertSqlBind(sql.get(4));
@@ -26,12 +26,12 @@ public class TestOrderedList extends BaseTestCase {
List<String> sql = LoggedSqlCollector.current();
assertThat(sql.size()).isGreaterThan(1);
assertThat(sql.get(0)).contains("insert into om_ordered_master");
assertSql(sql.get(0)).contains("insert into om_ordered_master");
boolean hasId = sql.get(1).contains(" (id, name");
if (hasId) {
assertThat(sql.get(1)).contains("insert into om_ordered_detail (id, name, version, sort_order, master_id) values (?,?,?,?,?)");
assertSql(sql.get(1)).contains("insert into om_ordered_detail (id, name, version, sort_order, master_id) values (?,?,?,?,?)");
} else {
assertThat(sql.get(1)).contains("insert into om_ordered_detail (name, version, sort_order, master_id) values (?,?,?,?)");
assertSql(sql.get(1)).contains("insert into om_ordered_detail (name, version, sort_order, master_id) values (?,?,?,?)");
}
// update without any changes
@@ -46,7 +46,7 @@ public class TestOrderedList extends BaseTestCase {
Ebean.save(master);
sql = LoggedSqlCollector.current();
assertThat(sql).hasSize(1);
assertThat(sql.get(0)).contains("update om_ordered_master set name=?, version=?");
assertSql(sql.get(0)).contains("update om_ordered_master set name=?, version=?");
fetchAndReorder(master.getId());
}
@@ -57,7 +57,7 @@ public class TestOrderedList extends BaseTestCase {
List<OmOrderedDetail> details1 = fresh.getDetails();
List<String> sql = LoggedSqlCollector.current();
assertThat(sql.get(0)).contains("order by t0.id, t1.sort_order");
assertSql(sql.get(0)).contains("order by t0.id, t1.sort_order");
// fetched, not dirty
Ebean.save(fresh);
@@ -77,8 +77,8 @@ public class TestOrderedList extends BaseTestCase {
sql = LoggedSqlCollector.current();
assertThat(sql).hasSize(7);
assertThat(sql.get(0)).contains("update om_ordered_master set name=?, version=?");
assertThat(sql.get(1)).contains("update om_ordered_detail set version=?, sort_order=? where id=? and version=?");
assertSql(sql.get(0)).contains("update om_ordered_master set name=?, version=?");
assertSql(sql.get(1)).contains("update om_ordered_detail set version=?, sort_order=? where id=? and version=?");
details1.get(1).setName("was 1");
fresh.setName("m1-mod3");
@@ -86,8 +86,8 @@ public class TestOrderedList extends BaseTestCase {
sql = LoggedSqlCollector.current();
assertThat(sql).hasSize(8);
assertThat(sql.get(0)).contains("update om_ordered_master set name=?, version=?");
assertThat(sql.get(1)).contains("update om_ordered_detail set version=?, sort_order=? where id=? and version=?");
assertSql(sql.get(0)).contains("update om_ordered_master set name=?, version=?");
assertSql(sql.get(1)).contains("update om_ordered_detail set version=?, sort_order=? where id=? and version=?");
assertThat(sql.get(3)).contains("update om_ordered_detail set name=?, version=?, sort_order=? where id=? and version=?");
@@ -95,8 +95,8 @@ public class TestOrderedList extends BaseTestCase {
sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(3);
assertThat(sql.get(0)).contains("delete from om_ordered_detail where master_id = ?");
assertSql(sql.get(0)).contains("delete from om_ordered_detail where master_id = ?");
assertSqlBind(sql.get(1));
assertThat(sql.get(2)).contains("delete from om_ordered_master where id=? and version=?");
assertSql(sql.get(2)).contains("delete from om_ordered_master where id=? and version=?");
}
}
@@ -80,9 +80,9 @@ public class TestForeignKeyModes extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
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 = ?");
assertSql(sql.get(0)).contains("delete from dfk_none_via_mto_m_dfk_one where dfk_none_via_mto_m_id = ?");
assertSqlBind(sql.get(1));
assertThat(sql.get(2)).contains("delete from dfk_none_via_mto_m where id=?");
assertSql(sql.get(2)).contains("delete from dfk_none_via_mto_m where id=?");
}
@IgnorePlatform(Platform.NUODB)
@@ -124,7 +124,7 @@ public class TestForeignKeyModes extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(1);
assertThat(sql.get(0)).contains("delete from dfk_cascade_one where id=?");
assertSql(sql.get(0)).contains("delete from dfk_cascade_one where id=?");
DfkCascade found = Ebean.find(DfkCascade.class, other.getId());
assertThat(found).isNull();
@@ -109,11 +109,11 @@ public class TestDeleteByQuery extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
if (isPlatformSupportsDeleteTableAlias()) {
assertThat(sql.get(0)).contains("delete from bbookmark_user t0 where t0.id = ?");
assertThat(sql.get(1)).contains("delete from bbookmark_user t0 where t0.id = ?");
assertSql(sql.get(0)).contains("delete from bbookmark_user t0 where t0.id = ?");
assertSql(sql.get(1)).contains("delete from bbookmark_user t0 where t0.id = ?");
} else if (!isMySql()) {
assertThat(sql.get(0)).contains("delete from bbookmark_user where id = ?");
assertThat(sql.get(1)).contains("delete from bbookmark_user where id = ?");
assertSql(sql.get(0)).contains("delete from bbookmark_user where id = ?");
assertSql(sql.get(1)).contains("delete from bbookmark_user where id = ?");
}
// and note this is the easiest option
@@ -130,8 +130,8 @@ public class TestDeleteByQuery extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
// escalate to fetch ids then delete ... but no rows found
assertThat(sql.get(0)).contains("select t0.id from contact t0 where t0.id = ?");
assertThat(sql.get(1)).contains("select t0.id from contact t0 where t0.id = ?");
assertSql(sql.get(0)).contains("select t0.id from contact t0 where t0.id = ?");
assertSql(sql.get(1)).contains("select t0.id from contact t0 where t0.id = ?");
// and note this is the easiest option
Ebean.delete(Contact.class, 7000);
@@ -152,9 +152,9 @@ public class TestDeleteByQuery extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
if (isPlatformSupportsDeleteTableAlias()) {
assertThat(sql.get(0)).contains("delete from contact t0 where t0.id = ?");
assertSql(sql.get(0)).contains("delete from contact t0 where t0.id = ?");
} else if (!isMySql()){
assertThat(sql.get(0)).contains("delete from contact where id = ?");
assertSql(sql.get(0)).contains("delete from contact where id = ?");
}
}
@@ -171,9 +171,9 @@ public class TestDeleteByQuery extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(1);
if (isSqlServer()) {
assertThat(sql.get(0)).contains("select t0.id from o_customer t0 with (updlock) where t0.name = ?");
assertSql(sql.get(0)).contains("select t0.id from o_customer t0 with (updlock) where t0.name = ?");
} else {
assertThat(sql.get(0)).contains("select t0.id from o_customer t0 where t0.name = ?");
assertSql(sql.get(0)).contains("select t0.id from o_customer t0 where t0.name = ?");
}
}
@@ -29,8 +29,8 @@ public class TestDeleteCascadeWithListener extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
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=?");
assertSql(sql.get(0)).contains("select t0.id from dc_detail t0 where master_id=?");
assertSql(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=?");
}
@@ -19,7 +19,7 @@ public class TestUnderscoreParam extends BaseTestCase {
query.findList();
assertThat(query.getGeneratedSql()).contains("where t0.name like ?");
assertSql(query).contains("where t0.name like ?");
}
@@ -113,8 +113,8 @@ public class TestInheritInsert extends BaseTestCase {
Car result = query.findOne();
assertThat(query.getGeneratedSql()).contains("order by t0.id, t2.location_code");
assertThat(query.getGeneratedSql()).contains("left join car_fuse t2 on t2.id = t1.fuse_id");
assertSql(query).contains("order by t0.id, t2.location_code");
assertSql(query).contains("left join car_fuse t2 on t2.id = t1.fuse_id");
assertNotNull(result);
}
@@ -48,8 +48,8 @@ public class TestInheritanceQuery extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(4);
assertThat(sql.get(1)).contains("where t0.type = 'A'");
assertThat(sql.get(2)).contains("where t0.type = 'B'");
assertSql(sql.get(1)).contains("where t0.type = 'A'");
assertSql(sql.get(2)).contains("where t0.type = 'B'");
assertThat(sql.get(3)).contains("where t0.type = 'B'");
Ebean.delete(a);
@@ -89,7 +89,7 @@ public class TestInheritanceBothSides extends BaseTestCase {
final List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(1);
assertThat(sql.get(0)).contains("select t0.dtype, t0.id, t0.name, t0.pos, t1.dtype, t1.id, t1.name from source_base t0 left join target_base t1 on t1.id = t0.target_id where t0.dtype = 'SourceA' order by t0.pos");
assertSql(sql.get(0)).contains("select t0.dtype, t0.id, t0.name, t0.pos, t1.dtype, t1.id, t1.name from source_base t0 left join target_base t1 on t1.id = t0.target_id where t0.dtype = 'SourceA' order by t0.pos");
}
/**
@@ -116,10 +116,10 @@ public class TestInheritanceBothSides extends BaseTestCase {
final List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(3);
//assertThat(sql.get(0)).contains("select t0.dtype, t0.id, t0.name, t0.pos, t0.target_id, t0.target_id from source_base t0 order by t0.pos");
assertThat(sql.get(0)).contains("select t0.dtype, t0.id, t0.name, t0.pos, t1.dtype, t0.target_id, t1.dtype, t0.target_id from source_base t0 left join target_base t1 on t1.id = t0.target_id order by t0.pos");
assertThat(sql.get(1)).contains("select t0.dtype, t0.id, t0.name from target_base t0 where t0.dtype = 'Target1' and t0.id ");
assertThat(sql.get(2)).contains("select t0.dtype, t0.id, t0.name from target_base t0 where t0.dtype = 'Target2' and t0.id = ?");
//assertSql(sql.get(0)).contains("select t0.dtype, t0.id, t0.name, t0.pos, t0.target_id, t0.target_id from source_base t0 order by t0.pos");
assertSql(sql.get(0)).contains("select t0.dtype, t0.id, t0.name, t0.pos, t1.dtype, t0.target_id, t1.dtype, t0.target_id from source_base t0 left join target_base t1 on t1.id = t0.target_id order by t0.pos");
assertSql(sql.get(1)).contains("select t0.dtype, t0.id, t0.name from target_base t0 where t0.dtype = 'Target1' and t0.id ");
assertSql(sql.get(2)).contains("select t0.dtype, t0.id, t0.name from target_base t0 where t0.dtype = 'Target2' and t0.id = ?");
}
private void assertSourceBaseEqual(SourceBase foundA, SourceBase sourceA) {
@@ -40,7 +40,7 @@ public class TestInheritanceRefCache extends BaseTestCase {
assertThat(gotRef.getRef()).isInstanceOf(CInhOne.class);
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(1);
assertThat(sql.get(0)).contains("from cinh_ref").contains("left join cinh_root");
assertSql(sql.get(0)).contains("from cinh_ref").contains("left join cinh_root");
// fetch again - from cache (but fetch second bean from cache)
LoggedSqlCollector.start();
@@ -50,7 +50,7 @@ public class TestInheritanceRefCache extends BaseTestCase {
assertThat(gotRef.getRef()).isInstanceOf(CInhOne.class);
sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(1);
assertThat(sql.get(0)).contains("from cinh_root");
assertSql(sql.get(0)).contains("from cinh_root");
// fetch again - both from cache
@@ -91,7 +91,7 @@ public class TestInheritanceRefCache extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(1);
assertThat(sql.get(0)).contains("from cinh_root");
assertSql(sql.get(0)).contains("from cinh_root");
// try some cache finds
Ebean.find(CInhRoot.class).setUseQueryCache(true).findList();
@@ -28,6 +28,6 @@ public class TestOnlyIdEntity extends BaseTestCase {
assertThat(bean.getId()).isGreaterThan(0);
assertThat(sql).hasSize(1);
assertThat(sql.get(0)).contains("insert into only_id_entity default values");
assertSql(sql.get(0)).contains("insert into only_id_entity default values");
}
}
@@ -87,8 +87,8 @@ public class TestCarWheelIud extends BaseTestCase {
final List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(2);
if (isH2() || isPostgres()) {
assertThat(sql.get(0)).contains("select t0.brand, sum(t0.sold) from sa_car t0 group by t0.brand limit 10");
assertThat(sql.get(1)).contains("select count(*) from ( select t0.brand, sum(t0.sold) from sa_car t0 group by t0.brand)");
assertSql(sql.get(0)).contains("select t0.brand, sum(t0.sold) from sa_car t0 group by t0.brand limit 10");
assertSql(sql.get(1)).contains("select count(*) from ( select t0.brand, sum(t0.sold) from sa_car t0 group by t0.brand)");
}
}
@@ -27,8 +27,8 @@ public class TestPersistCascade extends BaseTestCase {
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");
assertSql(sql.get(0)).contains("insert into pcf_country");
assertSql(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);
@@ -111,7 +111,7 @@ public class TestDbJson_List extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
// we don't update the phone numbers (as they are not dirty)
assertThat(sql.get(0)).contains("update ebasic_json_list set name=?, plain_bean=?, version=? where");
assertSql(sql.get(0)).contains("update ebasic_json_list set name=?, plain_bean=?, version=? where");
}
public void update_when_dirty() {
@@ -124,7 +124,7 @@ public class TestDbJson_List extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
// we don't update the phone numbers (as they are not dirty)
assertThat(sql.get(0)).contains("update ebasic_json_list set plain_bean=?, tags=?, version=? where id=? and version=?");
assertSql(sql.get(0)).contains("update ebasic_json_list set plain_bean=?, tags=?, version=? where id=? and version=?");
}
public void update_when_dirty_flags() {
@@ -137,7 +137,7 @@ public class TestDbJson_List extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
// we don't update the phone numbers (as they are not dirty)
assertThat(sql.get(0)).contains("update ebasic_json_list set plain_bean=?, flags=?, version=? where id=? and version=?;");
assertSql(sql.get(0)).contains("update ebasic_json_list set plain_bean=?, flags=?, version=? where id=? and version=?;");
}
public void update_when_dirty_SetListMap() {
@@ -152,7 +152,7 @@ public class TestDbJson_List extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
// we don't update the phone numbers (as they are not dirty)
assertThat(sql.get(0)).contains("update ebasic_json_list set bean_set=?, bean_list=?, bean_map=?, plain_bean=?, version=? where id=? and version=?");
assertSql(sql.get(0)).contains("update ebasic_json_list set bean_set=?, bean_list=?, bean_map=?, plain_bean=?, version=? where id=? and version=?");
}
@Test
@@ -79,7 +79,7 @@ public class TestLazyForeignKeys extends BaseTestCase {
List<MainEntityRelation> list = query.findList();
assertEquals(1, list.size());
assertThat(query.getGeneratedSql()).contains("t0.id, t0.attr1, t0.id1, t0.id2, t1.id, t2.id");
assertSql(query).contains("t0.id, t0.attr1, t0.id1, t0.id2, t1.id, t2.id");
MainEntityRelation rel1 = list.get(0);
assertEquals("ent1", rel1.getEntity1().getId());
@@ -48,8 +48,8 @@ public class TestM2MDeleteNoCascade extends BaseTestCase {
final List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(2);
assertThat(sql.get(0)).contains("delete from mnoc_user_mnoc_role where mnoc_user_user_id = ?");
assertThat(sql.get(1)).contains("delete from mnoc_user where user_id=? and version=?");
assertSql(sql.get(0)).contains("delete from mnoc_user_mnoc_role where mnoc_user_user_id = ?");
assertSql(sql.get(1)).contains("delete from mnoc_user where user_id=? and version=?");
final MnocUser found = DB.find(MnocUser.class, u0.getUserId());
assertThat(found).isNull();
@@ -76,8 +76,8 @@ public class TestM2MDeleteNoCascade extends BaseTestCase {
final List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(5);
assertThat(sql.get(0)).contains("update mnoc_user set user_name=?, version=? where user_id=? and version=?");
assertThat(sql.get(1)).contains("delete from mnoc_user_mnoc_role where mnoc_user_user_id = ?");
assertSql(sql.get(0)).contains("update mnoc_user set user_name=?, version=? where user_id=? and version=?");
assertSql(sql.get(1)).contains("delete from mnoc_user_mnoc_role where mnoc_user_user_id = ?");
assertSqlBind(sql.get(2));
assertThat(sql.get(3)).contains("insert into mnoc_user_mnoc_role (mnoc_user_user_id, mnoc_role_role_id) values (?, ?)");
assertSqlBind(sql.get(4));
@@ -108,9 +108,9 @@ public class TestM2MDeleteNoCascade extends BaseTestCase {
final List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(8);
assertThat(sql.get(0)).contains("delete from mnoc_user_mnoc_role where mnoc_user_user_id = ?");
assertSql(sql.get(0)).contains("delete from mnoc_user_mnoc_role where mnoc_user_user_id = ?");
assertThat(sql.get(4)).contains("delete from mnoc_user_mnoc_role where mnoc_user_user_id = ?");
assertThat(sql.get(2)).contains("delete from mnoc_user where user_id=? and version=?");
assertSql(sql.get(2)).contains("delete from mnoc_user where user_id=? and version=?");
assertThat(sql.get(6)).contains("delete from mnoc_user where user_id=? and version=?");
}
}
@@ -50,13 +50,13 @@ public class TestMergeBasic extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
// fetch the Ids ... used to identity inserts, updates and deletes
assertThat(sql.get(0)).contains("select t0.id, t1.id from uuone t0 left join uutwo t1 on t1.master_id = t0.id where t0.id = ?");
assertSql(sql.get(0)).contains("select t0.id, t1.id from uuone t0 left join uutwo t1 on t1.master_id = t0.id where t0.id = ?");
// deletes of Ids that are no longer in the graph
assertThat(sql.get(1)).contains("delete from uutwo where id=?");
assertSql(sql.get(1)).contains("delete from uutwo where id=?");
// cascade persist ... master
assertThat(sql.get(2)).contains("update uuone set name=?, description=?, version=? where id=? and version=?");
assertSql(sql.get(2)).contains("update uuone set name=?, description=?, version=? where id=? and version=?");
// persist children ...
if (isPersistBatchOnCascade()) {
@@ -98,13 +98,13 @@ public class TestMergeBasic extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
// fetch the Ids ... used to identity inserts, updates and deletes
assertThat(sql.get(0)).contains("select t0.id, t1.id from uuone t0 left join uutwo t1 on t1.master_id = t0.id where t0.id = ?");
assertSql(sql.get(0)).contains("select t0.id, t1.id from uuone t0 left join uutwo t1 on t1.master_id = t0.id where t0.id = ?");
// deletes of Ids that are no longer in the graph
assertThat(sql.get(1)).contains("delete from uutwo where id=?");
assertSql(sql.get(1)).contains("delete from uutwo where id=?");
// cascade persist ... master
assertThat(sql.get(2)).contains("update uuone set name=?, description=?, version=? where id=? and version=?");
assertSql(sql.get(2)).contains("update uuone set name=?, description=?, version=? where id=? and version=?");
// persist children ...
if (isPersistBatchOnCascade()) {
@@ -32,7 +32,7 @@ public class TestMergeCustomer extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(1);
assertThat(sql.get(0)).contains("update mcustomer set name=?, version=? where id=? and version=?");
assertSql(sql.get(0)).contains("update mcustomer set name=?, version=? where id=? and version=?");
}
/**
@@ -54,7 +54,7 @@ public class TestMergeCustomer extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(1);
assertThat(sql.get(0)).contains("update mcustomer set name=?, version=? where id=? and version=?");
assertSql(sql.get(0)).contains("update mcustomer set name=?, version=? where id=? and version=?");
}
@Test
@@ -72,8 +72,8 @@ public class TestMergeCustomer extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(2);
assertThat(sql.get(0)).contains("select t0.id from mcustomer t0 where t0.id = ?");
assertThat(sql.get(1)).contains("update mcustomer set name=?, version=? where id=? and version=?");
assertSql(sql.get(0)).contains("select t0.id from mcustomer t0 where t0.id = ?");
assertSql(sql.get(1)).contains("update mcustomer set name=?, version=? where id=? and version=?");
}
@Test
@@ -96,8 +96,8 @@ public class TestMergeCustomer extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
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=?");
assertSql(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 = ?");
assertSql(sql.get(1)).contains("update maddress set street=?, city=?, version=? 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=?");
}
@@ -125,8 +125,8 @@ public class TestMergeCustomer extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
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("insert into maddress (id, street, city, version) values (?,?,?,?)");
assertSql(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 = ?");
assertSql(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));
@@ -158,11 +158,11 @@ public class TestMergeCustomer extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
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 = ?");
assertSql(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("insert into maddress (id, street, city, version) values (?,?,?,?)");
assertSql(sql.get(1)).contains("select t0.id from maddress t0 where t0.id = ?");
assertSql(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));
@@ -217,8 +217,8 @@ public class TestMergeCustomer extends BaseTestCase {
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 = ?");
assertSql(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 = ?");
assertSql(sql.get(1)).contains("delete from mcontact_message where contact_id = ?");
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=?");
}
@@ -243,8 +243,8 @@ public class TestMergeCustomer extends BaseTestCase {
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 = ?");
assertSql(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 = ?");
assertSql(sql.get(1)).contains("delete from mcontact_message where contact_id = ?");
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=?");
}
@@ -280,8 +280,8 @@ public class TestMergeCustomer extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
if (isPersistBatchOnCascade()) {
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 = ?");
assertSql(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 = ?");
assertSql(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=?");
}
@@ -320,12 +320,12 @@ public class TestMergeCustomer extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
if (isPersistBatchOnCascade()) {
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 = ?");
assertSql(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 (?,?,?,?,?,?,?,?,?,?)");
assertSql(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 = ?");
assertSql(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=?");
@@ -42,15 +42,15 @@ public class TestMergeM2M extends BaseTestCase {
List<String> sql = LoggedSqlCollector.current();
if (isPersistBatchOnCascade()) {
assertThat(sql).hasSize(6);
assertThat(sql.get(0)).contains("select");
assertThat(sql.get(1)).contains("insert into mmachine");
assertThat(sql.get(2)).contains("insert into mmachine_mgroup");
assertSql(sql.get(0)).contains("select");
assertSql(sql.get(1)).contains("insert into mmachine");
assertSql(sql.get(2)).contains("insert into mmachine_mgroup");
assertSqlBind(sql, 3, 5);
} else {
assertThat(sql).hasSize(5);
assertThat(sql.get(0)).contains("select");
assertThat(sql.get(1)).contains("insert into mmachine");
assertThat(sql.get(2)).contains("insert into mmachine_mgroup");
assertSql(sql.get(0)).contains("select");
assertSql(sql.get(1)).contains("insert into mmachine");
assertSql(sql.get(2)).contains("insert into mmachine_mgroup");
assertThat(sql.get(3)).contains("insert into mmachine_mgroup");
assertThat(sql.get(4)).contains("insert into mmachine_mgroup");
}
@@ -67,8 +67,8 @@ public class TestMergeM2M extends BaseTestCase {
sql = LoggedSqlCollector.current();
assertThat(sql).hasSize(9);
assertThat(sql.get(0)).contains("select");
assertThat(sql.get(1)).contains("delete from mmachine_mgroup");
assertSql(sql.get(0)).contains("select");
assertSql(sql.get(1)).contains("delete from mmachine_mgroup");
assertSqlBind(sql, 2, 4);
assertThat(sql.get(5)).contains("insert into mmachine_mgroup");
@@ -2,6 +2,7 @@ package org.tests.model.aggregation;
import io.ebean.Model;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
@@ -22,6 +23,7 @@ public class DMachineAuxUse extends Model {
private String name;
@Column(name="edate")
private LocalDate date;
private long useSecs;
@@ -3,6 +3,7 @@ package org.tests.model.aggregation;
import io.ebean.annotation.Sum;
import io.ebean.annotation.View;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import java.math.BigDecimal;
@@ -17,6 +18,7 @@ public class DMachineAuxUseAgg {
private String name;
@Column(name="edate")
private LocalDate date;
@Sum
@@ -1,5 +1,6 @@
package org.tests.model.aggregation;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
@@ -18,6 +19,7 @@ public class DMachineStats {
@ManyToOne(optional = false)
DMachine machine;
@Column(name="edate")
LocalDate date;
long totalKms;
@@ -5,6 +5,7 @@ import io.ebean.annotation.Max;
import io.ebean.annotation.Sum;
import io.ebean.annotation.View;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import java.math.BigDecimal;
@@ -17,6 +18,7 @@ public class DMachineStatsAgg {
@ManyToOne
DMachine machine;
@Column(name="edate")
LocalDate date;
@Sum // which is the same as: @Aggregation("sum(totalKms)")
@@ -2,6 +2,7 @@ package org.tests.model.aggregation;
import io.ebean.Model;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
@@ -20,6 +21,7 @@ public class DMachineUse extends Model {
@ManyToOne(optional = false)
private DMachine machine;
@Column(name="edate")
private LocalDate date;
private long distanceKms;
@@ -32,11 +32,11 @@ public class TestAggregationMany extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(2);
assertThat(sql.get(0)).contains("select t0.id, t0.name, t0.version, t0.organisation_id from dmachine t0 where t0.organisation_id = ?");
assertSql(sql.get(0)).contains("select t0.id, t0.name, t0.version, t0.organisation_id from dmachine t0 where t0.organisation_id = ?");
assertThat(machines).hasSize(5);
if (isH2()) {
assertThat(sql.get(1)).contains("select t0.machine_id, t0.name, sum(t0.use_secs), sum(t0.fuel) from d_machine_aux_use t0 where (t0.machine_id) in (?,?,?,?,?) group by t0.machine_id, t0.name;");
assertSql(sql.get(1)).contains("select t0.machine_id, t0.name, sum(t0.use_secs), sum(t0.fuel) from d_machine_aux_use t0 where (t0.machine_id) in (?,?,?,?,?) group by t0.machine_id, t0.name;");
}
}
@@ -63,7 +63,7 @@ public class TestAggregationMany extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(1);
assertThat(sql.get(0)).contains("select t0.id, t0.name, t1.name, sum(t1.use_secs), sum(t1.fuel) from dmachine t0 left join d_machine_aux_use t1 on t1.machine_id = t0.id where t0.organisation_id = ? group by t0.id, t0.name, t1.name order by t0.id");
assertSql(sql.get(0)).contains("select t0.id, t0.name, t1.name, sum(t1.use_secs), sum(t1.fuel) from dmachine t0 left join d_machine_aux_use t1 on t1.machine_id = t0.id where t0.organisation_id = ? group by t0.id, t0.name, t1.name order by t0.id");
}
@Test
@@ -89,6 +89,6 @@ public class TestAggregationMany extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(1);
assertThat(sql.get(0)).contains("select t0.id, t0.name, sum(t1.use_secs), sum(t1.fuel) from dmachine t0 left join d_machine_aux_use t1 on t1.machine_id = t0.id where t0.organisation_id = ? group by t0.id, t0.name order by t0.id");
assertSql(sql.get(0)).contains("select t0.id, t0.name, sum(t1.use_secs), sum(t1.fuel) from dmachine t0 left join d_machine_aux_use t1 on t1.machine_id = t0.id where t0.organisation_id = ? group by t0.id, t0.name order by t0.id");
}
}
@@ -29,7 +29,7 @@ public class TestAggregationTopLevel extends BaseTestCase {
.query();
List<DMachineStatsAgg> result = query.findList();
assertThat(sqlOf(query)).contains("select t0.date, t0.machine_id from d_machine_stats t0 where t0.date > ?");
assertThat(sqlOf(query)).contains("select t0.edate, t0.machine_id from d_machine_stats t0 where t0.edate > ?");
assertThat(result).isNotEmpty();
}
@@ -50,10 +50,10 @@ public class TestAggregationTopLevel extends BaseTestCase {
assertThat(sql).hasSize(2);
if (isH2() || isPostgres()) {
assertThat(sql.get(0)).contains("select count(*) from ( select t0.date, sum(t0.total_kms) from d_machine_stats t0 group by t0.date having sum(t0.total_kms) > ?)");
assertThat(sql.get(1)).contains("select t0.date, sum(t0.total_kms) from d_machine_stats t0 group by t0.date having sum(t0.total_kms) > ? limit 10");
assertSql(sql.get(0)).contains("select count(*) from ( select t0.edate, sum(t0.total_kms) from d_machine_stats t0 group by t0.edate having sum(t0.total_kms) > ?)");
assertSql(sql.get(1)).contains("select t0.edate, sum(t0.total_kms) from d_machine_stats t0 group by t0.edate having sum(t0.total_kms) > ? limit 10");
} else if (isSqlServer()) {
assertThat(sql.get(0)).contains("select count(*) from ( select t0.date c0, sum(t0.total_kms) c1 from d_machine_stats t0 group by t0.date having sum(t0.total_kms) > ?) as c");
assertSql(sql.get(0)).contains("select count(*) from ( select t0.edate c0, sum(t0.total_kms) c1 from d_machine_stats t0 group by t0.edate having sum(t0.total_kms) > ?) as c");
}
}
@@ -67,7 +67,7 @@ public class TestAggregationTopLevel extends BaseTestCase {
.query();
List<DMachineStatsAgg> result = query.findList();
assertThat(sqlOf(query)).contains("select t0.machine_id, t0.date, sum(t0.total_kms), sum(cost) from d_machine_stats t0 where t0.date > ? group by t0.machine_id, t0.date having sum(cost) > ?");
assertThat(sqlOf(query)).contains("select t0.machine_id, t0.edate, sum(t0.total_kms), sum(cost) from d_machine_stats t0 where t0.edate > ? group by t0.machine_id, t0.edate having sum(cost) > ?");
assertThat(result).isNotEmpty();
}
@@ -80,7 +80,7 @@ public class TestAggregationTopLevel extends BaseTestCase {
.query();
List<DMachineStatsAgg> result = query.findList();
assertThat(sqlOf(query)).contains("select t0.machine_id, sum(t0.total_kms), sum(cost) from d_machine_stats t0 where t0.date > ? group by t0.machine_id");
assertThat(sqlOf(query)).contains("select t0.machine_id, sum(t0.total_kms), sum(cost) from d_machine_stats t0 where t0.edate > ? group by t0.machine_id");
assertThat(result).isNotEmpty();
}
@@ -94,7 +94,7 @@ public class TestAggregationTopLevel extends BaseTestCase {
.query();
List<DMachineStatsAgg> result = query.findList();
assertThat(sqlOf(query)).contains("select t0.date, sum(t0.total_kms), sum(t0.hours), max(t0.rate), sum(cost), max(t0.total_kms) from d_machine_stats t0 where t0.date > ? group by t0.date having sum(t0.hours) > ?");
assertThat(sqlOf(query)).contains("select t0.edate, sum(t0.total_kms), sum(t0.hours), max(t0.rate), sum(cost), max(t0.total_kms) from d_machine_stats t0 where t0.edate > ? group by t0.edate having sum(t0.hours) > ?");
assertThat(result).isNotEmpty();
}
@@ -108,7 +108,7 @@ public class TestAggregationTopLevel extends BaseTestCase {
.query();
List<DMachineStats> result = query.findList();
assertThat(sqlOf(query)).contains("select t0.machine_id, t0.date, sum(t0.total_kms), sum(t0.hours) from d_machine_stats t0 where t0.date > ? group by t0.machine_id, t0.date having sum(t0.hours) > ?");
assertThat(sqlOf(query)).contains("select t0.machine_id, t0.edate, sum(t0.total_kms), sum(t0.hours) from d_machine_stats t0 where t0.edate > ? group by t0.machine_id, t0.edate having sum(t0.hours) > ?");
assertThat(result).isNotEmpty();
}
@@ -122,7 +122,7 @@ public class TestAggregationTopLevel extends BaseTestCase {
.query();
List<DMachineStats> result = query.findList();
assertThat(sqlOf(query)).contains("select t0.machine_id, sum(t0.total_kms) from d_machine_stats t0 where t0.date > ? group by t0.machine_id having sum(t0.hours) > ?");
assertThat(sqlOf(query)).contains("select t0.machine_id, sum(t0.total_kms) from d_machine_stats t0 where t0.edate > ? group by t0.machine_id having sum(t0.hours) > ?");
assertThat(result).isNotEmpty();
}
@@ -143,7 +143,7 @@ public class TestAggregationTopLevel extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(1);
assertThat(sql.get(0)).contains("select sum(t0.total_kms), sum(t0.hours), t1.id, t1.name from d_machine_stats t0 join dmachine t1 on t1.id = t0.machine_id where t0.date > ? group by t1.id, t1.name having sum(t0.hours) > ?");
assertSql(sql.get(0)).contains("select sum(t0.total_kms), sum(t0.hours), t1.id, t1.name from d_machine_stats t0 join dmachine t1 on t1.id = t0.machine_id where t0.edate > ? group by t1.id, t1.name having sum(t0.hours) > ?");
}
@Test
@@ -163,7 +163,7 @@ public class TestAggregationTopLevel extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(1);
assertThat(sql.get(0)).contains("select t0.date, sum(t0.total_kms), sum(t0.hours), t1.id, t1.name from d_machine_stats t0 join dmachine t1 on t1.id = t0.machine_id where t0.date > ? group by t0.date, t1.id, t1.name having sum(t0.hours) > ?");
assertSql(sql.get(0)).contains("select t0.edate, sum(t0.total_kms), sum(t0.hours), t1.id, t1.name from d_machine_stats t0 join dmachine t1 on t1.id = t0.machine_id where t0.edate > ? group by t0.edate, t1.id, t1.name having sum(t0.hours) > ?");
}
@@ -185,8 +185,8 @@ public class TestAggregationTopLevel extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(2);
assertThat(sql.get(0)).contains("select sum(t0.total_kms), sum(t0.hours), t0.machine_id from d_machine_stats t0 where t0.date > ? group by t0.machine_id having sum(t0.hours) > ?");
assertThat(sql.get(1)).contains("select t0.id, t0.name from dmachine t0 where t0.id");
assertSql(sql.get(0)).contains("select sum(t0.total_kms), sum(t0.hours), t0.machine_id from d_machine_stats t0 where t0.edate > ? group by t0.machine_id having sum(t0.hours) > ?");
assertSql(sql.get(1)).contains("select t0.id, t0.name from dmachine t0 where t0.id");
}
@Test
@@ -207,8 +207,8 @@ public class TestAggregationTopLevel extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(2);
assertThat(sql.get(0)).contains("select t0.date, sum(t0.total_kms), sum(t0.hours), t0.machine_id from d_machine_stats t0 where t0.date > ? group by t0.date, t0.machine_id having sum(t0.hours) > ?");
assertThat(sql.get(1)).contains("select t0.id, t0.name from dmachine t0 where t0.id");
assertSql(sql.get(0)).contains("select t0.edate, sum(t0.total_kms), sum(t0.hours), t0.machine_id from d_machine_stats t0 where t0.edate > ? group by t0.edate, t0.machine_id having sum(t0.hours) > ?");
assertSql(sql.get(1)).contains("select t0.id, t0.name from dmachine t0 where t0.id");
}
@Test
@@ -220,7 +220,7 @@ public class TestAggregationTopLevel extends BaseTestCase {
.query();
List<DMachineStats> result = query.findList();
assertThat(sqlOf(query)).contains("select t0.machine_id, t0.date, max(t0.rate) from d_machine_stats t0 where t0.date > ? group by t0.machine_id, t0.date");
assertThat(sqlOf(query)).contains("select t0.machine_id, t0.edate, max(t0.rate) from d_machine_stats t0 where t0.edate > ? group by t0.machine_id, t0.edate");
assertThat(result).isNotEmpty();
}
@@ -268,7 +268,7 @@ public class TestAggregationTopLevel extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(1);
assertThat(sqlOf(query)).contains("select t0.id, t0.name, t1.date, max(t1.rate), sum(t1.total_kms) from dmachine t0 left join d_machine_stats t1 on t1.machine_id = t0.id where t0.name = ? group by t0.id, t0.name, t1.date order by t0.id");
assertThat(sqlOf(query)).contains("select t0.id, t0.name, t1.edate, max(t1.rate), sum(t1.total_kms) from dmachine t0 left join d_machine_stats t1 on t1.machine_id = t0.id where t0.name = ? group by t0.id, t0.name, t1.edate order by t0.id");
}
@@ -63,10 +63,10 @@ public class TestDbArray_asSet extends BaseTestCase {
List<EArraySetBean> list = query.findList();
assertThat(query.getGeneratedSql()).contains(" t0.other_ids @> array[?,?]::bigint[] ");
assertThat(query.getGeneratedSql()).contains(" t0.uids @> array[?] ");
assertThat(query.getGeneratedSql()).contains(" t0.phone_numbers @> array[?] ");
assertThat(query.getGeneratedSql()).contains(" coalesce(cardinality(t0.phone_numbers),0) <> 0");
assertSql(query).contains(" t0.other_ids @> array[?,?]::bigint[] ");
assertSql(query).contains(" t0.uids @> array[?] ");
assertSql(query).contains(" t0.phone_numbers @> array[?] ");
assertSql(query).contains(" coalesce(cardinality(t0.phone_numbers),0) <> 0");
assertThat(list).hasSize(1);
query = Ebean.find(EArraySetBean.class)
@@ -76,8 +76,8 @@ public class TestDbArray_asSet extends BaseTestCase {
.query();
query.findList();
assertThat(query.getGeneratedSql()).contains(" coalesce(cardinality(t0.other_ids),0) = 0");
assertThat(query.getGeneratedSql()).contains(" not (t0.uids @> array[?])");
assertSql(query).contains(" coalesce(cardinality(t0.other_ids),0) = 0");
assertSql(query).contains(" not (t0.uids @> array[?])");
}
json_parse_format();
@@ -108,7 +108,7 @@ public class TestDbArray_asSet extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
// we don't update the phone numbers (as they are not dirty)
assertThat(sql.get(0)).contains("update earray_set_bean set name=?, version=? where");
assertSql(sql.get(0)).contains("update earray_set_bean set name=?, version=? where");
}
//@Test//(dependsOnMethods = "update_when_notDirty")
@@ -121,7 +121,7 @@ public class TestDbArray_asSet extends BaseTestCase {
Ebean.save(found);
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql.get(0)).contains("update earray_set_bean set phone_numbers=?, uids=?, version=? where");
assertSql(sql.get(0)).contains("update earray_set_bean set phone_numbers=?, uids=?, version=? where");
}
@Test
@@ -94,10 +94,10 @@ public class TestDbArray_basic extends BaseTestCase {
assertThat(intEnums).containsExactly(IntEnum.ZERO, IntEnum.TWO);
assertThat(varcharEnums).containsExactly(VarcharEnum.ONE, VarcharEnum.TWO);
assertThat(query.getGeneratedSql()).contains(" t0.other_ids @> array[?,?]::bigint[] ");
assertThat(query.getGeneratedSql()).contains(" t0.uids @> array[?] ");
assertThat(query.getGeneratedSql()).contains(" t0.phone_numbers @> array[?] ");
assertThat(query.getGeneratedSql()).contains(" coalesce(cardinality(t0.phone_numbers),0) <> 0");
assertSql(query).contains(" t0.other_ids @> array[?,?]::bigint[] ");
assertSql(query).contains(" t0.uids @> array[?] ");
assertSql(query).contains(" t0.phone_numbers @> array[?] ");
assertSql(query).contains(" coalesce(cardinality(t0.phone_numbers),0) <> 0");
assertThat(list).hasSize(1);
query = Ebean.find(EArrayBean.class)
@@ -116,8 +116,8 @@ public class TestDbArray_basic extends BaseTestCase {
final Integer[] ints = (Integer[]) ((java.sql.Array) row.get("int_enums")).getArray();
assertThat(ints).containsExactly(100, 102);
assertThat(query.getGeneratedSql()).contains(" coalesce(cardinality(t0.other_ids),0) = 0");
assertThat(query.getGeneratedSql()).contains(" not (t0.uids @> array[?])");
assertSql(query).contains(" coalesce(cardinality(t0.other_ids),0) = 0");
assertSql(query).contains(" not (t0.uids @> array[?])");
}
json_parse_format();
@@ -148,7 +148,7 @@ public class TestDbArray_basic extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
// we don't update the phone numbers (as they are not dirty)
assertThat(sql.get(0)).contains("update earray_bean set name=?, version=? where");
assertSql(sql.get(0)).contains("update earray_bean set name=?, version=? where");
}
//@Test//(dependsOnMethods = "update_when_notDirty")
@@ -161,7 +161,7 @@ public class TestDbArray_basic extends BaseTestCase {
Ebean.save(found);
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql.get(0)).contains("update earray_bean set phone_numbers=?, uids=?, version=? where");
assertSql(sql.get(0)).contains("update earray_bean set phone_numbers=?, uids=?, version=? where");
}
@Test
@@ -23,7 +23,7 @@ public class UTMaster extends Model {
String description;
LocalDate date;
LocalDate eventDate;
@Version
Integer version;
@@ -55,12 +55,12 @@ public class UTMaster extends Model {
this.name = name;
}
public LocalDate getDate() {
return date;
public LocalDate getEventDate() {
return eventDate;
}
public void setDate(LocalDate date) {
this.date = date;
public void setEventDate(LocalDate eventDate) {
this.eventDate = eventDate;
}
public String getDescription() {
@@ -5,21 +5,21 @@ import io.ebean.annotation.Cache;
import javax.persistence.Entity;
import java.util.UUID;
@Cache(naturalKey = "uid")
@Cache(naturalKey = "cid")
@Entity
public class OCachedNkeyUid extends OCacheBase {
private UUID uid;
private UUID cid;
private String other;
public OCachedNkeyUid(UUID uid, String other) {
this.uid = uid;
public OCachedNkeyUid(UUID cid, String other) {
this.cid = cid;
this.other = other;
}
public UUID getUid() {
return uid;
public UUID getCid() {
return cid;
}
public String getOther() {
@@ -110,7 +110,7 @@ public class TestCacheViaComplexNaturalKey extends BaseTestCase {
assertThat(sql).hasSize(1);
if (isH2()) {
// in clause with only 1 bind param - (sku=3 ... we got hits on sku 1 and 2)
assertThat(sql.get(0)).contains("from o_cached_natkey t0 where t0.store = ? and t0.sku in (?) order by t0.sku desc; --bind(abc,Array[1]={3})");
assertSql(sql.get(0)).contains("from o_cached_natkey t0 where t0.store = ? and t0.sku in (?) order by t0.sku desc; --bind(abc,Array[1]={3})");
}
assertThat(list).hasSize(3);
@@ -149,7 +149,7 @@ public class TestCacheViaComplexNaturalKey extends BaseTestCase {
assertThat(list).hasSize(3);
assertThat(sql).hasSize(1);
if (isH2()) {
assertThat(sql.get(0)).contains("where t0.store = ? and t0.sku in (?,?) order by t0.sku desc; --bind(abc,Array[2]={1,3})");
assertSql(sql.get(0)).contains("where t0.store = ? and t0.sku in (?,?) order by t0.sku desc; --bind(abc,Array[2]={1,3})");
}
assertNaturalKeyHitMiss(1, 2);
assertBeanCacheHitMiss(1, 0);
@@ -207,7 +207,7 @@ public class TestCacheViaComplexNaturalKey extends BaseTestCase {
assertThat(sql).hasSize(1);
if (isH2()) {
// in clause with 2 bind params as we got not hits on the cache
assertThat(sql.get(0)).contains("from o_cached_natkey t0 where t0.store = ? and t0.sku in (?,?) order by t0.sku desc; --bind(abc,Array[2]={3,4})");
assertSql(sql.get(0)).contains("from o_cached_natkey t0 where t0.store = ? and t0.sku in (?,?) order by t0.sku desc; --bind(abc,Array[2]={3,4})");
}
assertThat(list).hasSize(2);
@@ -146,7 +146,7 @@ public class TestCacheViaComplexNaturalKey3 extends BaseTestCase {
assertThat(sql).hasSize(1);
if (isH2()) {
// in clause with only 1 bind param - miss on 1000
assertThat(sql.get(0)).contains("from o_cached_natkey3 t0 where t0.store = ? and t0.sku = ? and t0.code in (?) order by t0.code; --bind(def,2,Array[1]={1000})");
assertSql(sql.get(0)).contains("from o_cached_natkey3 t0 where t0.store = ? and t0.sku = ? and t0.code in (?) order by t0.code; --bind(def,2,Array[1]={1000})");
}
assertThat(list).hasSize(1);
@@ -174,7 +174,7 @@ public class TestCacheViaComplexNaturalKey3 extends BaseTestCase {
assertThat(sql).hasSize(1);
if (isH2()) {
// in clause with only 1 bind param - miss on 1000, 1002
assertThat(sql.get(0)).contains("from o_cached_natkey3 t0 where t0.store = ? and t0.sku = ? and t0.code in (?,?); --bind(def,2,Array[2]={1002,1000})");
assertSql(sql.get(0)).contains("from o_cached_natkey3 t0 where t0.store = ? and t0.sku = ? and t0.code in (?,?); --bind(def,2,Array[2]={1002,1000})");
}
assertThat(map).hasSize(2);
@@ -207,7 +207,7 @@ public class TestCacheViaComplexNaturalKey3 extends BaseTestCase {
assertThat(sql).hasSize(1);
if (isH2()) {
// in clause with only 1 bind param - (sku=3 ... we got hits on sku 1 and 2)
assertThat(sql.get(0)).contains("from o_cached_natkey3 t0 where t0.store = ? and t0.code in (?) and t0.sku = ? order by t0.sku desc, t0.code; --bind(def,Array[1]={1000},2)");
assertSql(sql.get(0)).contains("from o_cached_natkey3 t0 where t0.store = ? and t0.code in (?) and t0.sku = ? order by t0.sku desc, t0.code; --bind(def,Array[1]={1000},2)");
}
assertThat(list).hasSize(4);
@@ -269,7 +269,7 @@ public class TestCacheViaComplexNaturalKey3 extends BaseTestCase {
assertThat(sql).hasSize(1);
if (isH2()) {
// in clause with 2 bind params as we got not hits on the cache
assertThat(sql.get(0)).contains("from o_cached_natkey3 t0 where t0.store = ? and t0.sku in (?,?,?) and t0.code = ? order by t0.sku desc; --bind(abc,Array[3]={3,2,4},1001)");
assertSql(sql.get(0)).contains("from o_cached_natkey3 t0 where t0.store = ? and t0.sku in (?,?,?) and t0.code = ? order by t0.sku desc; --bind(abc,Array[3]={3,2,4},1001)");
}
assertThat(list).hasSize(2);
@@ -369,13 +369,13 @@ public class TestCacheViaComplexNaturalKey3 extends BaseTestCase {
assertBeanCacheHitMiss(1, 0);
if (isH2()) {
assertThat(sql.get(0)).contains("from o_cached_natkey3 t0 where t0.store = ? and concat(t0.sku,'-',t0.code) in (?,?) order by t0.sku desc; --bind(def,Array[2]={2-1000,3-1000})");
assertSql(sql.get(0)).contains("from o_cached_natkey3 t0 where t0.store = ? and concat(t0.sku,'-',t0.code) in (?,?) order by t0.sku desc; --bind(def,Array[2]={2-1000,3-1000})");
} else if (isPostgres()) {
assertThat(sql.get(0)).contains("from o_cached_natkey3 t0 where t0.store = ? and (t0.sku||'-'||t0.code)");
assertSql(sql.get(0)).contains("from o_cached_natkey3 t0 where t0.store = ? and (t0.sku||'-'||t0.code)");
} else if (isHana()) {
assertThat(sql.get(0)).contains("from o_cached_natkey3 t0 where t0.store = ? and concat(t0.sku, '-'||t0.code)");
assertSql(sql.get(0)).contains("from o_cached_natkey3 t0 where t0.store = ? and concat(t0.sku, '-'||t0.code)");
} else {
assertThat(sql.get(0)).contains("from o_cached_natkey3 t0 where t0.store = ? and concat(t0.sku,'-',t0.code)");
assertSql(sql.get(0)).contains("from o_cached_natkey3 t0 where t0.store = ? and concat(t0.sku,'-',t0.code)");
}
}
@@ -412,13 +412,13 @@ public class TestCacheViaComplexNaturalKey3 extends BaseTestCase {
assertBeanCacheHitMiss(1, 0);
if (isH2()) {
assertThat(sql.get(0)).contains("from o_cached_natkey3 t0 where t0.store = ? and concat(t0.sku,':',t0.code,'-foo') in (?,?) order by t0.sku desc; --bind(def,Array[2]={2:1000-foo,3:1000-foo})");
assertSql(sql.get(0)).contains("from o_cached_natkey3 t0 where t0.store = ? and concat(t0.sku,':',t0.code,'-foo') in (?,?) order by t0.sku desc; --bind(def,Array[2]={2:1000-foo,3:1000-foo})");
} else if (isPostgres()){
assertThat(sql.get(0)).contains("from o_cached_natkey3 t0 where t0.store = ? and (t0.sku||':'||t0.code||'-foo')");
assertSql(sql.get(0)).contains("from o_cached_natkey3 t0 where t0.store = ? and (t0.sku||':'||t0.code||'-foo')");
} else if (isHana()){
assertThat(sql.get(0)).contains("from o_cached_natkey3 t0 where t0.store = ? and concat(t0.sku, ':'||t0.code||'-foo')");
assertSql(sql.get(0)).contains("from o_cached_natkey3 t0 where t0.store = ? and concat(t0.sku, ':'||t0.code||'-foo')");
} else {
assertThat(sql.get(0)).contains("from o_cached_natkey3 t0 where t0.store = ? and concat(t0.sku,':',t0.code,'-foo')");
assertSql(sql.get(0)).contains("from o_cached_natkey3 t0 where t0.store = ? and concat(t0.sku,':',t0.code,'-foo')");
}
}
@@ -41,7 +41,7 @@ public class TestNatKeyUid extends BaseTestCase {
return DB.find(OCachedNkeyUid.class)
.where()
.eq("uid", one)
.eq("cid", one)
.findOne();
}
@@ -68,7 +68,7 @@ public class TestNatKeyUid extends BaseTestCase {
return DB.find(OCachedNkeyUid.class)
.setUseCache(true)
.where()
.in("uid", one, two)
.in("cid", one, two)
.findList();
}
@@ -72,9 +72,9 @@ public class TestIdClassScalar extends BaseTestCase {
List<String> sql = LoggedSqlCollector.current();
assertThat(sql).hasSize(3);
assertThat(sql.get(0)).contains("insert into bsite_user_d (site_id, user_id, access_level, version) values (?,?,?,?)");
assertThat(sql.get(1)).contains("update bsite_user_d set access_level=?, version=? where site_id=? and user_id=? and version=?");
assertThat(trimSql(sql.get(2))).contains("select t0.site_id, t0.user_id, t0.site_id, t0.user_id, t0.access_level, t0.version from bsite_user_d t0");
assertSql(sql.get(0)).contains("insert into bsite_user_d (site_id, user_id, access_level, version) values (?,?,?,?)");
assertSql(sql.get(1)).contains("update bsite_user_d set access_level=?, version=? where site_id=? and user_id=? and version=?");
assertSql(sql.get(2)).contains("select t0.site_id, t0.user_id, t0.site_id, t0.user_id, t0.access_level, t0.version from bsite_user_d t0");
BEmbId id = new BEmbId(site.id, user.id);
@@ -90,8 +90,8 @@ public class TestIdClassScalar extends BaseTestCase {
sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(2);
assertThat(trimSql(sql.get(0))).contains("select t0.site_id, t0.user_id, t0.site_id, t0.user_id, t0.access_level, t0.version from bsite_user_d t0 where t0.site_id = ? and t0.user_id = ?");
assertThat(sql.get(1)).contains("update bsite_user_d set access_level=?, version=? where site_id=? and user_id=? and version=?");
assertSql(sql.get(0)).contains("select t0.site_id, t0.user_id, t0.site_id, t0.user_id, t0.access_level, t0.version from bsite_user_d t0 where t0.site_id = ? and t0.user_id = ?");
assertSql(sql.get(1)).contains("update bsite_user_d set access_level=?, version=? where site_id=? and user_id=? and version=?");
}
/**
@@ -112,9 +112,9 @@ public class TestIdClassScalar extends BaseTestCase {
List<String> sql = LoggedSqlCollector.current();
assertThat(sql).hasSize(3);
assertThat(sql.get(0)).contains("insert into bsite_user_e (site_id, user_id, access_level)");
assertThat(sql.get(1)).contains("update bsite_user_e set access_level=? where site_id=? and user_id=?");
assertThat(trimSql(sql.get(2))).contains("select t0.site_id, t0.user_id, t0.access_level, t0.site_id, t0.user_id from bsite_user_e t0");
assertSql(sql.get(0)).contains("insert into bsite_user_e (site_id, user_id, access_level)");
assertSql(sql.get(1)).contains("update bsite_user_e set access_level=? where site_id=? and user_id=?");
assertSql(sql.get(2)).contains("select t0.site_id, t0.user_id, t0.access_level, t0.site_id, t0.user_id from bsite_user_e t0");
for (BSiteUserE bridge : list) {
@@ -136,8 +136,8 @@ public class TestIdClassScalar extends BaseTestCase {
sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(2);
assertThat(trimSql(sql.get(0))).contains("select t0.site_id, t0.user_id, t0.access_level, t0.site_id, t0.user_id from bsite_user_e t0 where t0.site_id = ? and t0.user_id = ?");
assertThat(sql.get(1)).contains("update bsite_user_e set access_level=? where site_id=? and user_id=?");
assertSql(sql.get(0)).contains("select t0.site_id, t0.user_id, t0.access_level, t0.site_id, t0.user_id from bsite_user_e t0 where t0.site_id = ? and t0.user_id = ?");
assertSql(sql.get(1)).contains("update bsite_user_e set access_level=? where site_id=? and user_id=?");
}
}
@@ -31,7 +31,7 @@ public class TestMTOInheritNoDiscriminator extends BaseTestCase {
assertThat(sql).hasSize(1);
if (isH2() || isPostgres()) {
assertThat(sql.get(0)).contains("select t0.id, t0.name, t0.version, t2.type, t0.truck_plate_no, t0.basic_id, t1.id, t1.some_uid, t1.foo, t1.owner_id from ttruck_holder t0 join tcar t2 on t2.plate_no = t0.truck_plate_no left join ttruck_holder_item t1 on t1.owner_id = t0.id where t0.id = ? order by t0.id");
assertSql(sql.get(0)).contains("select t0.id, t0.name, t0.version, t2.type, t0.truck_plate_no, t0.basic_id, t1.id, t1.some_uid, t1.foo, t1.owner_id from ttruck_holder t0 join tcar t2 on t2.plate_no = t0.truck_plate_no left join ttruck_holder_item t1 on t1.owner_id = t0.id where t0.id = ? order by t0.id");
}
}
@@ -41,8 +41,8 @@ public class TestCompositeKeyUserClient extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(2);
assertThat(sql.get(0)).contains("insert into cke_client (cod_cpny, cod_client, notes, username) values (?,?,?,?)");
assertThat(sql.get(1)).contains("update cke_client set notes=?, username=? where cod_cpny=? and cod_client=?");
assertSql(sql.get(0)).contains("insert into cke_client (cod_cpny, cod_client, notes, username) values (?,?,?,?)");
assertSql(sql.get(1)).contains("update cke_client set notes=?, username=? where cod_cpny=? and cod_client=?");
Ebean.delete(client);
@@ -1,5 +1,6 @@
package org.tests.model.elementcollection;
import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.validation.constraints.Size;
@@ -13,6 +14,7 @@ public class EcPhone {
String area;
@Size(max = 20)
@Column(name = "phnum")
String number;
public EcPhone(String countryCode, String area, String number) {
@@ -24,7 +24,7 @@ public class EcmPerson {
@ElementCollection
@MapKeyColumn(name = "type", length = 4)
@Column(name = "number", length = 10)
@Column(name = "phnum", length = 10)
Map<String, String> phoneNumbers = new LinkedHashMap<>();
@Transient
@@ -1,6 +1,7 @@
package org.tests.model.elementcollection;
import io.ebean.BaseTestCase;
import io.ebean.DB;
import io.ebean.text.json.JsonContext;
import org.ebeantest.LoggedSqlCollector;
@@ -10,7 +11,7 @@ import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
public class EcmPersonTest {
public class EcmPersonTest extends BaseTestCase {
@Test
public void readJsonThenInsert() {
@@ -31,9 +32,9 @@ public class EcmPersonTest {
final List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(4);
assertThat(sql.get(0)).contains("insert into ecm_person ");
assertThat(sql.get(1)).contains("insert into ecm_person_phone_numbers ");
assertThat(sql.get(2)).contains("-- bind");
assertSql(sql.get(0)).contains("insert into ecm_person ");
assertSql(sql.get(1)).contains("insert into ecm_person_phone_numbers ");
assertSql(sql.get(2)).contains("-- bind");
assertThat(sql.get(3)).contains("-- bind");
DB.delete(person);
@@ -1,5 +1,6 @@
package org.tests.model.elementcollection;
import io.ebean.BaseTestCase;
import io.ebean.DB;
import io.ebean.text.json.JsonContext;
import org.ebeantest.LoggedSqlCollector;
@@ -9,7 +10,7 @@ import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
public class EcsPersonTest {
public class EcsPersonTest extends BaseTestCase {
@Test
public void jsonReadThenInsert() {
@@ -30,9 +31,9 @@ public class EcsPersonTest {
final List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(4);
assertThat(sql.get(0)).contains("insert into ecs_person ");
assertThat(sql.get(1)).contains("insert into ecs_person_phone ");
assertThat(sql.get(2)).contains("-- bind");
assertSql(sql.get(0)).contains("insert into ecs_person ");
assertSql(sql.get(1)).contains("insert into ecs_person_phone ");
assertSql(sql.get(2)).contains("-- bind");
assertThat(sql.get(3)).contains("-- bind");
DB.delete(person);
@@ -35,8 +35,8 @@ public class TestElementCollectionBasic extends BaseTestCase {
sql = LoggedSqlCollector.current();
assertThat(sql).hasSize(2);
assertThat(sql.get(0)).contains("from ec_person t0 where t0.id = ?");
assertThat(sql.get(1)).contains("from ec_person_phone t0 where");
assertSql(sql.get(0)).contains("from ec_person t0 where t0.id = ?");
assertSql(sql.get(1)).contains("from ec_person_phone t0 where");
// save when not actually changed
Ebean.save(found);
@@ -62,14 +62,14 @@ public class TestElementCollectionBasic extends BaseTestCase {
List<String> sql = LoggedSqlCollector.current();
if (isPersistBatchOnCascade()) {
assertThat(sql).hasSize(4);
assertThat(sql.get(0)).contains("insert into ec_person");
assertThat(sql.get(1)).contains("insert into ec_person_phone");
assertSql(sql.get(0)).contains("insert into ec_person");
assertSql(sql.get(1)).contains("insert into ec_person_phone");
assertSqlBind(sql, 2, 3);
} else {
assertThat(sql).hasSize(3);
assertThat(sql.get(0)).contains("insert into ec_person");
assertThat(sql.get(1)).contains("insert into ec_person_phone");
assertThat(sql.get(2)).contains("insert into ec_person_phone");
assertSql(sql.get(0)).contains("insert into ec_person");
assertSql(sql.get(1)).contains("insert into ec_person_phone");
assertSql(sql.get(2)).contains("insert into ec_person_phone");
}
EcPerson person1 = new EcPerson("Fiona09");
@@ -96,8 +96,8 @@ public class TestElementCollectionBasic extends BaseTestCase {
sql = LoggedSqlCollector.current();
assertThat(sql).hasSize(2);
assertThat(trimSql(sql.get(0))).contains("select t0.id, t0.name, t0.version from ec_person t0 where");
assertThat(trimSql(sql.get(1))).contains("select t0.owner_id, t0.phone from ec_person_phone t0 where");
assertSql(sql.get(0)).contains("select t0.id, t0.name, t0.version from ec_person t0 where");
assertSql(sql.get(1)).contains("select t0.owner_id, t0.phone from ec_person_phone t0 where");
List<EcPerson> found2 =
Ebean.find(EcPerson.class)
@@ -111,7 +111,7 @@ public class TestElementCollectionBasic extends BaseTestCase {
sql = LoggedSqlCollector.current();
assertThat(sql).hasSize(1);
assertThat(trimSql(sql.get(0))).contains("select t0.id, t0.name, t0.version, t1.phone from ec_person t0 left join ec_person_phone t1");
assertSql(sql.get(0)).contains("select t0.id, t0.name, t0.version, t1.phone from ec_person t0 left join ec_person_phone t1");
EcPerson foundFirst = found2.get(0);
@@ -128,7 +128,7 @@ public class TestElementCollectionBasic extends BaseTestCase {
List<String> sql = LoggedSqlCollector.current();
assertThat(sql).hasSize(1);
assertThat(sql.get(0)).contains("update ec_person");
assertSql(sql.get(0)).contains("update ec_person");
assertThat(eventLog()).containsExactly("preUpdate", "postUpdate");
@@ -146,7 +146,7 @@ public class TestElementCollectionBasic extends BaseTestCase {
List<String> sql = LoggedSqlCollector.current();
assertThat(sql).hasSize(2);
assertThat(sql.get(0)).contains("update ec_person");
assertSql(sql.get(0)).contains("update ec_person");
assertThat(eventLog()).containsExactly("preUpdate", "postUpdate");
@@ -162,17 +162,17 @@ public class TestElementCollectionBasic extends BaseTestCase {
List<String> sql = LoggedSqlCollector.current();
if (isPersistBatchOnCascade()) {
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=?");
assertSql(sql.get(0)).contains("update ec_person set name=?, version=? where id=? and version=?");
assertSql(sql.get(1)).contains("delete from ec_person_phone where owner_id=?");
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);
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 (?,?)");
assertSql(sql.get(0)).contains("update ec_person set name=?, version=? where id=? and version=?");
assertSql(sql.get(1)).contains("delete from ec_person_phone where owner_id=?");
assertSql(sql.get(2)).contains("insert into ec_person_phone (owner_id,phone) values (?,?)");
assertThat(sql.get(3)).contains("insert into ec_person_phone (owner_id,phone) values (?,?)");
assertThat(sql.get(4)).contains("insert into ec_person_phone (owner_id,phone) values (?,?)");
}
@@ -194,8 +194,8 @@ public class TestElementCollectionBasic extends BaseTestCase {
List<String> sql = LoggedSqlCollector.current();
assertThat(sql).hasSize(9);
assertThat(sql.get(0)).contains("update ec_person set name=?, version=? where id=? and version=?");
assertThat(sql.get(2)).contains("delete from ec_person_phone where owner_id=?");
assertSql(sql.get(0)).contains("update ec_person set name=?, version=? where id=? and version=?");
assertSql(sql.get(2)).contains("delete from ec_person_phone where owner_id=?");
assertSqlBind(sql, 3);
assertThat(sql.get(4)).contains("insert into ec_person_phone (owner_id,phone) values (?,?)");
assertSqlBind(sql, 5, 8);
@@ -228,9 +228,9 @@ public class TestElementCollectionBasic extends BaseTestCase {
List<String> sql = LoggedSqlCollector.current();
assertThat(sql).hasSize(8);
assertThat(sql.get(0)).contains("delete from ec_person_phone where owner_id=?");
assertSql(sql.get(0)).contains("delete from ec_person_phone where owner_id=?");
assertSqlBind(sql, 1);
assertThat(sql.get(2)).contains("insert into ec_person_phone (owner_id,phone) values (?,?)");
assertSql(sql.get(2)).contains("insert into ec_person_phone (owner_id,phone) values (?,?)");
assertSqlBind(sql, 3, 7);
assertThat(eventLog()).containsExactly("preUpdate", "postUpdate");
@@ -246,16 +246,16 @@ public class TestElementCollectionBasic extends BaseTestCase {
List<String> sql = LoggedSqlCollector.current();
if (isPersistBatchOnCascade()) {
assertThat(sql).hasSize(9);
assertThat(sql.get(0)).contains("delete from ec_person_phone where owner_id=?");
assertSql(sql.get(0)).contains("delete from ec_person_phone where owner_id=?");
assertSqlBind(sql.get(1));
assertThat(sql.get(2)).contains("insert into ec_person_phone (owner_id,phone) values (?,?)");
assertSql(sql.get(2)).contains("insert into ec_person_phone (owner_id,phone) values (?,?)");
assertSqlBind(sql, 3, 8);
} else {
assertThat(sql).hasSize(7);
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 (?,?)");
assertThat(sql.get(2)).contains("insert into ec_person_phone (owner_id,phone) values (?,?)");
assertSql(sql.get(0)).contains("delete from ec_person_phone where owner_id=?");
assertSql(sql.get(1)).contains("insert into ec_person_phone (owner_id,phone) values (?,?)");
assertSql(sql.get(2)).contains("insert into ec_person_phone (owner_id,phone) values (?,?)");
assertThat(sql.get(3)).contains("insert into ec_person_phone (owner_id,phone) values (?,?)");
assertThat(sql.get(4)).contains("insert into ec_person_phone (owner_id,phone) values (?,?)");
assertThat(sql.get(5)).contains("insert into ec_person_phone (owner_id,phone) values (?,?)");
@@ -273,8 +273,8 @@ public class TestElementCollectionBasic extends BaseTestCase {
List<String> sql = LoggedSqlCollector.current();
assertThat(sql).hasSize(2);
assertThat(sql.get(0)).contains("delete from ec_person_phone where owner_id = ?");
assertThat(sql.get(1)).contains("delete from ec_person where id=? and version=?");
assertSql(sql.get(0)).contains("delete from ec_person_phone where owner_id = ?");
assertSql(sql.get(1)).contains("delete from ec_person where id=? and version=?");
assertThat(eventLog()).containsExactly("preDelete", "postDelete");
}
@@ -26,14 +26,14 @@ public class TestElementCollectionBasicMap extends BaseTestCase {
List<String> sql = LoggedSqlCollector.current();
if (isPersistBatchOnCascade()) {
assertThat(sql).hasSize(4);
assertThat(sql.get(0)).contains("insert into ecm_person");
assertThat(sql.get(1)).contains("insert into ecm_person_phone");
assertSql(sql.get(0)).contains("insert into ecm_person");
assertSql(sql.get(1)).contains("insert into ecm_person_phone");
assertSqlBind(sql, 2, 3);
} else {
assertThat(sql).hasSize(3);
assertThat(sql.get(0)).contains("insert into ecm_person");
assertThat(sql.get(1)).contains("insert into ecm_person_phone");
assertThat(sql.get(2)).contains("insert into ecm_person_phone");
assertSql(sql.get(0)).contains("insert into ecm_person");
assertSql(sql.get(1)).contains("insert into ecm_person_phone");
assertSql(sql.get(2)).contains("insert into ecm_person_phone");
}
EcmPerson person1 = new EcmPerson("MFiona09");
@@ -63,8 +63,8 @@ public class TestElementCollectionBasicMap extends BaseTestCase {
sql = LoggedSqlCollector.current();
assertThat(sql).hasSize(2);
assertThat(trimSql(sql.get(0))).contains("select t0.id, t0.name, t0.version from ecm_person t0 where");
assertThat(trimSql(sql.get(1))).contains("select t0.ecm_person_id, t0.type, t0.number from ecm_person_phone_numbers t0 where");
assertSql(sql.get(0)).contains("select t0.id, t0.name, t0.version from ecm_person t0 where");
assertSql(sql.get(1)).contains("select t0.ecm_person_id, t0.type, t0.phnum from ecm_person_phone_numbers t0 where");
List<EcmPerson> found2 =
DB.find(EcmPerson.class)
@@ -78,7 +78,7 @@ public class TestElementCollectionBasicMap extends BaseTestCase {
sql = LoggedSqlCollector.current();
assertThat(sql).hasSize(1);
assertThat(trimSql(sql.get(0))).contains("select t0.id, t0.name, t0.version, t1.type, t1.number from ecm_person t0 left join ecm_person_phone_numbers t1");
assertSql(sql.get(0)).contains("select t0.id, t0.name, t0.version, t1.type, t1.phnum from ecm_person t0 left join ecm_person_phone_numbers t1");
EcmPerson foundFirst = found2.get(0);
jsonToFrom(foundFirst);
@@ -94,7 +94,7 @@ public class TestElementCollectionBasicMap extends BaseTestCase {
List<String> sql = LoggedSqlCollector.current();
assertThat(sql).hasSize(1);
assertThat(sql.get(0)).contains("update ecm_person");
assertSql(sql.get(0)).contains("update ecm_person");
updateBoth(bean);
}
@@ -108,18 +108,18 @@ public class TestElementCollectionBasicMap extends BaseTestCase {
List<String> sql = LoggedSqlCollector.current();
if (isPersistBatchOnCascade()) {
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=?");
assertSql(sql.get(0)).contains("update ecm_person set name=?, version=? where id=? and version=?");
assertSql(sql.get(1)).contains("delete from ecm_person_phone_numbers where ecm_person_id=?");
assertSqlBind(sql.get(2));
assertThat(sql.get(3)).contains("insert into ecm_person_phone_numbers (ecm_person_id,type,number) values (?,?,?)");
assertThat(sql.get(3)).contains("insert into ecm_person_phone_numbers (ecm_person_id,type,phnum) 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=?");
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 (?,?,?)");
assertThat(sql.get(3)).contains("insert into ecm_person_phone_numbers (ecm_person_id,type,number) values (?,?,?)");
assertThat(sql.get(4)).contains("insert into ecm_person_phone_numbers (ecm_person_id,type,number) values (?,?,?)");
assertSql(sql.get(0)).contains("update ecm_person set name=?, version=? where id=? and version=?");
assertSql(sql.get(1)).contains("delete from ecm_person_phone_numbers where ecm_person_id=?");
assertSql(sql.get(2)).contains("insert into ecm_person_phone_numbers (ecm_person_id,type,phnum) values (?,?,?)");
assertThat(sql.get(3)).contains("insert into ecm_person_phone_numbers (ecm_person_id,type,phnum) values (?,?,?)");
assertThat(sql.get(4)).contains("insert into ecm_person_phone_numbers (ecm_person_id,type,phnum) values (?,?,?)");
}
updateNothing(bean);
@@ -143,17 +143,17 @@ public class TestElementCollectionBasicMap extends BaseTestCase {
List<String> sql = LoggedSqlCollector.current();
if (isPersistBatchOnCascade()) {
assertThat(sql).hasSize(7);
assertThat(sql.get(0)).contains("delete from ecm_person_phone_numbers where ecm_person_id=?");
assertSql(sql.get(0)).contains("delete from ecm_person_phone_numbers where ecm_person_id=?");
assertSqlBind(sql.get(1));
assertThat(sql.get(2)).contains("insert into ecm_person_phone_numbers (ecm_person_id,type,number) values (?,?,?)");
assertSql(sql.get(2)).contains("insert into ecm_person_phone_numbers (ecm_person_id,type,phnum) 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=?");
assertThat(sql.get(1)).contains("insert into ecm_person_phone_numbers (ecm_person_id,type,number) values (?,?,?)");
assertThat(sql.get(2)).contains("insert into ecm_person_phone_numbers (ecm_person_id,type,number) values (?,?,?)");
assertThat(sql.get(3)).contains("insert into ecm_person_phone_numbers (ecm_person_id,type,number) values (?,?,?)");
assertThat(sql.get(4)).contains("insert into ecm_person_phone_numbers (ecm_person_id,type,number) values (?,?,?)");
assertSql(sql.get(0)).contains("delete from ecm_person_phone_numbers where ecm_person_id=?");
assertSql(sql.get(1)).contains("insert into ecm_person_phone_numbers (ecm_person_id,type,phnum) values (?,?,?)");
assertSql(sql.get(2)).contains("insert into ecm_person_phone_numbers (ecm_person_id,type,phnum) values (?,?,?)");
assertThat(sql.get(3)).contains("insert into ecm_person_phone_numbers (ecm_person_id,type,phnum) values (?,?,?)");
assertThat(sql.get(4)).contains("insert into ecm_person_phone_numbers (ecm_person_id,type,phnum) values (?,?,?)");
}
delete(bean);
@@ -165,8 +165,8 @@ public class TestElementCollectionBasicMap extends BaseTestCase {
List<String> sql = LoggedSqlCollector.current();
assertThat(sql).hasSize(2);
assertThat(sql.get(0)).contains("delete from ecm_person_phone_numbers where ecm_person_id = ?");
assertThat(sql.get(1)).contains("delete from ecm_person where id=? and version=?");
assertSql(sql.get(0)).contains("delete from ecm_person_phone_numbers where ecm_person_id = ?");
assertSql(sql.get(1)).contains("delete from ecm_person where id=? and version=?");
}
private void jsonToFrom(EcmPerson foundFirst) {
@@ -24,14 +24,14 @@ public class TestElementCollectionBasicMapAsLob extends BaseTestCase {
List<String> sql = LoggedSqlCollector.current();
if (isPersistBatchOnCascade()) {
assertThat(sql).hasSize(4);
assertThat(sql.get(0)).contains("insert into ecmc_person");
assertThat(sql.get(1)).contains("insert into ecmc_person_phone");
assertSql(sql.get(0)).contains("insert into ecmc_person");
assertSql(sql.get(1)).contains("insert into ecmc_person_phone");
assertSqlBind(sql, 2, 3);
} else {
assertThat(sql).hasSize(3);
assertThat(sql.get(0)).contains("insert into ecmc_person");
assertThat(sql.get(1)).contains("insert into ecmc_person_phone");
assertThat(sql.get(2)).contains("insert into ecmc_person_phone");
assertSql(sql.get(0)).contains("insert into ecmc_person");
assertSql(sql.get(1)).contains("insert into ecmc_person_phone");
assertSql(sql.get(2)).contains("insert into ecmc_person_phone");
}
LoggedSqlCollector.stop();
@@ -25,14 +25,14 @@ public class TestElementCollectionBasicSet extends BaseTestCase {
List<String> sql = LoggedSqlCollector.current();
if (isPersistBatchOnCascade()) {
assertThat(sql).hasSize(4);
assertThat(sql.get(0)).contains("insert into ecs_person");
assertThat(sql.get(1)).contains("insert into ecs_person_phone");
assertSql(sql.get(0)).contains("insert into ecs_person");
assertSql(sql.get(1)).contains("insert into ecs_person_phone");
assertSqlBind(sql, 2, 3);
} else {
assertThat(sql).hasSize(3);
assertThat(sql.get(0)).contains("insert into ecs_person");
assertThat(sql.get(1)).contains("insert into ecs_person_phone");
assertThat(sql.get(2)).contains("insert into ecs_person_phone");
assertSql(sql.get(0)).contains("insert into ecs_person");
assertSql(sql.get(1)).contains("insert into ecs_person_phone");
assertSql(sql.get(2)).contains("insert into ecs_person_phone");
}
EcsPerson person1 = new EcsPerson("Fiona09");
@@ -58,8 +58,8 @@ public class TestElementCollectionBasicSet extends BaseTestCase {
sql = LoggedSqlCollector.current();
assertThat(sql).hasSize(2);
assertThat(trimSql(sql.get(0))).contains("select t0.id, t0.name, t0.version from ecs_person t0 where");
assertThat(trimSql(sql.get(1))).contains("select t0.ecs_person_id, t0.phone from ecs_person_phone t0 where");
assertSql(sql.get(0)).contains("select t0.id, t0.name, t0.version from ecs_person t0 where");
assertSql(sql.get(1)).contains("select t0.ecs_person_id, t0.phone from ecs_person_phone t0 where");
List<EcsPerson> found2 =
DB.find(EcsPerson.class)
@@ -73,7 +73,7 @@ public class TestElementCollectionBasicSet extends BaseTestCase {
sql = LoggedSqlCollector.current();
assertThat(sql).hasSize(1);
assertThat(trimSql(sql.get(0))).contains("select t0.id, t0.name, t0.version, t1.phone from ecs_person t0 left join ecs_person_phone t1");
assertSql(sql.get(0)).contains("select t0.id, t0.name, t0.version, t1.phone from ecs_person t0 left join ecs_person_phone t1");
EcsPerson foundFirst = found2.get(0);
jsonToFrom(foundFirst);
@@ -90,7 +90,7 @@ public class TestElementCollectionBasicSet extends BaseTestCase {
List<String> sql = LoggedSqlCollector.current();
assertThat(sql).hasSize(1);
assertThat(sql.get(0)).contains("update ecs_person");
assertSql(sql.get(0)).contains("update ecs_person");
updateBoth(bean);
}
@@ -104,16 +104,16 @@ public class TestElementCollectionBasicSet extends BaseTestCase {
List<String> sql = LoggedSqlCollector.current();
if (isPersistBatchOnCascade()) {
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=?");
assertSql(sql.get(0)).contains("update ecs_person set name=?, version=? where id=? and version=?");
assertSql(sql.get(1)).contains("delete from ecs_person_phone where ecs_person_id=?");
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=?");
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 (?,?)");
assertSql(sql.get(0)).contains("update ecs_person set name=?, version=? where id=? and version=?");
assertSql(sql.get(1)).contains("delete from ecs_person_phone where ecs_person_id=?");
assertSql(sql.get(2)).contains("insert into ecs_person_phone (ecs_person_id,phone) values (?,?)");
assertThat(sql.get(3)).contains("insert into ecs_person_phone (ecs_person_id,phone) values (?,?)");
assertThat(sql.get(4)).contains("insert into ecs_person_phone (ecs_person_id,phone) values (?,?)");
}
@@ -139,15 +139,15 @@ public class TestElementCollectionBasicSet extends BaseTestCase {
List<String> sql = LoggedSqlCollector.current();
if (isPersistBatchOnCascade()) {
assertThat(sql).hasSize(7);
assertThat(sql.get(0)).contains("delete from ecs_person_phone where ecs_person_id=?");
assertSql(sql.get(0)).contains("delete from ecs_person_phone where ecs_person_id=?");
assertSqlBind(sql.get(1));
assertThat(sql.get(2)).contains("insert into ecs_person_phone (ecs_person_id,phone) values (?,?)");
assertSql(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=?");
assertThat(sql.get(1)).contains("insert into ecs_person_phone (ecs_person_id,phone) values (?,?)");
assertThat(sql.get(2)).contains("insert into ecs_person_phone (ecs_person_id,phone) values (?,?)");
assertSql(sql.get(0)).contains("delete from ecs_person_phone where ecs_person_id=?");
assertSql(sql.get(1)).contains("insert into ecs_person_phone (ecs_person_id,phone) values (?,?)");
assertSql(sql.get(2)).contains("insert into ecs_person_phone (ecs_person_id,phone) values (?,?)");
assertThat(sql.get(3)).contains("insert into ecs_person_phone (ecs_person_id,phone) values (?,?)");
assertThat(sql.get(4)).contains("insert into ecs_person_phone (ecs_person_id,phone) values (?,?)");
}
@@ -161,8 +161,8 @@ public class TestElementCollectionBasicSet extends BaseTestCase {
List<String> sql = LoggedSqlCollector.current();
assertThat(sql).hasSize(2);
assertThat(sql.get(0)).contains("delete from ecs_person_phone where ecs_person_id = ?");
assertThat(sql.get(1)).contains("delete from ecs_person where id=? and version=?");
assertSql(sql.get(0)).contains("delete from ecs_person_phone where ecs_person_id = ?");
assertSql(sql.get(1)).contains("delete from ecs_person where id=? and version=?");
}
private void jsonToFrom(EcsPerson foundFirst) {
@@ -31,9 +31,9 @@ public class TestElementCollectionCascadeMultiple extends BaseTestCase {
final List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(9);
assertThat(sql.get(0)).contains("insert into ecs_person");
assertThat(sql.get(1)).contains("-- bind");
assertThat(sql.get(2)).contains("insert into ec_top");
assertSql(sql.get(0)).contains("insert into ecs_person");
assertSql(sql.get(1)).contains("-- bind");
assertSql(sql.get(2)).contains("insert into ec_top");
assertThat(sql.get(3)).contains("-- bind");
assertThat(sql.get(4)).contains("insert into ecs_person_phone");
assertThat(sql.get(5)).contains("-- bind");
@@ -24,14 +24,14 @@ public class TestElementCollectionEmbeddedList extends BaseTestCase {
List<String> sql = LoggedSqlCollector.current();
if (isPersistBatchOnCascade()) {
assertThat(sql).hasSize(4);
assertThat(sql.get(0)).contains("insert into ecbl_person");
assertThat(sql.get(1)).contains("insert into ecbl_person_phone_numbers");
assertSql(sql.get(0)).contains("insert into ecbl_person");
assertSql(sql.get(1)).contains("insert into ecbl_person_phone_numbers");
assertSqlBind(sql, 2, 3);
} else {
assertThat(sql).hasSize(3);
assertThat(sql.get(0)).contains("insert into ecbl_person");
assertThat(sql.get(1)).contains("insert into ecbl_person_phone_numbers");
assertThat(sql.get(2)).contains("insert into ecbl_person_phone_numbers");
assertSql(sql.get(0)).contains("insert into ecbl_person");
assertSql(sql.get(1)).contains("insert into ecbl_person_phone_numbers");
assertSql(sql.get(2)).contains("insert into ecbl_person_phone_numbers");
}
EcblPerson person1 = new EcblPerson("Fiona6409");
@@ -56,8 +56,8 @@ public class TestElementCollectionEmbeddedList extends BaseTestCase {
sql = LoggedSqlCollector.current();
assertThat(sql).hasSize(2);
assertThat(trimSql(sql.get(0))).contains("select t0.id, t0.name, t0.version from ecbl_person");
assertThat(trimSql(sql.get(1))).contains("select t0.person_id, t0.country_code, t0.area, t0.number from ecbl_person_phone_numbers");
assertSql(sql.get(0)).contains("select t0.id, t0.name, t0.version from ecbl_person");
assertSql(sql.get(1)).contains("select t0.person_id, t0.country_code, t0.area, t0.phnum from ecbl_person_phone_numbers");
List<EcblPerson> found2 =
DB.find(EcblPerson.class)
@@ -72,7 +72,7 @@ public class TestElementCollectionEmbeddedList extends BaseTestCase {
sql = LoggedSqlCollector.current();
assertThat(sql).hasSize(1);
String trimmedSql = trimSql(sql.get(0));
assertThat(trimmedSql).contains("select t0.id, t0.name, t0.version, t1.country_code, t1.area, t1.number from ecbl_person t0 left join ecbl_person_phone_numbers t1");
assertThat(trimmedSql).contains("select t0.id, t0.name, t0.version, t1.country_code, t1.area, t1.phnum from ecbl_person t0 left join ecbl_person_phone_numbers t1");
EcblPerson foundFirst = found2.get(0);
@@ -90,7 +90,7 @@ public class TestElementCollectionEmbeddedList extends BaseTestCase {
List<String> sql = LoggedSqlCollector.current();
assertThat(sql).hasSize(1);
assertThat(sql.get(0)).contains("update ecbl_person");
assertSql(sql.get(0)).contains("update ecbl_person");
updateBoth(bean);
}
@@ -104,18 +104,18 @@ public class TestElementCollectionEmbeddedList extends BaseTestCase {
List<String> sql = LoggedSqlCollector.current();
if (isPersistBatchOnCascade()) {
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=?");
assertSql(sql.get(0)).contains("update ecbl_person set name=?, version=? where id=? and version=?");
assertSql(sql.get(1)).contains("delete from ecbl_person_phone_numbers where person_id=?");
assertSqlBind(sql.get(2));
assertThat(sql.get(3)).contains("insert into ecbl_person_phone_numbers (person_id,country_code,area,number) values (?,?,?,?)");
assertThat(sql.get(3)).contains("insert into ecbl_person_phone_numbers (person_id,country_code,area,phnum) 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=?");
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 (?,?,?,?)");
assertThat(sql.get(3)).contains("insert into ecbl_person_phone_numbers (person_id,country_code,area,number) values (?,?,?,?)");
assertThat(sql.get(4)).contains("insert into ecbl_person_phone_numbers (person_id,country_code,area,number) values (?,?,?,?)");
assertSql(sql.get(0)).contains("update ecbl_person set name=?, version=? where id=? and version=?");
assertSql(sql.get(1)).contains("delete from ecbl_person_phone_numbers where person_id=?");
assertSql(sql.get(2)).contains("insert into ecbl_person_phone_numbers (person_id,country_code,area,phnum) values (?,?,?,?)");
assertThat(sql.get(3)).contains("insert into ecbl_person_phone_numbers (person_id,country_code,area,phnum) values (?,?,?,?)");
assertThat(sql.get(4)).contains("insert into ecbl_person_phone_numbers (person_id,country_code,area,phnum) values (?,?,?,?)");
}
updateNothing(bean);
@@ -139,17 +139,17 @@ public class TestElementCollectionEmbeddedList extends BaseTestCase {
List<String> sql = LoggedSqlCollector.current();
if (isPersistBatchOnCascade()) {
assertThat(sql).hasSize(7);
assertThat(sql.get(0)).contains("delete from ecbl_person_phone_numbers where person_id=?");
assertSql(sql.get(0)).contains("delete from ecbl_person_phone_numbers where person_id=?");
assertSqlBind(sql.get(1));
assertThat(sql.get(2)).contains("insert into ecbl_person_phone_numbers (person_id,country_code,area,number) values (?,?,?,?)");
assertSql(sql.get(2)).contains("insert into ecbl_person_phone_numbers (person_id,country_code,area,phnum) values (?,?,?,?)");
assertSqlBind(sql, 3, 6);
} else {
assertThat(sql).hasSize(5);
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 (?,?,?,?)");
assertThat(sql.get(2)).contains("insert into ecbl_person_phone_numbers (person_id,country_code,area,number) values (?,?,?,?)");
assertThat(sql.get(3)).contains("insert into ecbl_person_phone_numbers (person_id,country_code,area,number) values (?,?,?,?)");
assertThat(sql.get(4)).contains("insert into ecbl_person_phone_numbers (person_id,country_code,area,number) values (?,?,?,?)");
assertSql(sql.get(0)).contains("delete from ecbl_person_phone_numbers where person_id=?");
assertSql(sql.get(1)).contains("insert into ecbl_person_phone_numbers (person_id,country_code,area,phnum) values (?,?,?,?)");
assertSql(sql.get(2)).contains("insert into ecbl_person_phone_numbers (person_id,country_code,area,phnum) values (?,?,?,?)");
assertThat(sql.get(3)).contains("insert into ecbl_person_phone_numbers (person_id,country_code,area,phnum) values (?,?,?,?)");
assertThat(sql.get(4)).contains("insert into ecbl_person_phone_numbers (person_id,country_code,area,phnum) values (?,?,?,?)");
}
delete(bean);
@@ -161,8 +161,8 @@ public class TestElementCollectionEmbeddedList extends BaseTestCase {
List<String> sql = LoggedSqlCollector.current();
assertThat(sql).hasSize(2);
assertThat(sql.get(0)).contains("delete from ecbl_person_phone_numbers where person_id = ?");
assertThat(sql.get(1)).contains("delete from ecbl_person where id=? and version=?");
assertSql(sql.get(0)).contains("delete from ecbl_person_phone_numbers where person_id = ?");
assertSql(sql.get(1)).contains("delete from ecbl_person where id=? and version=?");
}
private void jsonToFrom(EcblPerson foundFirst) {
@@ -49,15 +49,15 @@ public class TestElementCollectionEmbeddedListCache extends BaseTestCase {
sql = LoggedSqlCollector.current();
if (isPersistBatchOnCascade()) {
assertThat(sql).hasSize(5); // update of collection only
assertThat(sql.get(0)).contains("delete from ecbl_person_phone_numbers where person_id=?");
assertSql(sql.get(0)).contains("delete from ecbl_person_phone_numbers where person_id=?");
assertSqlBind(sql.get(1));
assertThat(sql.get(2)).contains("insert into ecbl_person_phone_numbers (person_id,country_code,area,number) values (?,?,?,?)");
assertSql(sql.get(2)).contains("insert into ecbl_person_phone_numbers (person_id,country_code,area,phnum) 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=?");
assertThat(sql.get(1)).contains("insert into ecbl_person_phone_numbers (person_id,country_code,area,number) values (?,?,?,?)");
assertThat(sql.get(2)).contains("insert into ecbl_person_phone_numbers (person_id,country_code,area,number) values (?,?,?,?)");
assertSql(sql.get(0)).contains("delete from ecbl_person_phone_numbers where person_id=?");
assertSql(sql.get(1)).contains("insert into ecbl_person_phone_numbers (person_id,country_code,area,phnum) values (?,?,?,?)");
assertSql(sql.get(2)).contains("insert into ecbl_person_phone_numbers (person_id,country_code,area,phnum) values (?,?,?,?)");
}
EcblPerson three = Ebean.find(EcblPerson.class)
@@ -25,14 +25,14 @@ public class TestElementCollectionEmbeddedMap extends BaseTestCase {
List<String> sql = LoggedSqlCollector.current();
if (isPersistBatchOnCascade()) {
assertThat(sql).hasSize(4);
assertThat(sql.get(0)).contains("insert into ecbm_person");
assertThat(sql.get(1)).contains("insert into ecbm_person_phone_numbers");
assertSql(sql.get(0)).contains("insert into ecbm_person");
assertSql(sql.get(1)).contains("insert into ecbm_person_phone_numbers");
assertSqlBind(sql, 2, 3);
} else {
assertThat(sql).hasSize(3);
assertThat(sql.get(0)).contains("insert into ecbm_person");
assertThat(sql.get(1)).contains("insert into ecbm_person_phone_numbers");
assertThat(sql.get(2)).contains("insert into ecbm_person_phone_numbers");
assertSql(sql.get(0)).contains("insert into ecbm_person");
assertSql(sql.get(1)).contains("insert into ecbm_person_phone_numbers");
assertSql(sql.get(2)).contains("insert into ecbm_person_phone_numbers");
}
EcbmPerson person1 = new EcbmPerson("Fiona6409");
@@ -83,7 +83,7 @@ public class TestElementCollectionEmbeddedMap extends BaseTestCase {
List<String> sql = LoggedSqlCollector.current();
assertThat(sql).hasSize(1);
assertThat(sql.get(0)).contains("update ecbm_person");
assertSql(sql.get(0)).contains("update ecbm_person");
updateBoth(bean);
}
@@ -97,17 +97,17 @@ public class TestElementCollectionEmbeddedMap extends BaseTestCase {
List<String> sql = LoggedSqlCollector.current();
if (isPersistBatchOnCascade()) {
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(3)).contains("insert into ecbm_person_phone_numbers (person_id,mkey,country_code,area,number)");
assertSql(sql.get(0)).contains("update ecbm_person set name=?, version=? where id=? and version=?");
assertSql(sql.get(1)).contains("delete from ecbm_person_phone_numbers where person_id=?");
assertThat(sql.get(3)).contains("insert into ecbm_person_phone_numbers (person_id,mkey,country_code,area,phnum)");
assertSqlBind(sql, 4, 6);
} else {
assertThat(sql).hasSize(5);
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)");
assertThat(sql.get(3)).contains("insert into ecbm_person_phone_numbers (person_id,mkey,country_code,area,number)");
assertThat(sql.get(4)).contains("insert into ecbm_person_phone_numbers (person_id,mkey,country_code,area,number)");
assertSql(sql.get(0)).contains("update ecbm_person set name=?, version=? where id=? and version=?");
assertSql(sql.get(1)).contains("delete from ecbm_person_phone_numbers where person_id=?");
assertSql(sql.get(2)).contains("insert into ecbm_person_phone_numbers (person_id,mkey,country_code,area,phnum)");
assertThat(sql.get(3)).contains("insert into ecbm_person_phone_numbers (person_id,mkey,country_code,area,phnum)");
assertThat(sql.get(4)).contains("insert into ecbm_person_phone_numbers (person_id,mkey,country_code,area,phnum)");
}
updateNothing(bean);
@@ -131,17 +131,17 @@ public class TestElementCollectionEmbeddedMap extends BaseTestCase {
List<String> sql = LoggedSqlCollector.current();
if (isPersistBatchOnCascade()) {
assertThat(sql).hasSize(7);
assertThat(sql.get(0)).contains("delete from ecbm_person_phone_numbers where person_id=?");
assertSql(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 (?,?,?,?,?)");
assertSql(sql.get(2)).contains("insert into ecbm_person_phone_numbers (person_id,mkey,country_code,area,phnum) values (?,?,?,?,?)");
assertSqlBind(sql, 3, 6);
} else {
assertThat(sql).hasSize(5);
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 (?,?,?,?,?)");
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 (?,?,?,?,?)");
assertThat(sql.get(4)).contains("insert into ecbm_person_phone_numbers (person_id,mkey,country_code,area,number) values (?,?,?,?,?)");
assertSql(sql.get(0)).contains("delete from ecbm_person_phone_numbers where person_id=?");
assertSql(sql.get(1)).contains("insert into ecbm_person_phone_numbers (person_id,mkey,country_code,area,phnum) values (?,?,?,?,?)");
assertSql(sql.get(2)).contains("insert into ecbm_person_phone_numbers (person_id,mkey,country_code,area,phnum) values (?,?,?,?,?)");
assertThat(sql.get(3)).contains("insert into ecbm_person_phone_numbers (person_id,mkey,country_code,area,phnum) values (?,?,?,?,?)");
assertThat(sql.get(4)).contains("insert into ecbm_person_phone_numbers (person_id,mkey,country_code,area,phnum) values (?,?,?,?,?)");
}
delete(bean);
@@ -153,8 +153,8 @@ public class TestElementCollectionEmbeddedMap extends BaseTestCase {
List<String> sql = LoggedSqlCollector.current();
assertThat(sql).hasSize(2);
assertThat(sql.get(0)).contains("delete from ecbm_person_phone_numbers where person_id = ?");
assertThat(sql.get(1)).contains("delete from ecbm_person where id=? and version=?");
assertSql(sql.get(0)).contains("delete from ecbm_person_phone_numbers where person_id = ?");
assertSql(sql.get(1)).contains("delete from ecbm_person where id=? and version=?");
}
private void jsonToFrom(EcbmPerson foundFirst) {
@@ -50,16 +50,16 @@ 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=?");
assertSql(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 (?,?,?,?,?)");
assertSql(sql.get(2)).contains("insert into ecbm_person_phone_numbers (person_id,mkey,country_code,area,phnum) 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=?");
assertSql(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 (?,?,?,?,?)");
assertThat(sql.get(3)).contains("insert into ecbm_person_phone_numbers (person_id,mkey,country_code,area,number) values (?,?,?,?,?)");
assertSql(sql.get(2)).contains("insert into ecbm_person_phone_numbers (person_id,mkey,country_code,area,phnum) values (?,?,?,?,?)");
assertThat(sql.get(3)).contains("insert into ecbm_person_phone_numbers (person_id,mkey,country_code,area,phnum) values (?,?,?,?,?)");
}
EcbmPerson three = Ebean.find(EcbmPerson.class)
@@ -22,6 +22,6 @@ public class TestEmbeddedAttrOverride extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(1);
assertThat(sql.get(0)).contains("insert into primary_revision (id, revision, name, version) values (?,?,?,?)");
assertSql(sql.get(0)).contains("insert into primary_revision (id, revision, name, version) values (?,?,?,?)");
}
}
@@ -49,8 +49,8 @@ public class TestEmbeddedManyToOne extends BaseTestCase {
assertThat(sql).hasSize(2);
if (isH2()) {
assertThat(sql.get(0)).contains("select t0.id, t0.name, t0.version, t0.ma_street, t0.ma_suburb, t0.ma_city, t0.ma_country_code from eper_addr t0 where t0.id = ? ");
assertThat(sql.get(1)).contains("select t0.code, t0.name from o_country t0 where t0.code = ? ; --bind(NZ,");
assertSql(sql.get(0)).contains("select t0.id, t0.name, t0.version, t0.ma_street, t0.ma_suburb, t0.ma_city, t0.ma_country_code from eper_addr t0 where t0.id = ? ");
assertSql(sql.get(1)).contains("select t0.code, t0.name from o_country t0 where t0.code = ? ; --bind(NZ,");
}
}
}
@@ -50,8 +50,8 @@ public class TestHistoryOneToMany extends BaseTestCase {
if (isH2()) {
assertThat(sql).hasSize(2);
assertThat(sql.get(0)).contains("from hi_tone_with_history t0 where (t0.sys_period_start <= ? and (t0.sys_period_end is null or t0.sys_period_end > ?)) and lower(t0.name) like ? escape'' limit 10");
assertThat(sql.get(1)).contains("from hi_ttwo_with_history t0 left join hi_tthree_with_history t1 on t1.hi_ttwo_id = t0.id and (t1.sys_period_start <= ? and (t1.sys_period_end is null or t1.sys_period_end > ?)) where (t0.sys_period_start <= ? and (t0.sys_period_end is null or t0.sys_period_end > ?)) and (t0.hi_tone_id) in (?)");
assertSql(sql.get(0)).contains("from hi_tone_with_history t0 where (t0.sys_period_start <= ? and (t0.sys_period_end is null or t0.sys_period_end > ?)) and lower(t0.name) like ? escape'' limit 10");
assertSql(sql.get(1)).contains("from hi_ttwo_with_history t0 left join hi_tthree_with_history t1 on t1.hi_ttwo_id = t0.id and (t1.sys_period_start <= ? and (t1.sys_period_end is null or t1.sys_period_end > ?)) where (t0.sys_period_start <= ? and (t0.sys_period_end is null or t0.sys_period_end > ?)) and (t0.hi_tone_id) in (?)");
}
assertThat(list).hasSize(1);
@@ -29,8 +29,8 @@ public class TestMediaInheritanceJoinToMany extends BaseTestCase {
Assert.assertNotNull(profile);
String generatedSql = query.getGeneratedSql();
assertThat(generatedSql).contains("select t0.id, t0.name, t1.type, t1.id, t1.url, t1.note from mprofile t0 left join mmedia t1 on t1.id = t0.picture_id where t0.name = ?");
assertThat(generatedSql).contains("where t0.name = ?");
assertSql(generatedSql).contains("select t0.id, t0.name, t1.type, t1.id, t1.url, t1.note from mprofile t0 left join mmedia t1 on t1.id = t0.picture_id where t0.name = ?");
assertSql(generatedSql).contains("where t0.name = ?");
}
}
@@ -6,7 +6,7 @@ import org.junit.Test;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
public class TestColumnIdName extends BaseTestCase {
@Test
@@ -18,8 +18,8 @@ public class TestColumnIdName extends BaseTestCase {
final List<Tune> fetchedCollection = Ebean.find(Tune.class).findList();
assertEquals(1, fetchedCollection.size());
assertEquals(1, fetchedCollection.get(0).getLoonies().size());
assertEquals("Taz", fetchedCollection.get(0).getLoonies().get(0).getName());
assertThat(fetchedCollection).hasSize(1);
assertThat(fetchedCollection.get(0).getLoonies()).hasSize(1);
assertThat(fetchedCollection.get(0).getLoonies().get(0).getName()).isEqualTo("Taz");
}
}
@@ -46,8 +46,8 @@ public class TestOneToOneImportedPkNative extends BaseTestCase {
List<String> lazyLoadSql = LoggedSqlCollector.stop();
assertThat(lazyLoadSql).hasSize(2);
assertThat(lazyLoadSql.get(0)).contains("select t0.id, t0.name, t0.id from oto_bmaster t0 where t0.id = ?");
assertThat(lazyLoadSql.get(1)).contains("select t0.master_id, t0.child, t0.master_id from oto_bchild t0 where t0.master_id = ?");
assertSql(lazyLoadSql.get(0)).contains("select t0.id, t0.name, t0.id from oto_bmaster t0 where t0.id = ?");
assertSql(lazyLoadSql.get(1)).contains("select t0.master_id, t0.child, t0.master_id from oto_bchild t0 where t0.master_id = ?");
}
@Test
@@ -35,9 +35,9 @@ public class TestOneToOneOrphanRemove extends BaseTestCase {
List<String> sql = LoggedSqlCollector.current();
assertThat(sql).hasSize(5);
assertThat(sql.get(0)).contains("delete from oto_cust_address where aid=? and version=?");
assertSql(sql.get(0)).contains("delete from oto_cust_address where aid=? and version=?");
assertSqlBind(sql.get(1));
assertThat(sql.get(2)).contains("update oto_cust set version=? where cid=? and version=?");
assertSql(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");
@@ -46,9 +46,9 @@ public class TestOneToOneOrphanRemove extends BaseTestCase {
sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(3);
assertThat(sql.get(0)).contains("delete from oto_cust_address where aid=? and version=?");
assertSql(sql.get(0)).contains("delete from oto_cust_address where aid=? and version=?");
assertSqlBind(sql.get(1));
assertThat(sql.get(2)).contains("update oto_cust set version=? where cid=? and version=?");
assertSql(sql.get(2)).contains("update oto_cust set version=? where cid=? and version=?");
OtoCustAddress foundAddress = Ebean.find(OtoCustAddress.class, address2.getAid());
assertThat(foundAddress).isNull();
@@ -83,9 +83,9 @@ public class TestOneToOneOrphanStringId extends BaseTestCase {
List<String> sql = LoggedSqlCollector.current();
assertThat(sql).hasSize(5);
assertThat(sql.get(0)).contains("insert into oto_aone");
assertSql(sql.get(0)).contains("insert into oto_aone");
assertSqlBind(sql.get(1));
assertThat(sql.get(2)).contains("update oto_atwo set aone_id=? where id=?");
assertSql(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));
@@ -77,7 +77,7 @@ public class TestOneToOnePrimaryKeyJoin extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
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");
assertSql(sql.get(0)).contains("delete from oto_prime_extra where");
assertSql(sql.get(1)).contains("delete from oto_prime where");
}
}
@@ -76,7 +76,7 @@ public class TestOneToOnePrimaryKeyJoinBidi extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
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");
assertSql(sql.get(0)).contains("delete from oto_ubprime_extra where");
assertSql(sql.get(1)).contains("delete from oto_ubprime where");
}
}
@@ -99,7 +99,7 @@ public class TestOneToOnePrimaryKeyJoinOptional extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
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");
assertSql(sql.get(0)).contains("delete from oto_uprime_extra where");
assertSql(sql.get(1)).contains("delete from oto_uprime where");
}
}
@@ -28,9 +28,9 @@ public class DeleteById_SoftDelete_Tests extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(1);
if (isPlatformBooleanNative()) {
assertThat(sql.get(0)).contains("update cover set deleted=true where id = ?");
assertSql(sql.get(0)).contains("update cover set deleted=true where id = ?");
} else {
assertThat(sql.get(0)).contains("update cover set deleted=1 where id = ?");
assertSql(sql.get(0)).contains("update cover set deleted=1 where id = ?");
}
cover.deletePermanent();
@@ -60,7 +60,7 @@ public class DeleteById_SoftDelete_Tests extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(1);
assertThat(sql.get(0)).contains("update cover set deleted=? where id=?; -- bind(false");
assertSql(sql.get(0)).contains("update cover set deleted=? where id=?; -- bind(false");
Cover findAgain = DB.find(Cover.class, cover.getId());
assertNotNull(findAgain);
@@ -81,9 +81,9 @@ public class DeleteById_SoftDelete_Tests extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(1);
if (isPlatformBooleanNative()) {
assertThat(sql.get(0)).contains("update cover set deleted=true where id = ?");
assertSql(sql.get(0)).contains("update cover set deleted=true where id = ?");
} else {
assertThat(sql.get(0)).contains("update cover set deleted=1 where id = ?");
assertSql(sql.get(0)).contains("update cover set deleted=1 where id = ?");
}
cover.deletePermanent();
}
@@ -100,7 +100,7 @@ public class DeleteById_SoftDelete_Tests extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(1);
assertThat(sql.get(0)).contains("delete from cover where id = ?");
assertSql(sql.get(0)).contains("delete from cover where id = ?");
}
@Test
@@ -116,9 +116,9 @@ public class DeleteById_SoftDelete_Tests extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(1);
if (isPlatformBooleanNative()) {
assertThat(sql.get(0)).contains("update cover set deleted=true where id ");
assertSql(sql.get(0)).contains("update cover set deleted=true where id ");
} else {
assertThat(sql.get(0)).contains("update cover set deleted=1 where id ");
assertSql(sql.get(0)).contains("update cover set deleted=1 where id ");
}
}
@@ -138,9 +138,9 @@ public class DeleteById_SoftDelete_Tests extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(1);
if (isPlatformBooleanNative()) {
assertThat(sql.get(0)).contains("update cover set deleted=true where id");
assertSql(sql.get(0)).contains("update cover set deleted=true where id");
} else {
assertThat(sql.get(0)).contains("update cover set deleted=1 where id");
assertSql(sql.get(0)).contains("update cover set deleted=1 where id");
}
}
@@ -206,9 +206,9 @@ public class DeleteById_SoftDelete_Tests extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(3);
if (isPersistBatchOnCascade()) {
assertThat(sql.get(0)).contains("update cover set deleted=? where id=?");
assertSql(sql.get(0)).contains("update cover set deleted=? where id=?");
} else {
assertThat(sql.get(0)).contains("update cover set deleted=? where id=?");
assertSql(sql.get(0)).contains("update cover set deleted=? where id=?");
}
}
@@ -225,10 +225,10 @@ public class DeleteById_SoftDelete_Tests extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(3);
if (isPersistBatchOnCascade()) {
assertThat(sql.get(0)).contains("update cover set deleted=? where id=?");
assertSql(sql.get(0)).contains("update cover set deleted=? where id=?");
}
else {
assertThat(sql.get(0)).contains("update cover set deleted=? where id=?");
assertSql(sql.get(0)).contains("update cover set deleted=? where id=?");
}
}
@@ -248,10 +248,10 @@ public class DeleteById_SoftDelete_Tests extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(3);
if (isPersistBatchOnCascade()) {
assertThat(sql.get(0)).contains("update cover set deleted=? where id=?");
assertSql(sql.get(0)).contains("update cover set deleted=? where id=?");
}
else {
assertThat(sql.get(0)).contains("update cover set deleted=? where id=?");
assertSql(sql.get(0)).contains("update cover set deleted=? where id=?");
}
}
@@ -267,7 +267,7 @@ public class DeleteById_SoftDelete_Tests extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(3);
assertThat(sql.get(0)).contains("delete from cover where id=?");
assertSql(sql.get(0)).contains("delete from cover where id=?");
}
@Test
@@ -285,7 +285,7 @@ public class DeleteById_SoftDelete_Tests extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(3);
assertThat(sql.get(0)).contains("delete from cover where id=?");
assertSql(sql.get(0)).contains("delete from cover where id=?");
}
private List<Long> ids(List<Cover> beans) {
@@ -37,8 +37,8 @@ public class TestOneToOneHardDelete extends BaseTestCase {
// assert we loaded the missing/unloaded foreign key
assertThat(trimSql(sql.get(0), 1)).contains("select t0.id, t0.cover_id from album t0 where t0.id = ?");
// assert soft delete cascaded
assertThat(sql.get(1)).contains("update album set deleted=?, last_update=? where id=?");
assertThat(sql.get(2)).contains("update cover set deleted=? where id=?");
assertSql(sql.get(1)).contains("update album set deleted=?, last_update=? where id=?");
assertSql(sql.get(2)).contains("update cover set deleted=? where id=?");
Album found2 = Album.find.query().setId(album.getId()).setIncludeSoftDeletes().findOne();
@@ -54,7 +54,7 @@ public class TestOneToOneHardDelete extends BaseTestCase {
// assert we loaded the missing/unloaded foreign key
assertThat(trimSql(sql.get(0), 1)).contains("select t0.id, t0.cover_id from album t0 where t0.id = ?");
// assert hard delete cascaded
assertThat(sql.get(1)).contains("delete from album where");
assertThat(sql.get(2)).contains("delete from cover where");
assertSql(sql.get(1)).contains("delete from album where");
assertSql(sql.get(2)).contains("delete from cover where");
}
}
@@ -31,7 +31,7 @@ public class TestOrphanRemoveO2M extends BaseTestCase {
assertThat(Ebean.find(OrpDetail.class, "d2")).isNull();
assertThat(sql).hasSize(3);
assertThat(sql.get(0)).contains("delete from orp_detail where id=?");
assertSql(sql.get(0)).contains("delete from orp_detail where id=?");
assertSqlBind(sql, 1, 2);
}
@@ -26,8 +26,8 @@ public class TestTreeModel extends BaseTestCase {
final List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(5);
assertThat(sql.get(0)).contains("insert into tree_entity");
assertThat(sql.get(1)).contains("insert into tree_entity");
assertSql(sql.get(0)).contains("insert into tree_entity");
assertSql(sql.get(1)).contains("insert into tree_entity");
assertThat(sql.get(3)).contains("insert into tree_entity");
}
@@ -65,6 +65,6 @@ public class TestViewBaseEntity extends BaseTestCase {
assertThat(details).isNotEmpty();
}
assertThat(query.getGeneratedSql()).contains("from order_agg_vw t0 left join o_order t1 on t1.id = t0.order_id left join o_customer t3 on t3.id = t1.kcustomer_id left join o_order_detail t2 on t2.order_id = t1.id and t2.id > 0 where t0.order_total > ?");
assertSql(query).contains("from order_agg_vw t0 left join o_order t1 on t1.id = t0.order_id left join o_customer t3 on t3.id = t1.kcustomer_id left join o_order_detail t2 on t2.order_id = t1.id and t2.id > 0 where t0.order_total > ?");
}
}
@@ -1,5 +1,6 @@
package org.tests.o2m;
import io.ebean.BaseTestCase;
import io.ebean.DB;
import org.ebeantest.LoggedSqlCollector;
import org.junit.Test;
@@ -10,7 +11,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
public class TestOneToManyNoMappedBy {
public class TestOneToManyNoMappedBy extends BaseTestCase {
@Test
public void test() {
@@ -36,6 +37,6 @@ public class TestOneToManyNoMappedBy {
final List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(2);
assertThat(sql.get(1)).contains("select t0.banana_rama_id, t0.id, t0.description, t0.banana_rama_id from om_account_child_dbo t0 where");
assertSql(sql.get(1)).contains("select t0.banana_rama_id, t0.id, t0.description, t0.banana_rama_id from om_account_child_dbo t0 where");
}
}
@@ -39,13 +39,13 @@ public class TestOneToManyJoinTable extends BaseTestCase {
List<String> sql = LoggedSqlCollector.current();
if (isPersistBatchOnCascade()) {
assertThat(sql).hasSize(3);
assertThat(sql.get(0)).contains("insert into troop_monkey (troop_pid, monkey_mid) values (?, ?)");
assertSql(sql.get(0)).contains("insert into troop_monkey (troop_pid, monkey_mid) values (?, ?)");
assertSqlBind(sql, 1, 2);
} else {
assertThat(sql).hasSize(2);
assertThat(sql.get(0)).contains("insert into troop_monkey (troop_pid, monkey_mid) values (?, ?)");
assertThat(sql.get(1)).contains("insert into troop_monkey (troop_pid, monkey_mid) values (?, ?)");
assertSql(sql.get(0)).contains("insert into troop_monkey (troop_pid, monkey_mid) values (?, ?)");
assertSql(sql.get(1)).contains("insert into troop_monkey (troop_pid, monkey_mid) values (?, ?)");
}
long intersectionRows = DB.sqlQuery("select count(*) as total from troop_monkey where troop_pid = ?")
@@ -64,15 +64,15 @@ public class TestOneToManyJoinTable extends BaseTestCase {
sql = LoggedSqlCollector.current();
assertThat(sql).hasSize(1);
assertThat(trimSql(sql.get(0))).contains("from troop t0 left join troop_monkey t1z_ on t1z_.troop_pid = t0.pid left join monkey t1 on t1.mid = t1z_.monkey_mid where t0.pid = ?");
assertThat(trimSql(sql.get(0))).contains("select t0.pid, t0.name, t0.version, t1.mid, t1.name, t1.food_preference, t1.version");
assertSql(sql.get(0)).contains("from troop t0 left join troop_monkey t1z_ on t1z_.troop_pid = t0.pid left join monkey t1 on t1.mid = t1z_.monkey_mid where t0.pid = ?");
assertSql(sql.get(0)).contains("select t0.pid, t0.name, t0.version, t1.mid, t1.name, t1.food_preference, t1.version");
DB.delete(troop);
sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(2);
assertThat(sql.get(0)).contains("delete from troop_monkey where troop_pid = ?");
assertThat(sql.get(1)).contains("delete from troop where pid=? and version=?");
assertSql(sql.get(0)).contains("delete from troop_monkey where troop_pid = ?");
assertSql(sql.get(1)).contains("delete from troop where pid=? and version=?");
insertWithCascade();
@@ -97,8 +97,8 @@ public class TestOneToManyJoinTable extends BaseTestCase {
if (isPersistBatchOnCascade()) {
assertThat(sql).hasSize(13);
assertThat(sql.get(0)).contains("insert into trainer ");
assertThat(sql.get(1)).contains("insert into monkey ");
assertSql(sql.get(0)).contains("insert into trainer ");
assertSql(sql.get(1)).contains("insert into monkey ");
assertSqlBind(sql, 2, 4);
assertThat(sql.get(5)).contains("update monkey set food_preference=?, version=? where mid=? and version=?");
assertThat(sql.get(6)).contains("-- bind(");
@@ -107,9 +107,9 @@ public class TestOneToManyJoinTable extends BaseTestCase {
} else {
assertThat(sql).hasSize(10);
assertThat(sql.get(0)).contains("insert into trainer ");
assertThat(sql.get(1)).contains("update monkey set food_preference=?, version=? where mid=? and version=?");
assertThat(sql.get(2)).contains("insert into monkey ");
assertSql(sql.get(0)).contains("insert into trainer ");
assertSql(sql.get(1)).contains("update monkey set food_preference=?, version=? where mid=? and version=?");
assertSql(sql.get(2)).contains("insert into monkey ");
assertThat(sql.get(5)).contains("insert into trainer_monkey ");
assertThat(sql.get(9)).contains("insert into trainer_monkey ");
}
@@ -128,8 +128,8 @@ public class TestOneToManyJoinTable extends BaseTestCase {
sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(2);
assertThat(sql.get(0)).contains("delete from trainer_monkey where trainer_tid = ?");
assertThat(sql.get(1)).contains("delete from trainer where tid=?");
assertSql(sql.get(0)).contains("delete from trainer_monkey where trainer_tid = ?");
assertSql(sql.get(1)).contains("delete from trainer where tid=?");
}
}
@@ -37,10 +37,10 @@ public class TestOneToManyJoinTableInheritance extends BaseTestCase {
List<String> sql = LoggedSqlCollector.current();
assertThat(sql).hasSize(11);
assertThat(sql.get(0)).contains("insert into class_super ");
assertSql(sql.get(0)).contains("insert into class_super ");
if (idType() == IdType.IDENTITY) {
assertThat(sql.get(1)).contains("-- bind(ClassA)");
assertThat(sql.get(2)).contains("-- bind(ClassB)");
assertSql(sql.get(1)).contains("-- bind(ClassA)");
assertSql(sql.get(2)).contains("-- bind(ClassB)");
}
assertThat(sql.get(3)).contains("insert into monkey ");
if (idType() == IdType.IDENTITY) {
@@ -40,12 +40,12 @@ public class TestOneToManyJoinTableNoTableName extends BaseTestCase {
List<String> sql = LoggedSqlCollector.current();
if (isPersistBatchOnCascade()) {
assertThat(sql).hasSize(3);
assertThat(sql.get(0)).contains("insert into mkeygroup_monkey (mkeygroup_pid, monkey_mid) values (?, ?)");
assertSql(sql.get(0)).contains("insert into mkeygroup_monkey (mkeygroup_pid, monkey_mid) values (?, ?)");
assertSqlBind(sql, 1, 2);
} else {
assertThat(sql).hasSize(2);
assertThat(sql.get(0)).contains("insert into mkeygroup_monkey (mkeygroup_pid, monkey_mid) values (?, ?)");
assertThat(sql.get(1)).contains("insert into mkeygroup_monkey (mkeygroup_pid, monkey_mid) values (?, ?)");
assertSql(sql.get(0)).contains("insert into mkeygroup_monkey (mkeygroup_pid, monkey_mid) values (?, ?)");
assertSql(sql.get(1)).contains("insert into mkeygroup_monkey (mkeygroup_pid, monkey_mid) values (?, ?)");
}
int intersectionRows = DB.sqlQuery("select count(*) as total from mkeygroup_monkey where mkeygroup_pid = ?")
@@ -65,15 +65,15 @@ public class TestOneToManyJoinTableNoTableName extends BaseTestCase {
sql = LoggedSqlCollector.current();
assertThat(sql).hasSize(1);
assertThat(trimSql(sql.get(0))).contains("from mkeygroup t0 left join mkeygroup_monkey t1z_ on t1z_.mkeygroup_pid = t0.pid left join monkey t1 on t1.mid = t1z_.monkey_mid where t0.pid = ?");
assertThat(trimSql(sql.get(0))).contains("select t0.pid, t0.name, t0.version, t1.mid, t1.name, t1.food_preference, t1.version");
assertSql(sql.get(0)).contains("from mkeygroup t0 left join mkeygroup_monkey t1z_ on t1z_.mkeygroup_pid = t0.pid left join monkey t1 on t1.mid = t1z_.monkey_mid where t0.pid = ?");
assertSql(sql.get(0)).contains("select t0.pid, t0.name, t0.version, t1.mid, t1.name, t1.food_preference, t1.version");
Ebean.delete(troop);
sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(2);
assertThat(sql.get(0)).contains("delete from mkeygroup_monkey where mkeygroup_pid = ?");
assertThat(sql.get(1)).contains("delete from mkeygroup where pid=? and version=?");
assertSql(sql.get(0)).contains("delete from mkeygroup_monkey where mkeygroup_pid = ?");
assertSql(sql.get(1)).contains("delete from mkeygroup where pid=? and version=?");
}
@@ -33,7 +33,7 @@ public class TestMyAdHocSqlSelect extends BaseTestCase {
.query();
assertNotNull(query.findList());
assertThat(query.getGeneratedSql()).contains(" group by order_id having count(*) > ?");
assertSql(query).contains(" group by order_id having count(*) > ?");
}
@Test
@@ -56,7 +56,7 @@ public class TestMyAdHocSqlSelect extends BaseTestCase {
.query();
assertNotNull(query.findList());
assertThat(query.getGeneratedSql()).contains(" group by order_id having count(*) > ?");
assertSql(query).contains(" group by order_id having count(*) > ?");
}
@@ -43,9 +43,9 @@ public class TestQueryBaseTable extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(3);
assertThat(sql.get(0)).contains("from O_CUSTOMER");
assertThat(sql.get(1)).contains("from o_customer");
assertThat(sql.get(2)).contains("from O_CUSTOMER");
assertSql(sql.get(0)).contains("from O_CUSTOMER");
assertSql(sql.get(1)).contains("from o_customer");
assertSql(sql.get(2)).contains("from O_CUSTOMER");
}
}
@@ -55,7 +55,7 @@ public class TestQueryExists extends BaseTestCase {
List<Order> ordersThatDontHave = query2.findList();
assertThat(query.getGeneratedSql()).contains(" exists (");
assertSql(query).contains(" exists (");
assertThat(query2.getGeneratedSql()).contains(" not exists (");
assertThat(ordersThatHave).isNotEmpty();
@@ -79,7 +79,7 @@ public class TestQueryExists extends BaseTestCase {
query2.findList();
assertThat(query.getGeneratedSql()).contains(" exists (");
assertSql(query).contains(" exists (");
assertThat(query2.getGeneratedSql()).contains(" not exists (");
assertThat(customersWithContacts).isNotEmpty();
@@ -154,7 +154,7 @@ public class TestQueryFilterMany extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
assertEquals(2, sql.size());
assertThat(sql.get(1)).contains("and (t0.status = ? or t0.order_date = ?");
assertSql(sql.get(1)).contains("and (t0.status = ? or t0.order_date = ?");
}
@Test
@@ -170,11 +170,11 @@ public class TestQueryFilterMany extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(3);
assertThat(sql.get(0)).contains(" from o_customer t0; --bind()");
assertSql(sql.get(0)).contains(" from o_customer t0; --bind()");
platformAssertIn(sql.get(1), " from contact t0 where (t0.customer_id)");
assertThat(sql.get(1)).contains(" and t0.first_name is not null");
assertSql(sql.get(1)).contains(" and t0.first_name is not null");
platformAssertIn(sql.get(2), " from contact_note t0 where (t0.contact_id)");
assertThat(sql.get(2)).contains(" and lower(t0.title) like");
assertSql(sql.get(2)).contains(" and lower(t0.title) like");
}
@Test
@@ -191,8 +191,8 @@ public class TestQueryFilterMany extends BaseTestCase {
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(2);
assertThat(sql.get(0)).contains(" from o_customer t0");
assertThat(sql.get(1)).contains("from contact t0 where ");
assertThat(sql.get(1)).contains("and (t0.first_name is not null and lower(t0.email) like ?");
assertSql(sql.get(0)).contains(" from o_customer t0");
assertSql(sql.get(1)).contains("from contact t0 where ");
assertSql(sql.get(1)).contains("and (t0.first_name is not null and lower(t0.email) like ?");
}
}
@@ -21,9 +21,9 @@ public class TestQueryOrderById extends BaseTestCase {
query.findList();
if (isSqlServer()) {
assertThat(sqlOf(query)).isEqualTo("select t0.id, t0.name from o_customer t0 order by t0.id offset 1 rows fetch next 5 rows only");
assertSql(query).isEqualTo("select t0.id, t0.name from o_customer t0 order by t0.id offset 1 rows fetch next 5 rows only");
} else {
assertThat(sqlOf(query)).isEqualTo("select t0.id, t0.name from o_customer t0 order by t0.id limit 5 offset 1");
assertSql(query).isEqualTo("select t0.id, t0.name from o_customer t0 order by t0.id limit 5 offset 1");
}
}
@@ -38,9 +38,9 @@ public class TestQueryOrderById extends BaseTestCase {
query.findList();
if (isSqlServer()) {
assertThat(sqlOf(query)).isEqualTo("select t0.id, t0.name from o_customer t0 order by t0.id offset 1 rows fetch next 5 rows only");
assertSql(query).isEqualTo("select t0.id, t0.name from o_customer t0 order by t0.id offset 1 rows fetch next 5 rows only");
} else {
assertThat(sqlOf(query)).isEqualTo("select t0.id, t0.name from o_customer t0 order by t0.id limit 5 offset 1");
assertSql(query).isEqualTo("select t0.id, t0.name from o_customer t0 order by t0.id limit 5 offset 1");
}
}
}

Some files were not shown because too many files have changed in this diff Show More