#605 - Add and() and or() ... as synonyms for conjunction() and disjunction() ... to the "Query Criteria API"

This commit is contained in:
Robin Bygrave
2016-03-18 13:06:10 +13:00
parent 5d889790c2
commit 3ddd7099b5
5 changed files with 70 additions and 9 deletions
@@ -30,4 +30,26 @@ public class TestExprNestedDisjunction extends BaseTestCase {
Assert.assertTrue(s.contains(" and t0.anniversary = ? ) or (t0.status = ? and t0.id > ? )"));
}
@Test
public void test_nested_and() {
ResetBasicData.reset();
java.sql.Date onAfter = java.sql.Date.valueOf("2009-08-31");
Query<Customer> q = Ebean.find(Customer.class)
.where()
.or()
.and()
.startsWith("name", "r").eq("anniversary", onAfter).endJunction()
.and().eq("status", Customer.Status.ACTIVE).gt("id", 0).endJunction().orderBy()
.asc("name");
q.findList();
String s = q.getGeneratedSql();
Assert.assertTrue(s.contains("(t0.name like ? "));
Assert.assertTrue(s.contains(" and t0.anniversary = ? ) or (t0.status = ? and t0.id > ? )"));
}
}
@@ -9,7 +9,7 @@ import com.avaje.ebean.Query;
import com.avaje.tests.model.basic.Customer;
import com.avaje.tests.model.basic.ResetBasicData;
public class TestImplicitJoinOnParentRelatonship extends BaseTestCase {
public class TestImplicitJoinOnParentRelationship extends BaseTestCase {
@Test
public void test() {
@@ -50,14 +50,21 @@ public class TestImplicitJoinOnParentRelatonship extends BaseTestCase {
String expectedSql = "select distinct t0.id c0, t0.name c1 from o_customer t0 left outer join o_order u1 on u1.kcustomer_id = t0.id left outer join o_order_detail u2 on u2.order_id = u1.id left outer join o_product u3 on u3.id = u2.product_id where (u3.name = ? or t0.id = ? ) ";
Assert.assertEquals(expectedSql, query.getGeneratedSql());
// select distinct t0.id c0, t0.name c1
// from o_customer t0 select distinct t0.id c0, t0.name c1 from o_customer t0 join o_order u1 on u1.kcustomer_id = t0.id join o_order_detail u2 on u2.order_id = u1.id join o_product u3 on u3.id = u2.product_id where u3.name = ?
// left outer join o_order u1 on u1.kcustomer_id = t0.id
// left outer join o_order_detail u2 on u2.order_id = u1.id
// left outer join o_product u3 on u3.id = u2.product_id
// where (u3.name = ? or t0.id = ? ) ; --bind(Desk,4)
}
@Test
public void testWithOr() {
ResetBasicData.reset();
Query<Customer> query = Ebean.find(Customer.class)
.select("id, name")
.where().or().eq("orders.details.product.name", "Desk").eq("id", 4).endJunction()
.query();
query.findList();
String expectedSql = "select distinct t0.id c0, t0.name c1 from o_customer t0 left outer join o_order u1 on u1.kcustomer_id = t0.id left outer join o_order_detail u2 on u2.order_id = u1.id left outer join o_product u3 on u3.id = u2.product_id where (u3.name = ? or t0.id = ? ) ";
Assert.assertEquals(expectedSql, query.getGeneratedSql());
}
}