mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#410 - Require findPagedList() query to specify an order by clause - throw exception if no order by supplied
This commit is contained in:
@@ -50,6 +50,7 @@ public class TestAddOrderByWithFirstRowsMaxRows extends BaseTestCase {
|
||||
List<String> loggedSql = LoggedSqlCollector.stop();
|
||||
|
||||
assertThat(loggedSql).hasSize(1);
|
||||
assertThat(loggedSql.get(0)).contains("order by t0.id");
|
||||
}
|
||||
|
||||
|
||||
@@ -72,6 +73,25 @@ public class TestAddOrderByWithFirstRowsMaxRows extends BaseTestCase {
|
||||
assertThat(loggedSql.get(0)).contains("order by t0.id");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_maxRows1() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
LoggedSqlCollector.start();
|
||||
|
||||
// maxRows 1 with no first rows means Ebean does not automatically
|
||||
// add the order by id to the query
|
||||
Ebean.find(Order.class)
|
||||
.setMaxRows(1)
|
||||
.findList();
|
||||
|
||||
List<String> loggedSql = LoggedSqlCollector.stop();
|
||||
|
||||
assertThat(loggedSql).hasSize(1);
|
||||
assertThat(loggedSql.get(0)).doesNotContain("order by t0.id");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_pagingOne() {
|
||||
|
||||
@@ -107,4 +127,42 @@ public class TestAddOrderByWithFirstRowsMaxRows extends BaseTestCase {
|
||||
assertThat(loggedSql).hasSize(1);
|
||||
assertThat(loggedSql.get(0)).contains("order by t0.id");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void test_pagingAppendToExistingOrderBy() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
LoggedSqlCollector.start();
|
||||
|
||||
Ebean.find(Order.class)
|
||||
.order().asc("orderDate")
|
||||
.findPagedList(0, 10)
|
||||
.getList();
|
||||
|
||||
List<String> loggedSql = LoggedSqlCollector.stop();
|
||||
|
||||
assertThat(loggedSql).hasSize(1);
|
||||
assertThat(loggedSql.get(0)).contains("order by t0.order_date, t0.id");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_pagingExistingOrderByWithId() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
LoggedSqlCollector.start();
|
||||
|
||||
Ebean.find(Order.class)
|
||||
.order().asc("orderDate")
|
||||
.order().desc("id")
|
||||
.findPagedList(0, 10)
|
||||
.getList();
|
||||
|
||||
List<String> loggedSql = LoggedSqlCollector.stop();
|
||||
|
||||
assertThat(loggedSql).hasSize(1);
|
||||
assertThat(loggedSql.get(0)).contains("order by t0.order_date, t0.id desc");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user