#1943 - Return ExpressionList<T> from setMaxRows() setFirstRow() to allow fluid style

This is to allow fluid style use of setMaxRows() setFirstRow() with filterMany query
This commit is contained in:
rob bygrave
2020-02-17 17:19:27 +13:00
parent 1dd0f3cbf8
commit e0d322d80a
7 changed files with 79 additions and 21 deletions
@@ -53,7 +53,7 @@ public class TestLimitQuery extends BaseTestCase {
.fetch("details")
.where().gt("details.id", 0)
.setMaxRows(3)
.setFirstRow(0);
.setFirstRow(0).query();
query.findList();
@@ -96,7 +96,7 @@ public class TestLimitQuery extends BaseTestCase {
.setAutoTune(false)
.fetch("details")
.where().gt("details.id", 0)
.setMaxRows(10);
.setMaxRows(10).query();
//.findList();
List<Order> list = query.findList();
@@ -46,6 +46,34 @@ public class TestQueryFilterMany extends BaseTestCase {
}
@Test
public void filterMany_firstMaxRows_fluidStyle() {
ResetBasicData.reset();
LoggedSqlCollector.start();
final Query<Customer> query = DB.find(Customer.class)
.where().ieq("name", "Rob")
// fluid style adding maxRows/firstRow to filterMany
.filterMany("orders").eq("status", Order.Status.NEW).setMaxRows(100).setFirstRow(3)
.order().asc("id").setMaxRows(5);
final List<Customer> customers = query.findList();
assertThat(customers).isNotEmpty();
List<String> sqlList = LoggedSqlCollector.stop();
assertEquals(2, sqlList.size());
assertThat(sqlList.get(0)).contains("lower(t0.name) = ?");
assertThat(sqlList.get(1)).contains("status = ?");
if (isH2() || isPostgres()) {
assertThat(sqlList.get(0)).doesNotContain("offset");
assertThat(sqlList.get(0)).contains(" limit 5");
assertThat(sqlList.get(1)).contains(" offset 3");
assertThat(sqlList.get(1)).contains(" limit 100");
}
}
@Test
public void test_firstMaxRows() {
@@ -57,6 +85,7 @@ public class TestQueryFilterMany extends BaseTestCase {
.where().ieq("name", "Rob")
.order().asc("id").setMaxRows(5);
// non-fluid style adding maxRows/firstRow
final ExpressionList<Customer> filterMany = query.filterMany("orders").eq("status", Order.Status.NEW);
filterMany.setMaxRows(100);
filterMany.setFirstRow(3);
@@ -77,6 +106,34 @@ public class TestQueryFilterMany extends BaseTestCase {
}
}
@Test
public void filterMany_firstMaxRows_expressionFluidStyle() {
ResetBasicData.reset();
LoggedSqlCollector.start();
final Query<Customer> query = DB.find(Customer.class)
.where().ieq("name", "Rob")
// use expression + fluid style adding maxRows/firstRow to filterMany
.filterMany("orders", "status = ?", Order.Status.NEW).setMaxRows(100).setFirstRow(3)
.order().asc("id").setMaxRows(5);
final List<Customer> customers = query.findList();
assertThat(customers).isNotEmpty();
List<String> sqlList = LoggedSqlCollector.stop();
assertEquals(2, sqlList.size());
assertThat(sqlList.get(0)).contains("lower(t0.name) = ?");
assertThat(sqlList.get(1)).contains("status = ?");
if (isH2() || isPostgres()) {
assertThat(sqlList.get(0)).doesNotContain("offset");
assertThat(sqlList.get(0)).contains(" limit 5");
assertThat(sqlList.get(1)).contains(" offset 3");
assertThat(sqlList.get(1)).contains(" limit 100");
}
}
@Test
public void test_with_findOne() {
@@ -196,7 +196,7 @@ public class TestQueryFindIterate extends BaseTestCase {
Query<Customer> query = server.find(Customer.class)
.setAutoTune(false)
.where().gt("id", "JUNK_NOT_A_LONG")
.setMaxRows(2);
.setMaxRows(2).query();
// this throws an exception immediately
query.findEach(bean -> {
@@ -221,7 +221,7 @@ public class TestQueryFindIterate extends BaseTestCase {
Query<Customer> query = server.find(Customer.class)
.setAutoTune(false)
.where().gt("id", 0)
.setMaxRows(2);
.setMaxRows(2).query();
query.findEach(customer -> {
if (customer != null) {