#3379 Followup, Move orderById() to common QueryBuilder interface

Effectively this adds it to QueryBeans (where it was missing)
This commit is contained in:
Rob Bygrave
2024-04-04 22:05:17 +13:00
parent 7469a38bbc
commit 3e65705bf9
4 changed files with 36 additions and 8 deletions
@@ -510,14 +510,6 @@ public interface Query<T> extends CancelableQuery, QueryBuilder<Query<T>, T> {
*/
QueryType getQueryType();
/**
* Controls, if paginated queries should always append an 'order by id' statement at the end to
* guarantee a deterministic sort result. This may affect performance.
* If this is not enabled, and an orderBy is set on the query, it's up to the programmer that
* this query provides a deterministic result.
*/
Query<T> orderById(boolean orderById);
/**
* Set the profile location of this query. This is used to relate query execution metrics
* back to a location like a specific line of code.
@@ -466,6 +466,14 @@ public interface QueryBuilder<SELF, T> extends QueryBuilderProjection<SELF, T> {
*/
SELF setOrderBy(OrderBy<T> orderBy);
/**
* Controls, if paginated queries should always append an 'order by id' statement at the end to
* guarantee a deterministic sort result. This may affect performance.
* If this is not enabled, and an orderBy is set on the query, it's up to the programmer that
* this query provides a deterministic result.
*/
SELF orderById(boolean orderById);
/**
* Execute the query with the given lock type and WAIT.
* <p>
@@ -582,6 +582,12 @@ public abstract class TQRootBean<T, R> implements QueryBean<T, R> {
return root;
}
@Override
public R orderById(boolean orderById) {
query.orderById(orderById);
return root;
}
@Override
@Deprecated(since = "13.19", forRemoval = true)
public final R order(String orderByClause) {
@@ -79,6 +79,28 @@ class QOrderTest {
DB.delete(customer);
}
@Test
void orderById() {
Query<Order> query = new QOrder()
.select(QOrder.Alias.status)
.orderById(true).query();
query.findList();
String sql = query.getGeneratedSql();
assertThat(sql).contains("select /* QOrderTest.orderById:88 */ t0.id, t0.status from o_order t0 order by t0.id");
Query<Order> query2 = new QOrder()
.select(QOrder.Alias.status)
.orderById(true).orderBy().status.asc()
.query();
query2.findList();
String sql2 = query2.getGeneratedSql();
assertThat(sql2).contains("select /* QOrderTest.orderById:98 */ t0.id, t0.status from o_order t0 order by t0.status, t0.id");
}
@Test
void hint() {
LoggedSql.start();