Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Roland Praml committed 2022-02-03 14:56:55 +01:00
commit 1b10b4e742
67 files changed
+356 -390

No files matched your search

+3 -3
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>12.15.0-SNAPSHOT</version>
<version>12.15.1-SNAPSHOT</version>
</parent>
<name>ebean test</name>
@@ -29,14 +29,14 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core</artifactId>
<version>12.15.0-SNAPSHOT</version>
<version>12.15.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-ddl-generator</artifactId>
<version>12.15.0-SNAPSHOT</version>
<version>12.15.1-SNAPSHOT</version>
</dependency>
<dependency>
@@ -195,6 +195,14 @@ public abstract class BaseTestCase {
return Platform.DB2 == platform();
}
public boolean platformDistinctOn() {
return isPostgresCompatible();
}
public boolean isPostgresCompatible() {
return isPostgres() || isYugabyte();
}
public boolean isPostgres() {
return Platform.POSTGRES == platform().base();
}
@@ -273,7 +281,7 @@ public abstract class BaseTestCase {
* Platform specific IN clause assert.
*/
protected void platformAssertIn(String sql, String containsIn) {
if (isPostgres()) {
if (isPostgres() || isYugabyte()) {
assertThat(sql).contains(containsIn+" = any(");
} else {
assertThat(sql).contains(containsIn+" in ");
@@ -285,7 +293,7 @@ public abstract class BaseTestCase {
* Platform specific NOT IN clause assert.
*/
protected void platformAssertNotIn(String sql, String containsIn) {
if (isPostgres()) {
if (isPostgres() || isYugabyte()) {
assertThat(sql).contains(containsIn+" != all(");
} else {
assertThat(sql).contains(containsIn+" not in ");
@@ -11,10 +11,10 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertNotNull;
public class EbeanServer_deleteAllByIdTest extends BaseTestCase {
class EbeanServer_deleteAllByIdTest extends BaseTestCase {
@Test
public void saveAllByVarArgs() {
void saveAllByVarArgs() {
final EBasicVer bean0 = bean("foo0");
final EBasicVer bean1 = bean("foo1");
@@ -41,8 +41,7 @@ public class EbeanServer_deleteAllByIdTest extends BaseTestCase {
}
@Test
public void deleteAllById() {
void deleteAllById() {
List<EBasicVer> someBeans = beans(3);
DB.saveAll(someBeans);
@@ -61,8 +60,7 @@ public class EbeanServer_deleteAllByIdTest extends BaseTestCase {
}
@Test
public void deleteAllById_withTransaction() {
void deleteAllById_withTransaction() {
List<EBasicVer> someBeans = beans(3);
DB.saveAll(someBeans);
@@ -84,8 +82,7 @@ public class EbeanServer_deleteAllByIdTest extends BaseTestCase {
}
@Test
public void deleteAllPermanentById() {
void deleteAllPermanentById() {
List<EBasicVer> someBeans = beans(3);
DB.saveAll(someBeans);
@@ -103,10 +100,8 @@ public class EbeanServer_deleteAllByIdTest extends BaseTestCase {
platformAssertIn(loggedSql.get(0), "delete from e_basicver where id ");
}
@Test
public void deleteAllPermanentById_withTransaction() {
void deleteAllPermanentById_withTransaction() {
List<EBasicVer> someBeans = beans(3);
DB.saveAll(someBeans);
@@ -117,7 +117,7 @@ public class UpdateQueryTest extends BaseTestCase {
assertThat(sql).hasSize(1);
assertThat(rows).isEqualTo(0);
if (isPostgres()) {
if (isPostgresCompatible()) {
assertSql(sql.get(0)).contains("update o_customer set status = ? where id = any(?)");
} else {
assertSql(sql.get(0)).contains("update o_customer set status = ? where id in (?,?,?,?,?)"); // bind padding to 5
@@ -121,7 +121,7 @@ public class IsEmptyExpressionQueryTest extends BaseTestCase {
.query();
query.findList();
if (isPostgres()) {
if (platformDistinctOn()) {
assertThat(sqlOf(query)).contains("select distinct on (t0.id) t0.id from o_customer t0 join contact u1 on u1.customer_id = t0.id where not exists (select 1 from contact_note x where x.contact_id = u1.id)");
} else {
@@ -140,7 +140,7 @@ public class IsEmptyExpressionQueryTest extends BaseTestCase {
.query();
query.findList();
if (isPostgres()) {
if (platformDistinctOn()) {
assertThat(sqlOf(query)).contains("select distinct on (t0.id) t0.id from o_customer t0 join contact u1 on u1.customer_id = t0.id where exists (select 1 from contact_note x where x.contact_id = u1.id)");
} else {
@@ -22,17 +22,15 @@ import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class EqlParserTest extends BaseTestCase {
class EqlParserTest extends BaseTestCase {
@Test
public void illegal_syntax() {
void illegal_syntax() {
assertThrows(IllegalArgumentException.class, () -> parse("find Article where name = :p0"));
}
@Test
public void where_eq() {
void where_eq() {
Query<Customer> query = parse("where name eq 'Rob'");
query.findList();
@@ -40,7 +38,7 @@ public class EqlParserTest extends BaseTestCase {
}
@Test
public void where_eqOrNull_bindVal() {
void where_eqOrNull_bindVal() {
Query<Customer> query = parse("where name eqOrNull 'Rob'");
query.findList();
@@ -48,7 +46,7 @@ public class EqlParserTest extends BaseTestCase {
}
@Test
public void where_eqOrNull_bindNamed() {
void where_eqOrNull_bindNamed() {
Query<Customer> query = parse("where name eqOrNull :name");
query.setParameter("name", "Rob");
query.findList();
@@ -57,8 +55,7 @@ public class EqlParserTest extends BaseTestCase {
}
@Test
public void where_eqOrNull_bindPositioned() {
void where_eqOrNull_bindPositioned() {
final Query<Customer> query = where("name eqOrNull ?", "Rob");
query.findList();
if (isH2()) {
@@ -67,8 +64,7 @@ public class EqlParserTest extends BaseTestCase {
}
@Test
public void where_eqOrNull_bindPositioned_asNull() {
void where_eqOrNull_bindPositioned_asNull() {
final Query<Customer> query = where("name eqOrNull ?", (String)null);
query.findList();
if (isH2()) {
@@ -77,8 +73,7 @@ public class EqlParserTest extends BaseTestCase {
}
@Test
public void where_gtOrNull_bindPositioned() {
void where_gtOrNull_bindPositioned() {
final Query<Customer> query = where("name gtOrNull ?", "Rob");
query.findList();
if (isH2()) {
@@ -87,8 +82,7 @@ public class EqlParserTest extends BaseTestCase {
}
@Test
public void where_geOrNull_bindPositioned() {
void where_geOrNull_bindPositioned() {
final Query<Customer> query = where("name geOrNull ?", "Rob");
query.findList();
if (isH2()) {
@@ -97,8 +91,7 @@ public class EqlParserTest extends BaseTestCase {
}
@Test
public void where_ltOrNull_bindPositioned() {
void where_ltOrNull_bindPositioned() {
final Query<Customer> query = where("name ltOrNull ?", "Rob");
query.findList();
if (isH2()) {
@@ -107,8 +100,7 @@ public class EqlParserTest extends BaseTestCase {
}
@Test
public void where_leOrNull_bindPositioned() {
void where_leOrNull_bindPositioned() {
final Query<Customer> query = where("name leOrNull ?", "Rob");
query.findList();
if (isH2()) {
@@ -117,8 +109,7 @@ public class EqlParserTest extends BaseTestCase {
}
@Test
public void where_eq_reverse() {
void where_eq_reverse() {
Query<Customer> query = parse("where 'Rob' eq name");
query.findList();
@@ -126,40 +117,35 @@ public class EqlParserTest extends BaseTestCase {
}
@Test
public void where_gt_reverse() {
void where_gt_reverse() {
Query<Customer> query = parse("where 'Rob' > name");
query.findList();
assertSql(query).contains("where t0.name < ?");
}
@Test
public void where_gte_reverse() {
void where_gte_reverse() {
Query<Customer> query = parse("where 'Rob' >= name");
query.findList();
assertSql(query).contains("where t0.name <= ?");
}
@Test
public void where_lt_reverse() {
void where_lt_reverse() {
Query<Customer> query = parse("where 'Rob' < name");
query.findList();
assertSql(query).contains("where t0.name > ?");
}
@Test
public void where_lte_reverse() {
void where_lte_reverse() {
Query<Customer> query = parse("where 'Rob' <= name");
query.findList();
assertSql(query).contains("where t0.name >= ?");
}
@Test
public void where_ieq() {
void where_ieq() {
Query<Customer> query = parse("where name ieq 'Rob'");
query.findList();
@@ -167,8 +153,7 @@ public class EqlParserTest extends BaseTestCase {
}
@Test
public void where_ine() {
void where_ine() {
Query<Customer> query = parse("where name ine 'Rob'");
query.findList();
@@ -176,16 +161,14 @@ public class EqlParserTest extends BaseTestCase {
}
@Test
public void where_ieq_reverse() {
void where_ieq_reverse() {
Query<Customer> query = parse("where 'Rob' ieq name");
query.findList();
assertSql(query).contains("where lower(t0.name) = ?");
}
@Test
public void where_ine_reverse() {
void where_ine_reverse() {
Query<Customer> query = parse("where 'Rob' ine name");
query.findList();
@@ -193,8 +176,7 @@ public class EqlParserTest extends BaseTestCase {
}
@Test
public void where_eq2() {
void where_eq2() {
Query<Customer> query = parse("where name = 'Rob'");
query.findList();
@@ -202,8 +184,7 @@ public class EqlParserTest extends BaseTestCase {
}
@Test
public void where_namedParam() {
void where_namedParam() {
Query<Customer> query = parse("where name eq :name");
query.setParameter("name", "Rob");
query.findList();
@@ -212,7 +193,7 @@ public class EqlParserTest extends BaseTestCase {
}
@Test
public void where_namedParam_otherOrder() {
void where_namedParam_otherOrder() {
Query<Customer> query = parse("where :nm < name");
query.setParameter("nm", "Rob");
query.findList();
@@ -221,8 +202,7 @@ public class EqlParserTest extends BaseTestCase {
}
@Test
public void where_namedParam_startsWith() {
void where_namedParam_startsWith() {
Query<Customer> query = parse("where name startsWith :name");
query.setParameter("name", "Rob");
query.findList();
@@ -232,8 +212,7 @@ public class EqlParserTest extends BaseTestCase {
@Test
@IgnorePlatform({Platform.HANA, Platform.DB2}) // The HANA JDBC driver checks the field length on binding and rejects 'NEW'
public void where_or1() {
void where_or1() {
Query<Customer> query = parse("where name = 'Rob' or (status = 'NEW' and smallnote is null)");
query.findList();
@@ -242,8 +221,7 @@ public class EqlParserTest extends BaseTestCase {
@Test
@ForPlatform({Platform.HANA, Platform.DB2})
public void where_or1_hana() {
void where_or1_hana() {
Query<Customer> query = parse("where name = 'Rob' or (status = 'N' and smallnote is null)");
query.findList();
@@ -252,8 +230,7 @@ public class EqlParserTest extends BaseTestCase {
@Test
@IgnorePlatform({Platform.HANA, Platform.DB2}) // The HANA & DB2 JDBC driver checks the field length on binding and rejects 'NEW'
public void where_or2() {
void where_or2() {
Query<Customer> query = parse("where (name = 'Rob' or status = 'NEW') and smallnote is null");
query.findList();
@@ -262,8 +239,7 @@ public class EqlParserTest extends BaseTestCase {
@Test
@ForPlatform({Platform.HANA, Platform.DB2})
public void where_or2_hana() {
void where_or2_hana() {
Query<Customer> query = parse("where (name = 'Rob' or status = 'N') and smallnote is null");
query.findList();
@@ -272,8 +248,7 @@ public class EqlParserTest extends BaseTestCase {
@Test
@IgnorePlatform({Platform.HANA, Platform.DB2}) // The HANA & DB2 JDBC driver checks the field length on binding and rejects 'NEW'
public void test_simplifyExpressions() {
void test_simplifyExpressions() {
Query<Customer> query = parse("where not (name = 'Rob' and status = 'NEW')");
query.findList();
assertSql(query).contains("where not (t0.name = ? and t0.status = ?)");
@@ -289,8 +264,7 @@ public class EqlParserTest extends BaseTestCase {
@Test
@ForPlatform({Platform.HANA, Platform.DB2})
public void test_simplifyExpressions_hana() {
void test_simplifyExpressions_hana() {
Query<Customer> query = parse("where not (name = 'Rob' and status = 'N')");
query.findList();
assertSql(query).contains("where not (t0.name = ? and t0.status = ?)");
@@ -305,8 +279,7 @@ public class EqlParserTest extends BaseTestCase {
}
@Test
public void where_in() {
void where_in() {
Query<Customer> query = parse("where name in ('Rob','Jim')");
query.findList();
@@ -314,8 +287,7 @@ public class EqlParserTest extends BaseTestCase {
}
@Test
public void where_in_when_namedParams() {
void where_in_when_namedParams() {
Query<Customer> query = parse("where name in (:one, :two)");
query.setParameter("one", "Foo");
query.setParameter("two", "Bar");
@@ -325,8 +297,7 @@ public class EqlParserTest extends BaseTestCase {
}
@Test
public void where_in_when_namedParams_withWhitespace() {
void where_in_when_namedParams_withWhitespace() {
Query<Customer> query = parse("where name in (:one, :two)");
query.setParameter("one", "Foo");
query.setParameter("two", "Bar");
@@ -336,8 +307,7 @@ public class EqlParserTest extends BaseTestCase {
}
@Test
public void where_in_when_namedParams_withNoWhitespace() {
void where_in_when_namedParams_withNoWhitespace() {
Query<Customer> query = parse("where name in (:one,:two)");
query.setParameter("one", "Foo");
query.setParameter("two", "Bar");
@@ -347,8 +317,7 @@ public class EqlParserTest extends BaseTestCase {
}
@Test
public void where_in_when_namedParamAsList() {
void where_in_when_namedParamAsList() {
Query<Customer> query = parse("where name in (:names)");
query.setParameter("names", Arrays.asList("Baz", "Maz", "Jim"));
query.findList();
@@ -357,60 +326,49 @@ public class EqlParserTest extends BaseTestCase {
}
@Test
public void where_inOrEmpty_withVals() {
void where_inOrEmpty_withVals() {
final Query<Customer> query = where("name inOrEmpty ?", Arrays.asList("Baz", "Maz", "Jim"));
query.findList();
platformAssertIn(query.getGeneratedSql(), "where t0.name");
}
@Test
public void where_inOrEmpty_withValsAsSet() {
void where_inOrEmpty_withValsAsSet() {
final Query<Customer> query = where("name inOrEmpty ?", new HashSet<>(Arrays.asList("Baz", "Maz", "Jim")));
query.findList();
platformAssertIn(query.getGeneratedSql(), "where t0.name");
}
@Test
public void where_inOrEmpty_withEmpty() {
void where_inOrEmpty_withEmpty() {
final Query<Customer> query = where("name inOrEmpty ?", new ArrayList());
query.findList();
assertSql(query).doesNotContain("where");
}
@Test
public void where_inOrEmpty_withNull() {
void where_inOrEmpty_withNull() {
List<String> names = null;
final Query<Customer> query = where("name inOrEmpty ?", names);
query.findList();
assertSql(query).doesNotContain("where");
}
@Test//(expected = IllegalArgumentException.class)
public void query_inOrEmpty_withVals() {
@Test
void query_inOrEmpty_withVals() {
assertThrows(IllegalArgumentException.class, () -> parse("where name inOrEmpty (:names)"));
// query.setParameter("names", Arrays.asList("Baz", "Maz", "Jim"));
// query.findList();
// platformAssertIn(query.getGeneratedSql(), "where t0.name");
}
/**
* This test fails in that we can't use inOrEmpty with named parameters.
*/
@Test//(expected = IllegalArgumentException.class)
public void query_inOrEmpty_withNamedParams_expect_IllegalArgument() {
@Test
void query_inOrEmpty_withNamedParams_expect_IllegalArgument() {
assertThrows(IllegalArgumentException.class, () -> parse("where name inOrEmpty (:names)"));
// query.setParameter("names", new ArrayList<>());
// assertThrows(IllegalArgumentException.class, query::findList);
// assertSql(query).doesNotContain("where");
}
@Test
public void where_inrange() {
void where_inrange() {
Query<Customer> query = parse("where name inrange 'As' to 'B'");
query.findList();
@@ -418,8 +376,7 @@ public class EqlParserTest extends BaseTestCase {
}
@Test
public void where_inrange_withNamedParams() {
void where_inrange_withNamedParams() {
Query<Customer> query = parse("where name inrange :one to :two");
query.setParameter("one", "a");
query.setParameter("two", "b");
@@ -429,8 +386,7 @@ public class EqlParserTest extends BaseTestCase {
}
@Test
public void where_between() {
void where_between() {
Query<Customer> query = parse("where name between 'As' and 'B'");
query.findList();
@@ -438,8 +394,7 @@ public class EqlParserTest extends BaseTestCase {
}
@Test
public void where_between_withNamedParams() {
void where_between_withNamedParams() {
Query<Customer> query = parse("where name between :one and :two");
query.setParameter("one", "a");
query.setParameter("two", "b");
@@ -449,8 +404,7 @@ public class EqlParserTest extends BaseTestCase {
}
@Test
public void where_betweenProperty() {
void where_betweenProperty() {
Query<Customer> query = parse("where 'x' between name and smallnote");
query.findList();
@@ -458,8 +412,7 @@ public class EqlParserTest extends BaseTestCase {
}
@Test
public void where_betweenProperty_withNamed() {
void where_betweenProperty_withNamed() {
Query<Customer> query = parse("where :some between name and smallnote");
query.setParameter("some", "A");
query.findList();
@@ -468,8 +421,7 @@ public class EqlParserTest extends BaseTestCase {
}
@Test
public void selectFetch_basic() {
void selectFetch_basic() {
Query<Customer> query = parse("select name fetch billingAddress");
query.findList();
@@ -477,8 +429,7 @@ public class EqlParserTest extends BaseTestCase {
}
@Test
public void selectFetch_basic2() {
void selectFetch_basic2() {
ResetBasicData.reset();
Query<Customer> query = parse("select name, status fetch billingAddress");
@@ -488,8 +439,7 @@ public class EqlParserTest extends BaseTestCase {
}
@Test
public void selectFetch_withProperties() {
void selectFetch_withProperties() {
Query<Customer> query = parse("select name fetch billingAddress (line1, city) ");
query.findList();
@@ -498,8 +448,7 @@ public class EqlParserTest extends BaseTestCase {
@Test
@IgnorePlatform(Platform.SQLSERVER)
public void selectFetchFetchLimit() {
void selectFetchFetchLimit() {
Query<Customer> query = parse("select name fetch billingAddress (line1, city) fetch shippingAddress (line1) limit 10");
query.findList();
@@ -507,18 +456,15 @@ public class EqlParserTest extends BaseTestCase {
}
@Test
public void selectFetchFetchMany() {
void selectFetchFetchMany() {
Query<Customer> query = parse("select name fetch billingAddress (line1, city) fetch contacts");
query.findList();
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");
}
@Test
public void selectFetchFetchManyProperties() {
void selectFetchFetchManyProperties() {
Query<Customer> query = parse("select name fetch billingAddress (line1, city) fetch contacts (email)");
query.findList();
@@ -527,8 +473,7 @@ public class EqlParserTest extends BaseTestCase {
@Test
@IgnorePlatform(Platform.SQLSERVER)
public void selectFetchFetchManyPropertiesLimit() {
void selectFetchFetchManyPropertiesLimit() {
ResetBasicData.reset();
LoggedSql.start();
@@ -543,8 +488,7 @@ public class EqlParserTest extends BaseTestCase {
}
@Test
public void fetch_basic() {
void fetch_basic() {
Query<Customer> query = parse("fetch billingAddress");
query.findList();
@@ -552,8 +496,7 @@ public class EqlParserTest extends BaseTestCase {
}
@Test
public void fetch_withProperty() {
void fetch_withProperty() {
Query<Customer> query = parse("fetch billingAddress (city)");
query.findList();
@@ -561,8 +504,7 @@ public class EqlParserTest extends BaseTestCase {
}
@Test
public void fetch_withProperty_noWhitespace() {
void fetch_withProperty_noWhitespace() {
Query<Customer> query = parse("fetch billingAddress(city)");
query.findList();
@@ -570,8 +512,7 @@ public class EqlParserTest extends BaseTestCase {
}
@Test
public void fetch_basic_multiple() {
void fetch_basic_multiple() {
Query<Customer> query = parse("fetch billingAddress fetch shippingAddress");
query.findList();
@@ -580,8 +521,7 @@ public class EqlParserTest extends BaseTestCase {
}
@Test
public void fetch_basic_multiple_withProperties() {
void fetch_basic_multiple_withProperties() {
Query<Customer> query = parse("fetch billingAddress (city) fetch shippingAddress (city)");
query.findList();
@@ -589,8 +529,7 @@ public class EqlParserTest extends BaseTestCase {
}
@Test
public void fetch_lazy() {
void fetch_lazy() {
Query<Customer> query = parse("fetch lazy billingAddress");
query.findList();
@@ -598,8 +537,7 @@ public class EqlParserTest extends BaseTestCase {
}
@Test
public void fetch_lazy50() {
void fetch_lazy50() {
Query<Customer> query = parse("fetch lazy(50) billingAddress");
query.findList();
@@ -607,8 +545,7 @@ public class EqlParserTest extends BaseTestCase {
}
@Test
public void fetch_query50() {
void fetch_query50() {
ResetBasicData.reset();
Query<Customer> query = parse("fetch query(50) billingAddress");
query.findList();
@@ -617,8 +554,7 @@ public class EqlParserTest extends BaseTestCase {
}
@Test
public void fetch_query50_asHint() {
void fetch_query50_asHint() {
ResetBasicData.reset();
Query<Customer> query = parse("fetch query(50) billingAddress (city)");
query.findList();
@@ -627,8 +563,7 @@ public class EqlParserTest extends BaseTestCase {
}
@Test
public void fetch_lazy50_asHint() {
void fetch_lazy50_asHint() {
ResetBasicData.reset();
Query<Customer> query = parse("fetch lazy(50) billingAddress (city) order by id");
List<Customer> list = query.findList();
@@ -640,8 +575,7 @@ public class EqlParserTest extends BaseTestCase {
}
@Test
public void select() {
void select() {
ResetBasicData.reset();
Query<Customer> query = parse("select (name)");
@@ -654,8 +588,7 @@ public class EqlParserTest extends BaseTestCase {
}
@Test
public void select_sum() {
void select_sum() {
ResetBasicData.reset();
Query<Customer> query = parse("select (sum(id))");
@@ -664,8 +597,7 @@ public class EqlParserTest extends BaseTestCase {
}
@Test
public void select_max() {
void select_max() {
ResetBasicData.reset();
Query<Customer> query = parse("select (max(cretime))");
@@ -678,8 +610,7 @@ public class EqlParserTest extends BaseTestCase {
}
@Test
public void select_agg() {
void select_agg() {
ResetBasicData.reset();
Query<Customer> query = parse("select status, max(cretime)");
@@ -690,8 +621,7 @@ public class EqlParserTest extends BaseTestCase {
}
@Test
public void select_agg_sum() {
void select_agg_sum() {
ResetBasicData.reset();
Query<OrderDetail> query = DB.createQuery(OrderDetail.class, "select sum(orderQty) fetch `order` (id)");
@@ -702,8 +632,7 @@ public class EqlParserTest extends BaseTestCase {
}
@Test
public void selectDistinct() {
void selectDistinct() {
ResetBasicData.reset();
Query<Customer> query = parse("select distinct (name)");
@@ -711,10 +640,8 @@ public class EqlParserTest extends BaseTestCase {
assertSql(query).contains("select distinct t0.name from o_customer t0");
}
@Test
public void limit() {
void limit() {
ResetBasicData.reset();
Query<Customer> query = parse("limit 10");
@@ -725,8 +652,7 @@ public class EqlParserTest extends BaseTestCase {
}
@Test
public void limitOffset() {
void limitOffset() {
ResetBasicData.reset();
Query<Customer> query = parse("order by name limit 10 offset 5");
@@ -737,8 +663,7 @@ public class EqlParserTest extends BaseTestCase {
}
@Test
public void orderBy() {
void orderBy() {
ResetBasicData.reset();
Query<Customer> query = parse("order by id");
@@ -749,8 +674,7 @@ public class EqlParserTest extends BaseTestCase {
}
@Test
public void orderBy_desc() {
void orderBy_desc() {
ResetBasicData.reset();
Query<Customer> query = parse("order by id desc");
@@ -761,8 +685,7 @@ public class EqlParserTest extends BaseTestCase {
}
@Test
public void orderBy_nullsLast() {
void orderBy_nullsLast() {
if (!isPlatformOrderNullsSupport()) {
return;
}
@@ -777,8 +700,7 @@ public class EqlParserTest extends BaseTestCase {
}
@Test
public void orderBy_nullsFirst() {
void orderBy_nullsFirst() {
if (!isPlatformOrderNullsSupport()) {
return;
}
@@ -792,8 +714,7 @@ public class EqlParserTest extends BaseTestCase {
}
@Test
public void orderBy_multiple() {
void orderBy_multiple() {
if (!isPlatformOrderNullsSupport()) {
return;
}
@@ -807,15 +728,13 @@ public class EqlParserTest extends BaseTestCase {
}
private Query<Customer> parse(String raw) {
Query<Customer> query = DB.find(Customer.class);
EqlParser.parse(raw, (SpiQuery<?>) query);
return query;
}
@Test
public void where_simple() {
void where_simple() {
final Query<Customer> query = where("name isNotNull");
query.findList();
if (isH2()) {
@@ -824,8 +743,7 @@ public class EqlParserTest extends BaseTestCase {
}
@Test
public void where_withParams() {
void where_withParams() {
final Query<Customer> query = where("id isNotNull and name = ? and smallnote istartsWith ?", "Rob", "Foo");
query.findList();
if (isH2()) {
@@ -834,8 +752,7 @@ public class EqlParserTest extends BaseTestCase {
}
@Test
public void where_withParamsQuPos() {
void where_withParamsQuPos() {
final Query<Customer> query = where("name = ?1 and smallnote istartsWith ?2 and name like ?1", "Rob", "Foo");
query.findList();
if (isH2()) {
@@ -844,8 +761,7 @@ public class EqlParserTest extends BaseTestCase {
}
@Test
public void where_orSimple() {
void where_orSimple() {
final Query<Customer> query = where("id isNotNull or name = ?", "Rob", "Foo");
query.findList();
if (isH2()) {
@@ -854,8 +770,7 @@ public class EqlParserTest extends BaseTestCase {
}
@Test
public void where_orWithParams() {
void where_orWithParams() {
final Query<Customer> query = where("(id isNotNull or name = ?) and smallnote istartsWith ?", "Rob", "Foo");
query.findList();
if (isH2()) {
@@ -864,8 +779,7 @@ public class EqlParserTest extends BaseTestCase {
}
@Test
public void where_dateInRange() {
void where_dateInRange() {
final Query<Customer> query = where("anniversary inrange ? to ?", LocalDate.now().minusDays(7), LocalDate.now());
query.findList();
if (isH2()) {
@@ -874,8 +788,7 @@ public class EqlParserTest extends BaseTestCase {
}
@Test
public void where_dateInRange_camelCase() {
void where_dateInRange_camelCase() {
final Query<Customer> query = where("anniversary inRange ? to ?", LocalDate.now().minusDays(7), LocalDate.now());
query.findList();
if (isH2()) {
@@ -884,10 +797,8 @@ public class EqlParserTest extends BaseTestCase {
}
private Query<Customer> where(String where, Object... params) {
Query<Customer> query = DB.find(Customer.class);
EqlParser.parseWhere(where, query.where(), query.getExpressionFactory(), params);
return query;
}
}
@@ -207,13 +207,9 @@ public class TestRawSqlBuilder extends BaseTestCase {
assertEquals(5, columnMapping.getIndexPosition("dataMonth"));
}
@ForPlatform(Platform.POSTGRES)
@Test
public void postgres_parse_withDateTruncCaseHaving() {
if (!isPostgres()) {
return;
}
ResetBasicData.reset();
String sql = "select DATE_TRUNC('DAY', d.order_date) as day," +
@@ -34,8 +34,6 @@ public class TestQueryForUpdate extends BaseTestCase {
if (isSqlServer()) {
assertThat(sqlOf(query)).contains("with (updlock)");
} else if (isPostgres()) {
assertThat(sqlOf(query)).contains("for update");
} else {
assertThat(sqlOf(query)).contains("for update");
}
@@ -134,14 +132,10 @@ public class TestQueryForUpdate extends BaseTestCase {
List<String> sql = LoggedSql.stop();
assertThat(sql).hasSize(2);
if (isH2() || isPostgres()) {
if (isH2() || isPostgresCompatible()) {
assertSql(sql.get(0)).contains("from e_basic t0 where t0.id =");
assertSql(sql.get(1)).contains("from e_basic t0 where t0.id =");
if (isPostgres()) {
assertSql(sql.get(1)).contains("for update");
} else {
assertSql(sql.get(1)).contains("for update");
}
assertSql(sql.get(1)).contains("for update");
}
transaction.end();
@@ -165,8 +159,6 @@ public class TestQueryForUpdate extends BaseTestCase {
assertThat(sqlOf(query)).contains("for update");
} else if (isSqlServer()) {
assertThat(sqlOf(query)).contains("with (updlock,nowait)");
} else if (isPostgres()) {
assertThat(sqlOf(query)).contains("for update nowait");
} else {
assertThat(sqlOf(query)).contains("for update nowait");
}
@@ -192,8 +184,6 @@ public class TestQueryForUpdate extends BaseTestCase {
assertThat(sqlOf(query)).contains("with (updlock,nowait)");
} else if (isH2()) {
assertThat(sqlOf(query)).contains("for update");
} else if (isPostgres()) {
assertThat(sqlOf(query)).contains("for update nowait");
} else {
assertThat(sqlOf(query)).contains("for update nowait");
}
@@ -26,8 +26,7 @@ public class TestInetAddressType extends TransactionalTestCase {
@Test
public void testIp6() throws UnknownHostException {
if (isPostgres() || isYugabyte()) {
if (isPostgresCompatible()) {
insertUpdateDeleteFind("2001:db8:85a3:0:0:8a2e:370:7334", "2001:db8:85a3::8a2e:370:7334", "2001:4f8:3:ba::/64", "2001:4f8:3:ba::/64");
} else {
insertUpdateDeleteFind("2001:db8:85a3:0:0:8a2e:370:7334", "2001:db8:85a3:0:0:8a2e:370:7334", "192.168.100.128/25", "192.168.100.128/25");
@@ -43,7 +43,7 @@ public class TestSqlRowUUID extends BaseTestCase {
assertThat(value).isEqualTo(e.getId());
if (isPostgres()) {
if (isPostgresCompatible()) {
usingPostrgesAnyWithPositionedParameter_needsExplicitCast(e);
}
}
@@ -86,7 +86,7 @@ public class TestOnCascadeDeleteChildrenWithCompositeKeys extends BaseTestCase {
beanProperty.findIdsByParentId(null, ids, null, null, true);
beanProperty.findIdsByParentId(1L, null, null, null, true);
}
/**
* Test makes select and a select distinct of entities with composite keys.
*/
@@ -106,7 +106,7 @@ public class TestOnCascadeDeleteChildrenWithCompositeKeys extends BaseTestCase {
query1.setDistinct(true).setCountDistinct(CountDistinctOrder.COUNT_DESC_ATTR_ASC).setMaxRows(20);
query1.findSingleAttributeList();
if (isH2() || isMariaDB() || isPostgres()) {
if (isH2() || isMariaDB() || isPostgresCompatible()) {
assertThat(query1.getGeneratedSql()).contains("select distinct r1.attribute_, count(*) from "
+ "(select distinct t0.user_id, t0.role_id, t1.name as attribute_ "
+ "from em_user_role t0 join em_user t1 on t1.id = t0.user_id) r1 "
@@ -40,7 +40,7 @@ public class TestDeleteByQuery extends BaseTestCase {
assertSql(sql.get(0)).contains("delete from bbookmark_user where id in (select top 3 t0.id from bbookmark_user t0 where t0.name like ");
} else {
assertSql(sql.get(0)).contains("delete from bbookmark_user where id in (select t0.id from bbookmark_user t0 where t0.name like");
if (isH2() || isPostgres()) {
if (isH2() || isPostgresCompatible()) {
assertSql(sql.get(0)).contains("limit 3");
}
}
@@ -139,7 +139,7 @@ public class TestHistoryInsert extends BaseTestCase {
assertThat(sql).hasSize(1);
if (isH2()) {
assertThat(sql.get(0)).contains("and t0.sys_period_start < ? and (t0.sys_period_end >= ? or t0.sys_period_end is null)");
} else if (isPostgres()) {
} else if (isPostgresCompatible()) {
assertThat(sql.get(0)).contains("and lower(t0.sys_period) < ? and (upper(t0.sys_period) >= ? or upper(t0.sys_period) is null)");
}
@@ -85,7 +85,7 @@ public class TestCarWheelIud extends BaseTestCase {
final List<String> sql = LoggedSql.stop();
assertThat(sql).hasSize(2);
if (isH2() || isPostgres()) {
if (isH2() || isPostgresCompatible()) {
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)");
}
@@ -49,7 +49,7 @@ public class TestAggregationTopLevel extends BaseTestCase {
List<String> sql = LoggedSql.stop();
assertThat(sql).hasSize(2);
if (isH2() || isPostgres()) {
if (isH2() || isPostgresCompatible()) {
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()) {
@@ -8,6 +8,7 @@ import io.ebean.annotation.NotNull;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Version;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
@@ -38,7 +39,7 @@ public class EArrayBean {
List<Long> otherIds = new ArrayList<>();
@DbArray
List<Double> doubs;
List<BigDecimal> decimals;
@DbArray
List<Status> statuses;
@@ -103,12 +104,12 @@ public class EArrayBean {
this.otherIds = otherIds;
}
public List<Double> getDoubs() {
return doubs;
public List<BigDecimal> getDecimals() {
return decimals;
}
public void setDoubs(List<Double> doubs) {
this.doubs = doubs;
public void setDecimals(List<BigDecimal> decimals) {
this.decimals = decimals;
}
public List<Status> getStatuses() {
@@ -53,7 +53,7 @@ public class TestDbArray_asSet extends BaseTestCase {
assertThat(found.getPhoneNumbers()).containsExactly("4321", "9823");
if (isPostgres()) {
if (isPostgresCompatible()) {
Query<EArraySetBean> query = DB.find(EArraySetBean.class)
.where()
.arrayContains("otherIds", 96L, 97L)
@@ -7,6 +7,7 @@ import io.ebean.annotation.Platform;
import io.ebean.test.LoggedSql;
import org.junit.jupiter.api.Test;
import java.math.BigDecimal;
import java.sql.SQLException;
import java.util.*;
@@ -14,7 +15,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
public class TestDbArray_basic extends BaseTestCase {
class TestDbArray_basic extends BaseTestCase {
private final EArrayBean bean = new EArrayBean();
@@ -22,7 +23,7 @@ public class TestDbArray_basic extends BaseTestCase {
@Test
@IgnorePlatform(Platform.HANA)
public void insert() throws SQLException {
void insert() throws SQLException {
DB.find(EArrayBean.class).delete();
bean.setName("some stuff");
assertThat(bean.getStatuses()).as("DbArray is auto initialised").isNotNull();
@@ -31,17 +32,16 @@ public class TestDbArray_basic extends BaseTestCase {
phNumbers.add("4321");
phNumbers.add("9823");
List<Double> doubles = new ArrayList<>();
doubles.add(1.3);
doubles.add(2.4);
List<BigDecimal> doubles = new ArrayList<>();
doubles.add(BigDecimal.valueOf(1.3));
doubles.add(BigDecimal.valueOf(2.4));
bean.getUids().add(UUID.randomUUID());
bean.getUids().add(UUID.randomUUID());
bean.getOtherIds().add(95L);
bean.getOtherIds().add(96L);
bean.getOtherIds().add(97L);
bean.setDoubs(doubles);
bean.setDecimals(doubles);
bean.setStatuses(new ArrayList<>());
bean.getStatuses().add(EArrayBean.Status.ONE);
bean.getStatuses().add(EArrayBean.Status.THREE);
@@ -60,7 +60,7 @@ public class TestDbArray_basic extends BaseTestCase {
assertThat(found.getPhoneNumbers()).containsExactly("4321", "9823");
if (isPostgres()) {
if (isPostgresCompatible()) {
Query<EArrayBean> query = DB.find(EArrayBean.class)
.where()
.arrayContains("otherIds", 96L, 97L)
@@ -118,7 +118,7 @@ public class TestDbArray_basic extends BaseTestCase {
}
//@Test//(dependsOnMethods = "insert")
public void json_parse_format() {
void json_parse_format() {
String asJson = DB.json().toJson(found);
assertThat(asJson).contains("\"phoneNumbers\":[\"4321\",\"9823\"]");
@@ -132,7 +132,7 @@ public class TestDbArray_basic extends BaseTestCase {
}
//@Test//(dependsOnMethods = "insert")
public void update_when_notDirty() {
void update_when_notDirty() {
found.setName("jack");
LoggedSql.start();
@@ -144,7 +144,7 @@ public class TestDbArray_basic extends BaseTestCase {
}
//@Test//(dependsOnMethods = "update_when_notDirty")
public void update_when_dirty() {
void update_when_dirty() {
found.getPhoneNumbers().add("9987");
found.getUids().add(UUID.randomUUID());
@@ -158,8 +158,7 @@ public class TestDbArray_basic extends BaseTestCase {
@Test
@IgnorePlatform(Platform.HANA)
public void insertNulls() {
void insertNulls() {
EArrayBean bean = new EArrayBean();
bean.setName("some nulls");
bean.setPhoneNumbers(null);
@@ -171,8 +170,7 @@ public class TestDbArray_basic extends BaseTestCase {
@Test
@IgnorePlatform(Platform.HANA)
public void insertAll_when_hasNulls() {
void insertAll_when_hasNulls() {
EArrayBean bean = new EArrayBean();
bean.setName("some nulls");
bean.setPhoneNumbers(null);
@@ -189,16 +187,16 @@ public class TestDbArray_basic extends BaseTestCase {
/**
* Platforms without Array support use JSON which by default isn't including null values.
*/
@ForPlatform({Platform.H2, Platform.POSTGRES})
@ForPlatform({Platform.H2, Platform.POSTGRES, Platform.YUGABYTE})
@Test
public void nullItems() {
void nullItems() {
EArrayBean bean = new EArrayBean();
bean.setName("null items");
List<Double> doubles = new ArrayList<>();
doubles.add(1.3);
List<BigDecimal> doubles = new ArrayList<>();
doubles.add(BigDecimal.valueOf(1.3));
doubles.add(null);
doubles.add(2.4);
doubles.add(BigDecimal.valueOf(2.4));
bean.getPhoneNumbers().add("111222333");
bean.getPhoneNumbers().add(null);
@@ -213,7 +211,7 @@ public class TestDbArray_basic extends BaseTestCase {
bean.getUids().add(null);
bean.getUids().add(UUID.randomUUID());
bean.setDoubs(doubles);
bean.setDecimals(doubles);
bean.setStatuses(new ArrayList<>());
bean.getStatuses().add(EArrayBean.Status.ONE);
@@ -235,7 +233,7 @@ public class TestDbArray_basic extends BaseTestCase {
assertThat(found.getPhoneNumbers()).containsExactly("111222333", null, "333222111");
assertThat(found.getOtherIds()).containsExactly(15L, null, 30L, null);
assertNull(found.getUids().get(1));
assertThat(found.getDoubs()).containsExactly(1.3, null, 2.4);
assertThat(found.getDecimals()).contains(new BigDecimal("1.3"), null, new BigDecimal("2.4"));
assertThat(found.getStatuses()).containsExactly(EArrayBean.Status.ONE, null, EArrayBean.Status.THREE);
assertThat(found.getVcEnums()).containsExactly(VarcharEnum.ONE, null, VarcharEnum.TWO);
assertThat(found.getIntEnums()).containsExactly(null, IntEnum.ZERO, null, IntEnum.TWO);
@@ -244,8 +242,7 @@ public class TestDbArray_basic extends BaseTestCase {
@Test
@IgnorePlatform(Platform.HANA)
public void hitCache() {
void hitCache() {
List<UUID> uids = new ArrayList<>();
uids.add(UUID.randomUUID());
uids.add(UUID.randomUUID());
@@ -271,17 +268,17 @@ public class TestDbArray_basic extends BaseTestCase {
}
@Test
@ForPlatform(Platform.POSTGRES)
public void asDto_withArray() {
@ForPlatform({Platform.POSTGRES, Platform.YUGABYTE})
void asDto_withArray() {
DB.find(EArrayBean.class).delete();
bean.setName("array in dto test");
List<String> phNumbers = bean.getPhoneNumbers();
phNumbers.add("4321");
phNumbers.add("9823");
List<Double> doubs = bean.getDoubs();
doubs.add(1.23);
doubs.add(4.56);
List<BigDecimal> doubs = bean.getDecimals();
doubs.add(BigDecimal.valueOf(1.23));
doubs.add(BigDecimal.valueOf(4.56));
DB.save(bean);
// Data is saved correctly
@@ -290,7 +287,7 @@ public class TestDbArray_basic extends BaseTestCase {
// Interestingly writing `select("id,name,phone_numbers,doubs")`
// generates `select t0.id, t0.name, t0.id, t0.doubs`
// surprisingly changing unknown property to id
.select("id,name,phoneNumbers,doubs")
.select("id,name,phoneNumbers,decimals")
.asDto(EArrayBeanDto.class)
// Shouldn't be necessary
// But without it I see error
@@ -300,7 +297,7 @@ public class TestDbArray_basic extends BaseTestCase {
List<EArrayBeanDto> dtos = query.findList();
List<String> sql = LoggedSql.stop();
assertSql(sql.get(0)).contains("select t0.id, t0.name, t0.phone_numbers, t0.doubs");
assertSql(sql.get(0)).contains("select t0.id, t0.name, t0.phone_numbers, t0.decimals");
for (EArrayBeanDto dto : dtos) {
assertThat(dto.id).isNotNull();
@@ -308,13 +305,13 @@ public class TestDbArray_basic extends BaseTestCase {
// Failure: null
assertThat(dto.phoneNumbers).isNotNull();
// Failure: null
assertThat(dto.doubs).isNotNull();
assertThat(dto.decimals).isNotNull();
}
}
@Test
@ForPlatform(Platform.POSTGRES)
public void sqlUpdate_withArray() {
@ForPlatform({Platform.POSTGRES, Platform.YUGABYTE})
void sqlUpdate_withArray() {
DB.find(EArrayBean.class).delete();
bean.setName("array in sql update test");
DB.save(bean);
@@ -329,11 +326,7 @@ public class TestDbArray_basic extends BaseTestCase {
SqlUpdate update1 = DB.sqlUpdate("UPDATE earray_bean SET phone_numbers = ?")
.setParameter(1, phNumbers);
update1.execute();
System.out.println("done");
// Named param fails with
// javax.persistence.PersistenceException:
// ERROR: syntax error at or near "$2"
SqlUpdate update2 = DB.sqlUpdate("UPDATE earray_bean SET phone_numbers = :pns")
.setArrayParameter("pns", phNumbers);
update2.execute();
@@ -341,19 +334,19 @@ public class TestDbArray_basic extends BaseTestCase {
found = DB.find(EArrayBean.class, bean.getId());
System.out.println(found);
assertEquals("array in sql update test", found.getName());
assertThat(found.getPhoneNumbers()).containsExactly("4321", "9823");
assertThat(found.getPhoneNumbers()).containsExactlyInAnyOrder("4321", "9823");
}
public static class EArrayBeanDto {
Integer id;
List<String> phoneNumbers;
List<Double> doubs;
List<BigDecimal> decimals;
String name;
@Override
public String toString() {
return "id:" + id + " name:" + name + " phoneNumbers:" + phoneNumbers + " doubs:" + doubs;
return "id:" + id + " name:" + name + " phoneNumbers:" + phoneNumbers + " doubs:" + decimals;
}
public Integer getId() {
@@ -380,12 +373,12 @@ public class TestDbArray_basic extends BaseTestCase {
this.phoneNumbers = phoneNumbers;
}
public List<Double> getDoubs() {
return doubs;
public List<BigDecimal> getDecimals() {
return decimals;
}
public void setDoubs(List<Double> doubs) {
this.doubs = doubs;
public void setDecimals(List<BigDecimal> decimals) {
this.decimals = decimals;
}
}
}
@@ -369,7 +369,7 @@ public class TestCacheViaComplexNaturalKey3 extends BaseTestCase {
if (isH2()) {
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() || isOracle() || isDb2() || isYugabyte()) {
} else if (isPostgresCompatible() || isOracle() || isDb2()) {
assertSql(sql.get(0)).contains("from o_cached_natkey3 t0 where t0.store = ? and (t0.sku||'-'||t0.code)");
} else if (isHana()) {
assertSql(sql.get(0)).contains("from o_cached_natkey3 t0 where t0.store = ? and concat(t0.sku, '-'||t0.code)");
@@ -412,7 +412,7 @@ public class TestCacheViaComplexNaturalKey3 extends BaseTestCase {
if (isH2()) {
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() || isOracle() || isDb2() || isYugabyte()){
} else if (isPostgresCompatible() || isOracle() || isDb2()){
assertSql(sql.get(0)).contains("from o_cached_natkey3 t0 where t0.store = ? and (t0.sku||':'||t0.code||'-foo')");
} else if (isHana()){
assertSql(sql.get(0)).contains("from o_cached_natkey3 t0 where t0.store = ? and concat(t0.sku, ':'||t0.code||'-foo')");
@@ -30,7 +30,7 @@ public class TestMTOInheritNoDiscriminator extends BaseTestCase {
final List<String> sql = LoggedSql.stop();
assertThat(sql).hasSize(1);
if (isH2() || isPostgres()) {
if (isH2() || isPostgresCompatible()) {
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");
}
}
@@ -51,7 +51,7 @@ public class TestHistoryEmbeddedId extends BaseTestCase {
assertThat(sql.get(0)).contains("from hembi_bean_with_history t0 where t0.part=? and t0.brand=?");
if (isH2()) {
assertThat(sql.get(0)).contains("order by t0.sys_period_start desc");
} else if (isPostgres()) {
} else if (isPostgresCompatible()) {
assertThat(sql.get(0)).contains("order by lower(t0.sys_period) desc");
}
}
@@ -23,7 +23,7 @@ public class TestImplicitJoinOnParentRelationship extends BaseTestCase {
query.findList();
if (isPostgres()) {
if (platformDistinctOn()) {
String expectedSql = "select distinct on (t0.id) t0.id, t0.name from o_customer t0 join o_order u1 on u1.kcustomer_id = t0.id and u1.order_date is not null join o_order_detail u2 on u2.order_id = u1.id and u2.id > 0 join o_product u3 on u3.id = u2.product_id where u3.name = ?";
assertThat(sqlOf(query, 1)).contains(expectedSql);
@@ -54,7 +54,7 @@ public class TestImplicitJoinOnParentRelationship extends BaseTestCase {
query.findList();
if (isPostgres()) {
if (platformDistinctOn()) {
String expectedSql = "select distinct on (t0.id) t0.id, t0.name from o_customer t0 left join o_order u1 on u1.kcustomer_id = t0.id and u1.order_date is not null left join o_order_detail u2 on u2.order_id = u1.id and u2.id > 0 left join o_product u3 on u3.id = u2.product_id where (u3.name = ? or t0.id = ?)";
assertThat(sqlOf(query, 1)).contains(expectedSql);
} else {
@@ -75,7 +75,7 @@ public class TestImplicitJoinOnParentRelationship extends BaseTestCase {
query.findList();
if (isPostgres()) {
if (platformDistinctOn()) {
String expectedSql = "select distinct on (t0.id) t0.id, t0.name from o_customer t0 left join o_order u1 on u1.kcustomer_id = t0.id and u1.order_date is not null left join o_order_detail u2 on u2.order_id = u1.id and u2.id > 0 left join o_product u3 on u3.id = u2.product_id where (u3.name = ? or t0.id = ?)";
assertThat(sqlOf(query, 1)).contains(expectedSql);
@@ -34,7 +34,7 @@ public class TestManyWhereJoin extends BaseTestCase {
// join o_order u1 on u1.kcustomer_id = t0.id
// where u1.status = ? ; --bind(NEW)
if (isPostgres()) {
if (isPostgresCompatible()) {
assertThat(sql).contains("select distinct on (t0.id) t0.id, ");
} else {
assertThat(sql).contains("select distinct t0.id");
@@ -70,7 +70,7 @@ public class TestManyWhereJoin extends BaseTestCase {
// where t1.order_date is not null and u1.status = ?
// order by t0.id; --bind(NEW)
if (isPostgres()) {
if (platformDistinctOn()) {
assertThat(sql).contains("select distinct on (t0.id, t1.id) t0.id, t0.status,");
} else {
assertThat(sql).contains("select distinct t0.id, t0.status, t1.id, t1.status,");
@@ -101,7 +101,7 @@ public class TestManyWhereJoin extends BaseTestCase {
// where u1.product_id = ?
// order by t0.cretime; --bind(1)
if (isPostgres()) {
if (platformDistinctOn()) {
assertThat(sql).contains("select distinct on (t0.cretime, t0.id) t0.id, t0.status,");
} else {
assertThat(sql).contains("select distinct t0.id, t0.status,");
@@ -135,7 +135,7 @@ public class TestManyWhereJoin extends BaseTestCase {
// where u1.product_id = ?
// order by t0.cretime
if (isPostgres()) {
if (platformDistinctOn()) {
assertThat(sql).contains("select distinct on (t0.cretime, t0.id) t0.id, t0.status,");
} else {
assertThat(sql).contains("select distinct t0.id, t0.status,");
@@ -171,7 +171,7 @@ public class TestManyWhereJoin extends BaseTestCase {
// where t1.id > 0 and u1.product_id = ?
// order by t0.cretime, t0.id, t1.id asc, t1.order_qty asc, t1.cretime desc; --bind(1)
if (isPostgres()) {
if (platformDistinctOn()) {
assertThat(sql).contains("select distinct on (t0.cretime, t0.id, t1.id, t1.order_qty, t1.cretime) t0.id, t0.status,");
} else {
assertThat(sql).contains("select distinct t0.id, t0.status,");
@@ -29,7 +29,7 @@ public class TestQueryExists extends BaseTestCase {
String sql = LoggedSql.stop().get(0);
assertThat(check).isTrue();
if (isH2() || isPostgres()) {
if (isH2() || isPostgresCompatible()) {
assertThat(sql).contains("select t0.id from o_order t0 where t0.id > ? limit 1");
}
@@ -65,7 +65,7 @@ public class TestQueryFilterMany extends BaseTestCase {
assertThat(sqlList.get(0)).contains("lower(t0.name) = ?");
assertThat(sqlList.get(1)).contains("status = ?");
if (isH2() || isPostgres()) {
if (isH2() || isPostgresCompatible()) {
assertThat(sqlList.get(0)).doesNotContain("offset");
assertThat(sqlList.get(0)).contains(" limit 5");
assertThat(sqlList.get(1)).contains(" offset 3");
@@ -97,7 +97,7 @@ public class TestQueryFilterMany extends BaseTestCase {
assertThat(sqlList.get(0)).contains("lower(t0.name) = ?");
assertThat(sqlList.get(1)).contains("status = ?");
if (isH2() || isPostgres()) {
if (isH2() || isPostgresCompatible()) {
assertThat(sqlList.get(0)).doesNotContain("offset");
assertThat(sqlList.get(0)).contains(" limit 5");
assertThat(sqlList.get(1)).contains(" offset 3");
@@ -126,7 +126,7 @@ public class TestQueryFilterMany extends BaseTestCase {
assertThat(sqlList.get(0)).contains("lower(t0.name) = ?");
assertThat(sqlList.get(1)).contains("status = ?");
if (isH2() || isPostgres()) {
if (isH2() || isPostgresCompatible()) {
assertThat(sqlList.get(0)).doesNotContain("offset");
assertThat(sqlList.get(0)).contains(" limit 5");
assertThat(sqlList.get(1)).contains(" order by t0.order_date desc, t0.id limit 100 offset 3");
@@ -220,7 +220,7 @@ public class TestQueryFilterMany extends BaseTestCase {
List<String> sqlList = LoggedSql.stop();
assertEquals(1, sqlList.size());
assertThat(sqlList.get(0)).contains("from o_customer t0 left join o_order t1 on t1.kcustomer_id = t0.id and t1.order_date is not null left join o_customer t2 on t2.id = t1.kcustomer_id where t1.status ");
if (isPostgres()) {
if (isPostgresCompatible()) {
assertThat(sqlList.get(0)).contains("where t1.status = any(?) order by t0.id");
} else {
assertThat(sqlList.get(0)).contains("where t1.status in (?) order by t0.id");
@@ -243,7 +243,7 @@ public class TestQueryFilterMany extends BaseTestCase {
List<String> sqlList = LoggedSql.stop();
assertEquals(2, sqlList.size());
assertThat(sqlList.get(0)).contains("from o_customer t0");
if (isPostgres()) {
if (isPostgresCompatible()) {
assertThat(sqlList.get(1)).contains("from o_order t0 join o_customer t1 on t1.id = t0.kcustomer_id where t0.order_date is not null and (t0.kcustomer_id) = any(?)");
assertThat(sqlList.get(1)).contains(" and t0.status = any(?)");
} else {
@@ -69,7 +69,7 @@ public class TestSubQuery extends BaseTestCase {
// execute the subQuery as copy (generatedSQL must be part of original query)
Query<OrderDetail> debugSq = sq.copy();
debugSq.findSingleAttribute();
if (isPostgres()) {
if (isPostgresCompatible()) {
assertThat(debugSq.getGeneratedSql()).isEqualTo("select t1.id from o_order_detail t0 join o_order t1 on t1.id = t0.order_id where t0.product_id = any(?)");
} else {
assertSql(debugSq.getGeneratedSql()).isEqualTo("select t1.id from o_order_detail t0 join o_order t1 on t1.id = t0.order_id where t0.product_id in (?)");
@@ -78,7 +78,7 @@ public class TestSubQuery extends BaseTestCase {
Query<Order> query = DB.find(Order.class).select("shipDate").where().isIn("id", sq).query();
query.findSingleAttribute();
if (isPostgres()) {
if (isPostgresCompatible()) {
assertThat(query.getGeneratedSql()).isEqualTo("select t0.ship_date from o_order t0 where (t0.id) in (" + debugSq.getGeneratedSql() + ")");
} else {
assertSql(query.getGeneratedSql()).isEqualTo("select t0.ship_date from o_order t0 where (t0.id) in (" + trimSql(debugSq.getGeneratedSql()) + ")");
@@ -149,7 +149,7 @@ public class TestAggregationCount extends BaseTestCase {
String sql = sqlOf(query, 5);
if (isH2()) {
assertThat(sql).contains("select distinct t0.id, t0.name, count(u1.id), sum(u1.my_units), sum(u1.my_units * u1.amount), sum(u1.my_units), t0.name from tevent_one t0 ");
} else if (isPostgres()) {
} else if (isPostgresCompatible()) {
assertThat(sql).contains("t0.name, count(u1.id), sum(u1.my_units), sum(u1.my_units * u1.amount), sum(u1.my_units), t0.name from tevent_one t0 ");
}
assertThat(sql).contains("from tevent_one t0 join tevent_many u1 on u1.event_id = t0.id ");
@@ -237,7 +237,7 @@ public class TestCustomerFinder extends BaseTestCase {
assertThat(metricsJson).contains("\"name\":\"txn.main\"");
assertThat(metricsJson).contains("\"name\":\"orm.Customer.findList\"");
assertThat(metricsJson).contains("\"loc\":\"org.tests.model.basic.finder.CustomerFinder.byNameStatus\"");
if (isH2() || isPostgres()) {
if (isH2() || isPostgresCompatible()) {
assertThat(metricsJson).contains("\"hash\":\"de3affa5b4bff07e19c1c012590dcde6\"");
assertThat(metricsJson).contains("\"sql\":\"select t0.id, t0.status,");
}
@@ -56,7 +56,7 @@ public class TestDisjunctWhereOuterOnMany extends BaseTestCase {
assertEquals(2, list.size());
assertEquals(2, rowCount);
if (isPostgres()) {
if (platformDistinctOn()) {
String expectedSql = "select distinct on (t0.id) t0.id, t0.name, t0.description, t0.version from uuone t0 left join uutwo u1 on u1.master_id = t0.id where (t0.name = ? or u1.name = ?)";
assertSql(query).contains(expectedSql);
@@ -115,7 +115,7 @@ public class TestQueryJoinOnFormula extends BaseTestCase {
.where().isNotNull("order.shipments.order.totalAmount").query();
shipQuery.findList();
if (isPostgres()) {
if (platformDistinctOn()) {
assertThat(shipQuery.getGeneratedSql()).contains("select distinct on (t0.id) t0.id from or_order_ship t0");
} else {
assertSql(shipQuery.getGeneratedSql()).contains("select distinct t0.id from or_order_ship t0 ");
@@ -49,7 +49,7 @@ public class TestOrderByWithDistinct extends BaseTestCase {
query.findList();
String sql = sqlOf(query);
if (isPostgres()) {
if (platformDistinctOn()) {
assertThat(sql).contains("select distinct on (t0.user_name, t0.userid) t0.userid,");
} else if (isH2()) {
assertThat(sql).contains("select distinct t0.userid, t0.user_name, t0.user_type_id from muser t0");
@@ -133,7 +133,7 @@ public class TestOrderByWithDistinct extends BaseTestCase {
assertEquals(1, list.size());
assertEquals(user1, list.get(0));
String generatedSql = query.getGeneratedSql();
if (isPostgres()) {
if (platformDistinctOn()) {
assertThat(generatedSql).contains("select distinct on (t1.name, t0.user_name, t0.userid) t0.userid"); // using distinct
} else {
@@ -168,7 +168,7 @@ public class TestOrderByWithDistinct extends BaseTestCase {
// order by t1.name; --bind(A)
generatedSql = query.getGeneratedSql();
if (isPostgres()) {
if (platformDistinctOn()) {
assertThat(generatedSql).contains("select distinct on (t1.name, t0.userid) t0.userid"); // using distinct
} else {
assertThat(generatedSql).contains("select distinct t0.userid"); // using distinct
@@ -36,7 +36,7 @@ public class TestOrderByWithDistinctTake2 extends BaseTestCase {
// where lower(u1.first_name) like ?
// order by t0.name; --bind(r%)
if (isPostgres()) {
if (platformDistinctOn()) {
assertThat(generatedSql).contains("select distinct on (t0.name, t0.id) t0.id, t0.name");
} else {
@@ -59,7 +59,7 @@ public class TestOrderByWithDistinctTake2 extends BaseTestCase {
String generatedSql = sqlOf(query);
if (isPostgres()) {
if (platformDistinctOn()) {
assertThat(generatedSql).contains("select distinct on (t0.name, t0.id) t0.id, t0.name, t0.id");
} else {
assertThat(generatedSql).contains("select distinct t0.id, t0.name, t0.id");
@@ -42,7 +42,7 @@ public class TestQueryConversationRowCount extends BaseTestCase {
// where t0.group_id = ? and ((t0.open = ? and u1.user_id = ? ) or t0.open = ? )
// order by t0.when_created desc;
if (isPostgres()) {
if (platformDistinctOn()) {
assertThat(generatedSql).contains("select distinct on (t0.when_created, t0.id) t0.id, t0.title, t0.isopen");
} else {
@@ -94,7 +94,7 @@ public class TestQueryDistinct extends BaseTestCase {
query.findList();
if (isH2() || isPostgres()) {
if (isH2() || isPostgresCompatible()) {
String generatedSql = sqlOf(query);
assertThat(generatedSql).contains("select distinct t0.name from o_customer t0 limit 10");
}
@@ -41,7 +41,7 @@ public class TestQueryRowCountWithMany extends BaseTestCase {
// order by t0.cretime, t0.id, t1.id asc, t1.order_qty asc, t1.cretime desc; --bind(1)
String generatedSql = sqlOf(query, 1);
if (isPostgres()) {
if (platformDistinctOn()) {
assertThat(generatedSql).contains("select distinct on (t0.cretime, t0.id, t1.id, t1.order_qty, t1.cretime) t0.id, t0.status,"); // need the distinct
} else {
@@ -313,8 +313,7 @@ public class SqlQueryTests extends BaseTestCase {
@Test
public void firstRow() {
if (isPostgres()) {
if (isPostgresCompatible()) {
ResetBasicData.reset();
@@ -25,7 +25,7 @@ public class TestQuotedIdentifierQuery extends BaseTestCase {
.raw("t0.`CODE` = ?", "bar")
.findList();
} else if (isH2() || isPostgres()) {
} else if (isH2() || isPostgresCompatible()) {
DB.find(BWithQIdent.class)
.where()
@@ -94,7 +94,7 @@ public class TestNativeSqlBasic extends BaseTestCase {
query.findList();
if (isH2() || isPostgres()) {
if (isH2() || isPostgresCompatible()) {
assertThat(sqlOf(query)).contains(" limit 10");
}
}
@@ -113,7 +113,7 @@ public class TestNativeSqlBasic extends BaseTestCase {
query.findList();
if (isH2() || isPostgres()) {
if (isH2() || isPostgresCompatible()) {
assertThat(sqlOf(query)).contains(" limit 10 offset 20");
}
}
@@ -158,8 +158,8 @@ datasource.oracle.url=jdbc:oracle:thin:@localhost:1521:XE
#ebean.postgres.timestamp=timestamp
datasource.pg.username=unit
datasource.pg.password=unit
datasource.pg.url=jdbc:postgresql://127.0.0.1:5432/unit
datasource.pg.password=test
datasource.pg.url=jdbc:postgresql://127.0.0.1:6432/unit
#datasource.pg.capturestacktrace=true
datasource.pg.maxStackTraceSize=50
@@ -1,6 +1,6 @@
ebean.test.platform=sqlserver
ebean.test.dbName=test_ebean
ebean.test.sqlserver.version=2017-latest
ebean.test.sqlserver.version=2017-CU28-ubuntu-16.04
ebean.test.sqlserver.containerName=local_sqlserver2017
ebean.test.sqlserver.collation=LATIN1_GENERAL_100_CS_AS_SC
ebean.test.sqlserver.port=9435