mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-03 16:25:36 +00:00
#410 - Require findPagedList() query to specify an order by clause - throw exception if no order by supplied
This commit is contained in:
1 parent
04fda0a6b4
commit
ec4f655312
4 files changed
+134
-3
No files matched your search
@@ -0,0 +1,110 @@
|
||||
package com.avaje.tests.query;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.PagedList;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
import org.avaje.ebeantest.LoggedSqlCollector;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Ebean adds order by clause if none provided when using both first rows and max rows.
|
||||
*/
|
||||
public class TestAddOrderByWithFirstRowsMaxRows extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test_firstRows() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
LoggedSqlCollector.start();
|
||||
|
||||
Ebean.find(Order.class)
|
||||
.setFirstRow(3)
|
||||
.orderBy().asc("id")
|
||||
.findList();
|
||||
|
||||
List<String> loggedSql = LoggedSqlCollector.stop();
|
||||
|
||||
assertThat(loggedSql).hasSize(1);
|
||||
assertThat(loggedSql.get(0)).contains("order by t0.id");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void test_maxRows() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
LoggedSqlCollector.start();
|
||||
|
||||
Ebean.find(Order.class)
|
||||
.setMaxRows(10)
|
||||
.findList();
|
||||
|
||||
List<String> loggedSql = LoggedSqlCollector.stop();
|
||||
|
||||
assertThat(loggedSql).hasSize(1);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void test_firstRowsMaxRows() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
LoggedSqlCollector.start();
|
||||
|
||||
Ebean.find(Order.class)
|
||||
.setFirstRow(3)
|
||||
.setMaxRows(10)
|
||||
.orderBy().asc("id")
|
||||
.findList();
|
||||
|
||||
List<String> loggedSql = LoggedSqlCollector.stop();
|
||||
|
||||
assertThat(loggedSql).hasSize(1);
|
||||
assertThat(loggedSql.get(0)).contains("order by t0.id");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_pagingOne() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
LoggedSqlCollector.start();
|
||||
|
||||
PagedList<Order> pagedList =
|
||||
Ebean.find(Order.class)
|
||||
.findPagedList(0, 10);
|
||||
|
||||
pagedList.getList();
|
||||
|
||||
List<String> loggedSql = LoggedSqlCollector.stop();
|
||||
|
||||
assertThat(loggedSql).hasSize(1);
|
||||
assertThat(loggedSql.get(0)).contains("order by t0.id");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_pagingTwo() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
LoggedSqlCollector.start();
|
||||
|
||||
Ebean.find(Order.class)
|
||||
.findPagedList(1, 10)
|
||||
.getList();
|
||||
|
||||
List<String> loggedSql = LoggedSqlCollector.stop();
|
||||
|
||||
assertThat(loggedSql).hasSize(1);
|
||||
assertThat(loggedSql.get(0)).contains("order by t0.id");
|
||||
}
|
||||
}
|
||||
@@ -117,6 +117,6 @@ datasource.pg.databaseDriver=org.postgresql.Driver
|
||||
|
||||
datasource.ms.username=test
|
||||
datasource.ms.password=test
|
||||
datasource.ms.databaseUrl=jdbc:sqlserver://192.168.1.68:1433;databaseName=test
|
||||
datasource.ms.databaseUrl=jdbc:sqlserver://192.168.1.69:1433;databaseName=test
|
||||
datasource.ms.databaseDriver=com.microsoft.sqlserver.jdbc.SQLServerDriver
|
||||
|
||||
Reference in new issue
Block a user