mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-10-26 08:06:09 +01:00
Bugfix orderby for an IdQueryField(ID)
Squash commits of branch bugfix/orderby-id: - Bugfix orderby for an IdQueryField(ID) - Add changelog for the bugfix ordering by ID field - Add second unit test to order by name and id
This commit is contained in:
2
gradle/changelog/bugfix_order_by_id.yaml
Normal file
2
gradle/changelog/bugfix_order_by_id.yaml
Normal file
@@ -0,0 +1,2 @@
|
||||
- type: fixed
|
||||
description: Ensure query results are ordered by the ID field
|
||||
@@ -451,7 +451,12 @@ class SQLiteQueryableStore<T> implements QueryableStore<T>, QueryableMaintenance
|
||||
Iterator<OrderBy<T>> it = orderBy.iterator();
|
||||
while (it.hasNext()) {
|
||||
OrderBy<T> order = it.next();
|
||||
orderByBuilder.append("json_extract(payload, '$.").append(order.field.getName()).append("') ").append(order.order.name());
|
||||
if (order.field instanceof IdQueryField) {
|
||||
orderByBuilder.append("ID ");
|
||||
} else {
|
||||
orderByBuilder.append("json_extract(payload, '$.").append(order.field.getName()).append("') ");
|
||||
}
|
||||
orderByBuilder.append(order.order.name());
|
||||
if (it.hasNext()) {
|
||||
orderByBuilder.append(", ");
|
||||
}
|
||||
|
||||
@@ -457,6 +457,39 @@ class SQLiteQueryableStoreTest {
|
||||
.containsExactly("Tricia");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldQueryForIdAndOrderByDESC() {
|
||||
SQLiteQueryableMutableStore<User> store = new StoreTestBuilder(connectionString).withIds();
|
||||
store.put("1", new User("trish", "Tricia", "tricia@hog.org"));
|
||||
store.put("2", new User("trillian", "Trillian McMillan", "mcmillan@gmail.com"));
|
||||
store.put("3", new User("arthur", "Arthur Dent", "arthur@hog.org"));
|
||||
|
||||
List<User> all = store.query().orderBy(ID, QueryableStore.Order.DESC)
|
||||
.findAll();
|
||||
|
||||
assertThat(all)
|
||||
.extracting("name")
|
||||
.containsExactly("arthur","trillian","trish");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldOrderIdsAndPayload() {
|
||||
SQLiteQueryableMutableStore<User> store = new StoreTestBuilder(connectionString).withIds();
|
||||
store.put("1", new User("trish", "Tricia", "tricia@hog.org"));
|
||||
store.put("2", new User("trillian", "Trillian McMillan", "mcmillan@gmail.com"));
|
||||
store.put("3", new User("trillian", "Arthur Dent", "arthur@hog.org"));
|
||||
|
||||
List<User> all = store.query()
|
||||
.orderBy(USER_NAME, QueryableStore.Order.DESC)
|
||||
.orderBy(ID, QueryableStore.Order.ASC)
|
||||
.findAll();
|
||||
|
||||
System.out.println(all);
|
||||
assertThat(all)
|
||||
.extracting("displayName")
|
||||
.containsExactly("Tricia","Trillian McMillan","Arthur Dent");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldQueryForParents() {
|
||||
new StoreTestBuilder(connectionString, Group.class.getName())
|
||||
|
||||
Reference in New Issue
Block a user