Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions ebean-api/src/main/java/io/ebean/Query.java
Original file line number Diff line number Diff line change
Expand Up @@ -510,14 +510,6 @@ default Query<T> setOrder(OrderBy<T> orderBy) {
*/
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.
Expand Down
8 changes: 8 additions & 0 deletions ebean-api/src/main/java/io/ebean/QueryBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,14 @@ default SELF setUseQueryCache(boolean enabled) {
*/
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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,12 @@ public R setOrderBy(OrderBy<T> orderBy) {
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) {
Expand Down
22 changes: 22 additions & 0 deletions ebean-querybean/src/test/java/org/querytest/QOrderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,28 @@ public static void after() {
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();
Expand Down
Loading