diff --git a/extensions/panache/panache-common/runtime/src/main/java/io/quarkus/panache/common/Sort.java b/extensions/panache/panache-common/runtime/src/main/java/io/quarkus/panache/common/Sort.java index a503da211661c..0db5221d5f3e3 100644 --- a/extensions/panache/panache-common/runtime/src/main/java/io/quarkus/panache/common/Sort.java +++ b/extensions/panache/panache-common/runtime/src/main/java/io/quarkus/panache/common/Sort.java @@ -294,6 +294,17 @@ public Sort and(String name, Direction direction, NullPrecedence nullPrecedence) return this; } + /** + * Add a sort column + * + * @param column the column to sort on with his properties + * @return this instance, modified. + */ + public Sort and(Column column) { + columns.add(column); + return this; + } + /** * Disables escaping of column names with a backticks during HQL Order By clause generation * diff --git a/integration-tests/hibernate-orm-panache/src/main/java/io/quarkus/it/panache/defaultpu/TestEndpoint.java b/integration-tests/hibernate-orm-panache/src/main/java/io/quarkus/it/panache/defaultpu/TestEndpoint.java index 440aa962ac3f0..5f5a835f864e3 100644 --- a/integration-tests/hibernate-orm-panache/src/main/java/io/quarkus/it/panache/defaultpu/TestEndpoint.java +++ b/integration-tests/hibernate-orm-panache/src/main/java/io/quarkus/it/panache/defaultpu/TestEndpoint.java @@ -518,10 +518,17 @@ private void testSorting() { Sort sort1 = Sort.by("name", "status"); List order1 = Arrays.asList(person3, person2, person1); + List columns = Arrays.asList( + new Sort.column("name", Sort.Direction.Descending), + new Sort.column("status", Sort.Direction.Ascending) + ); List list = Person.findAll(sort1).list(); Assertions.assertEquals(order1, list); + list = Person.findAll(Sort.and(column)).list(); + Assertions.assertEquals(order1, list); + list = Person.listAll(sort1); Assertions.assertEquals(order1, list); @@ -534,6 +541,13 @@ private void testSorting() { list = Person.find("name", sort2, "stef").list(); Assertions.assertEquals(order2, list); + columns = Arrays.asList( + new Sort.column("name", Sort.Direction.Descending), + new Sort.column("status", Sort.Direction.Ascending) + ); + list = Person.find("name", Sort.and(column), "stef").list(); + Assertions.assertEquals(order2, list); + list = Person.list("name", sort2, "stef"); Assertions.assertEquals(order2, list);