#727 - ENH: Add endOr(), endAnd(), endNot() ... to ExpressionList as synonym for endJunction()

This commit is contained in:
Robin Bygrave
2016-06-01 16:03:30 +12:00
parent 74d7652044
commit 71f70c01ae
4 changed files with 90 additions and 24 deletions
@@ -1,13 +1,11 @@
package com.avaje.tests.query;
import org.junit.Assert;
import org.junit.Test;
import com.avaje.ebean.BaseTestCase;
import com.avaje.ebean.Ebean;
import com.avaje.ebean.Query;
import com.avaje.tests.model.basic.Customer;
import com.avaje.tests.model.basic.ResetBasicData;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
@@ -20,16 +18,17 @@ public class TestExprNestedDisjunction extends BaseTestCase {
java.sql.Date onAfter = java.sql.Date.valueOf("2009-08-31");
Query<Customer> q = Ebean.find(Customer.class).where().disjunction()
.conjunction().startsWith("name", "r").eq("anniversary", onAfter).endJunction()
.conjunction().eq("status", Customer.Status.ACTIVE).gt("id", 0).endJunction().orderBy()
.asc("name");
Query<Customer> q = Ebean.find(Customer.class).where()
.disjunction()
.conjunction().startsWith("name", "r").eq("anniversary", onAfter).endJunction()
.conjunction().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 > ? )"));
assertThat(s).contains("(t0.name like ? ");
assertThat(s).contains(" and t0.anniversary = ? ) or (t0.status = ? and t0.id > ? )");
}
@@ -44,16 +43,16 @@ public class TestExprNestedDisjunction extends BaseTestCase {
.where()
.or()
.and()
.startsWith("name", "r").eq("anniversary", onAfter).endJunction()
.startsWith("name", "r").eq("anniversary", onAfter).endAnd()
.and()
.eq("status", Customer.Status.ACTIVE).gt("id", 0).endJunction()
.eq("status", Customer.Status.ACTIVE).gt("id", 0).endAnd()
.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 > ? )"));
assertThat(s).contains("(t0.name like ? ");
assertThat(s).contains(" and t0.anniversary = ? ) or (t0.status = ? and t0.id > ? )");
}
@Test
@@ -68,7 +67,7 @@ public class TestExprNestedDisjunction extends BaseTestCase {
.not()
.gt("id", 1)
.eq("anniversary", onAfter)
.endJunction()
.endNot()
.orderBy().asc("name");
q.findList();
@@ -91,7 +90,30 @@ public class TestExprNestedDisjunction extends BaseTestCase {
.not()
.gt("id", 1)
.eq("anniversary", onAfter)
//.endNot()
.orderBy().asc("name");
q.findList();
String s = q.getGeneratedSql();
assertThat(s).contains("where (t0.status = ? or not (t0.id > ? and t0.anniversary = ? ) )");
}
@Test
public void test_not_nested_with_endNot() {
ResetBasicData.reset();
java.sql.Date onAfter = java.sql.Date.valueOf("2009-08-31");
Query<Customer> q = Ebean.find(Customer.class)
.where()
.or()
.eq("status", Customer.Status.ACTIVE)
.not()
.gt("id", 1)
.eq("anniversary", onAfter)
.endNot()
.endOr()
.orderBy().asc("name");
q.findList();