Skip to content

Commit 6ffec9e

Browse files
authored
Merge pull request quarkusio#53569 from FroMage/panache-next-sort
Panache next sort
2 parents 2c2f619 + 225ff7e commit 6ffec9e

22 files changed

Lines changed: 630 additions & 195 deletions

File tree

extensions/panache/hibernate-orm-panache/deployment/src/test/java/io/quarkus/hibernate/orm/panache/deployment/test/JpaOperationsSortTest.java

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,64 @@ public void testSortByDisabledEscaping() {
7575
Sort sort1 = Sort.by("foo.`bar`").disableEscaping();
7676
assertEquals(" ORDER BY foo.`bar`", PanacheJpaUtil.toOrderBy(sort1));
7777
}
78+
79+
@Test
80+
public void testCaseInsensitiveSorting() {
81+
Sort sort = Sort.ascendingIgnoreCase("name");
82+
assertEquals(" ORDER BY LOWER(`name`)", PanacheJpaUtil.toOrderBy(sort));
83+
}
84+
85+
@Test
86+
public void testCaseInsensitiveSortingDescending() {
87+
Sort sort = Sort.descendingIgnoreCase("name");
88+
assertEquals(" ORDER BY LOWER(`name`) DESC", PanacheJpaUtil.toOrderBy(sort));
89+
}
90+
91+
@Test
92+
public void testCaseInsensitiveSortingWithNullPrecedence() {
93+
Sort sort = Sort.ascendingIgnoreCase("name").nullsFirst();
94+
assertEquals(" ORDER BY LOWER(`name`) NULLS FIRST", PanacheJpaUtil.toOrderBy(sort));
95+
}
96+
97+
@Test
98+
public void testMixedCaseSensitiveAndInsensitive() {
99+
Sort sort = Sort.by("category").andIgnoreCase("name", Sort.Direction.Descending);
100+
assertEquals(" ORDER BY `category` , LOWER(`name`) DESC", PanacheJpaUtil.toOrderBy(sort));
101+
}
102+
103+
@Test
104+
public void testCaseInsensitiveEmbeddedColumn() {
105+
Sort sort = Sort.ascendingIgnoreCase("author.name");
106+
assertEquals(" ORDER BY LOWER(`author`.`name`)", PanacheJpaUtil.toOrderBy(sort));
107+
}
108+
109+
@Test
110+
public void testCaseInsensitiveDisabledEscaping() {
111+
Sort sort = Sort.ascendingIgnoreCase("name").disableEscaping();
112+
assertEquals(" ORDER BY LOWER(name)", PanacheJpaUtil.toOrderBy(sort));
113+
}
114+
115+
@Test
116+
public void testIgnoreCaseFluentAPI() {
117+
Sort sort = Sort.by("name", "author").ignoreCase();
118+
assertEquals(" ORDER BY LOWER(`name`) , LOWER(`author`)", PanacheJpaUtil.toOrderBy(sort));
119+
}
120+
121+
@Test
122+
public void testCaseInsensitiveMultipleColumns() {
123+
Sort sort = Sort.ascendingIgnoreCase("name", "author");
124+
assertEquals(" ORDER BY LOWER(`name`) , LOWER(`author`)", PanacheJpaUtil.toOrderBy(sort));
125+
}
126+
127+
@Test
128+
public void testNullsFirstConvenience() {
129+
Sort sort = Sort.by("foo").nullsFirst();
130+
assertEquals(" ORDER BY `foo` NULLS FIRST", PanacheJpaUtil.toOrderBy(sort));
131+
}
132+
133+
@Test
134+
public void testNullsLastConvenience() {
135+
Sort sort = Sort.by("foo").nullsLast();
136+
assertEquals(" ORDER BY `foo` NULLS LAST", PanacheJpaUtil.toOrderBy(sort));
137+
}
78138
}

extensions/panache/hibernate-panache-next/runtime/pom.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,10 @@
3333
<groupId>io.quarkus</groupId>
3434
<artifactId>quarkus-panache-common</artifactId>
3535
</dependency>
36-
<!-- For the metamodel generation -->
36+
<!-- For the metamodel generation and now also for public API (Order/Sort) -->
3737
<dependency>
3838
<groupId>jakarta.data</groupId>
3939
<artifactId>jakarta.data-api</artifactId>
40-
<optional>true</optional>
4140
</dependency>
4241
<dependency>
4342
<groupId>jakarta.json.bind</groupId>

extensions/panache/hibernate-panache-next/runtime/src/main/java/io/quarkus/hibernate/panache/PanacheRepositoryQueries.java

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22

33
import java.util.Map;
44

5+
import jakarta.data.Order;
56
import jakarta.persistence.LockModeType;
67

7-
import io.quarkus.panache.common.Sort;
8-
98
public interface PanacheRepositoryQueries<EntityResult, EntityList, Query extends PanacheQuery<?, ?, ?, ?>, Count, Confirmation, Id> {
109

1110
// Queries
@@ -44,15 +43,15 @@ public interface PanacheRepositoryQueries<EntityResult, EntityList, Query extend
4443
* Find entities using a query and the given sort options, with optional indexed parameters.
4544
*
4645
* @param query a {@link io.quarkus.hibernate.panache query string}
47-
* @param sort the sort strategy to use
46+
* @param order the sort strategy to use
4847
* @param params optional sequence of indexed parameters
4948
* @return a new {@link PanacheQuery} instance for the given query
5049
* @see #find(String, Object...)
51-
* @see #find(String, Sort, Map)
52-
* @see #list(String, Sort, Object...)
53-
* @see #stream(String, Sort, Object...)
50+
* @see #find(String, Order, Map)
51+
* @see #list(String, Order, Object...)
52+
* @see #stream(String, Order, Object...)
5453
*/
55-
Query find(String query, Sort sort, Object... params);
54+
Query find(String query, Order<?> order, Object... params);
5655

5756
/**
5857
* Find entities using a query, with named parameters.
@@ -71,15 +70,15 @@ public interface PanacheRepositoryQueries<EntityResult, EntityList, Query extend
7170
* Find entities using a query and the given sort options, with named parameters.
7271
*
7372
* @param query a {@link io.quarkus.hibernate.panache query string}
74-
* @param sort the sort strategy to use
73+
* @param order the sort strategy to use
7574
* @param params {@link Map} of indexed parameters
7675
* @return a new {@link PanacheQuery} instance for the given query
7776
* @see #find(String, Map)
78-
* @see #find(String, Sort, Object...)
79-
* @see #list(String, Sort, Map)
80-
* @see #stream(String, Sort, Map)
77+
* @see #find(String, Order, Object...)
78+
* @see #list(String, Order, Map)
79+
* @see #stream(String, Order, Map)
8180
*/
82-
Query find(String query, Sort sort, Map<String, Object> params);
81+
Query find(String query, Order<?> order, Map<String, Object> params);
8382

8483
/**
8584
* Find all entities of this type.
@@ -94,13 +93,13 @@ public interface PanacheRepositoryQueries<EntityResult, EntityList, Query extend
9493
/**
9594
* Find all entities of this type, in the given order.
9695
*
97-
* @param sort the sort order to use
96+
* @param order the sort order to use
9897
* @return a new {@link PanacheQuery} instance to find all entities of this type.
9998
* @see #findAll()
100-
* @see #listAll(Sort)
101-
* @see #streamAll(Sort)
99+
* @see #listAll(Order)
100+
* @see #streamAll(Order)
102101
*/
103-
Query findAll(Sort sort);
102+
Query findAll(Order<?> order);
104103

105104
/**
106105
* Find entities matching a query, with optional indexed parameters.
@@ -118,18 +117,18 @@ public interface PanacheRepositoryQueries<EntityResult, EntityList, Query extend
118117

119118
/**
120119
* Find entities matching a query and the given sort options, with optional indexed parameters.
121-
* This method is a shortcut for <code>find(query, sort, params).list()</code>.
120+
* This method is a shortcut for <code>find(query, order, params).list()</code>.
122121
*
123122
* @param query a {@link io.quarkus.hibernate.panache query string}
124-
* @param sort the sort strategy to use
123+
* @param order the sort strategy to use
125124
* @param params optional sequence of indexed parameters
126125
* @return a {@link List} containing all results, without paging
127126
* @see #list(String, Object...)
128-
* @see #list(String, Sort, Map)
129-
* @see #find(String, Sort, Object...)
130-
* @see #stream(String, Sort, Object...)
127+
* @see #list(String, Order, Map)
128+
* @see #find(String, Order, Object...)
129+
* @see #stream(String, Order, Object...)
131130
*/
132-
EntityList list(String query, Sort sort, Object... params);
131+
EntityList list(String query, Order<?> order, Object... params);
133132

134133
/**
135134
* Find entities matching a query, with named parameters.
@@ -147,18 +146,18 @@ public interface PanacheRepositoryQueries<EntityResult, EntityList, Query extend
147146

148147
/**
149148
* Find entities matching a query and the given sort options, with named parameters.
150-
* This method is a shortcut for <code>find(query, sort, params).list()</code>.
149+
* This method is a shortcut for <code>find(query, order, params).list()</code>.
151150
*
152151
* @param query a {@link io.quarkus.hibernate.panache query string}
153-
* @param sort the sort strategy to use
152+
* @param order the sort strategy to use
154153
* @param params {@link Map} of indexed parameters
155154
* @return a {@link List} containing all results, without paging
156155
* @see #list(String, Map)
157-
* @see #list(String, Sort, Object...)
158-
* @see #find(String, Sort, Map)
159-
* @see #stream(String, Sort, Map)
156+
* @see #list(String, Order, Object...)
157+
* @see #find(String, Order, Map)
158+
* @see #stream(String, Order, Map)
160159
*/
161-
EntityList list(String query, Sort sort, Map<String, Object> params);
160+
EntityList list(String query, Order<?> order, Map<String, Object> params);
162161

163162
/**
164163
* Find all entities of this type.
@@ -173,15 +172,15 @@ public interface PanacheRepositoryQueries<EntityResult, EntityList, Query extend
173172

174173
/**
175174
* Find all entities of this type, in the given order.
176-
* This method is a shortcut for <code>findAll(sort).list()</code>.
175+
* This method is a shortcut for <code>findAll(order).list()</code>.
177176
*
178-
* @param sort the sort order to use
177+
* @param order the sort order to use
179178
* @return a {@link List} containing all results, without paging
180179
* @see #listAll()
181-
* @see #findAll(Sort)
182-
* @see #streamAll(Sort)
180+
* @see #findAll(Order)
181+
* @see #streamAll(Order)
183182
*/
184-
EntityList listAll(Sort sort);
183+
EntityList listAll(Order<?> order);
185184

186185
/**
187186
* Counts the number of this type of entity in the database.

extensions/panache/hibernate-panache-next/runtime/src/main/java/io/quarkus/hibernate/panache/blocking/PanacheRepositoryBlockingQueries.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
import java.util.Optional;
66
import java.util.stream.Stream;
77

8+
import jakarta.data.Order;
89
import jakarta.persistence.LockModeType;
910

1011
import io.quarkus.hibernate.panache.PanacheRepositoryQueries;
11-
import io.quarkus.panache.common.Sort;
1212

1313
public interface PanacheRepositoryBlockingQueries<Entity, Id>
1414
extends PanacheRepositoryQueries<Entity, List<Entity>, PanacheBlockingQuery<Entity>, Long, Boolean, Id> {
@@ -49,20 +49,20 @@ public interface PanacheRepositoryBlockingQueries<Entity, Id>
4949

5050
/**
5151
* Find entities matching a query and the given sort options, with optional indexed parameters.
52-
* This method is a shortcut for <code>find(query, sort, params).stream()</code>.
52+
* This method is a shortcut for <code>find(query, order, params).stream()</code>.
5353
* It requires a transaction to work.
5454
* Without a transaction, the underlying cursor can be closed before the end of the stream.
5555
*
5656
* @param query a {@link io.quarkus.hibernate.panache query string}
57-
* @param sort the sort strategy to use
57+
* @param order the sort strategy to use
5858
* @param params optional sequence of indexed parameters
5959
* @return a {@link Stream} containing all results, without paging
6060
* @see #stream(String, Object...)
61-
* @see #stream(String, Sort, Map)
62-
* @see #find(String, Sort, Object...)
63-
* @see #list(String, Sort, Object...)
61+
* @see #stream(String, Order, Map)
62+
* @see #find(String, Order, Object...)
63+
* @see #list(String, Order, Object...)
6464
*/
65-
Stream<Entity> stream(String query, Sort sort, Object... params);
65+
Stream<Entity> stream(String query, Order<?> order, Object... params);
6666

6767
/**
6868
* Find entities matching a query, with named parameters.
@@ -82,20 +82,20 @@ public interface PanacheRepositoryBlockingQueries<Entity, Id>
8282

8383
/**
8484
* Find entities matching a query and the given sort options, with named parameters.
85-
* This method is a shortcut for <code>find(query, sort, params).stream()</code>.
85+
* This method is a shortcut for <code>find(query, order, params).stream()</code>.
8686
* It requires a transaction to work.
8787
* Without a transaction, the underlying cursor can be closed before the end of the stream.
8888
*
8989
* @param query a {@link io.quarkus.hibernate.panache query string}
90-
* @param sort the sort strategy to use
90+
* @param order the sort strategy to use
9191
* @param params {@link Map} of indexed parameters
9292
* @return a {@link Stream} containing all results, without paging
9393
* @see #stream(String, Map)
94-
* @see #stream(String, Sort, Object...)
95-
* @see #find(String, Sort, Map)
96-
* @see #list(String, Sort, Map)
94+
* @see #stream(String, Order, Object...)
95+
* @see #find(String, Order, Map)
96+
* @see #list(String, Order, Map)
9797
*/
98-
Stream<Entity> stream(String query, Sort sort, Map<String, Object> params);
98+
Stream<Entity> stream(String query, Order<?> order, Map<String, Object> params);
9999

100100
/**
101101
* Find all entities of this type.
@@ -104,11 +104,11 @@ public interface PanacheRepositoryBlockingQueries<Entity, Id>
104104
* Without a transaction, the underlying cursor can be closed before the end of the stream.
105105
*
106106
* @return a {@link Stream} containing all results, without paging
107-
* @see #streamAll(Sort)
107+
* @see #streamAll(Order)
108108
* @see #findAll()
109109
* @see #listAll()
110110
*/
111-
Stream<Entity> streamAll(Sort sort);
111+
Stream<Entity> streamAll(Order<?> order);
112112

113113
/**
114114
* Find all entities of this type, in the given order.
@@ -118,8 +118,8 @@ public interface PanacheRepositoryBlockingQueries<Entity, Id>
118118
*
119119
* @return a {@link Stream} containing all results, without paging
120120
* @see #streamAll()
121-
* @see #findAll(Sort)
122-
* @see #listAll(Sort)
121+
* @see #findAll(Order)
122+
* @see #listAll(Order)
123123
*/
124124
Stream<Entity> streamAll();
125125
}

0 commit comments

Comments
 (0)