|
9 | 9 | import java.util.Objects; |
10 | 10 | import java.util.concurrent.CompletionStage; |
11 | 11 |
|
| 12 | +import org.hibernate.query.Order; |
12 | 13 | import org.hibernate.annotations.Filter; |
13 | 14 | import org.hibernate.annotations.FilterDef; |
14 | 15 | import org.hibernate.annotations.ParamDef; |
@@ -163,6 +164,39 @@ public void testMaxResultsWithStage(VertxTestContext context) { |
163 | 164 | ); |
164 | 165 | } |
165 | 166 |
|
| 167 | + @Test |
| 168 | + public void testReactiveKeyedPagination(VertxTestContext context) { |
| 169 | + test( context, openSession() |
| 170 | + .thenCompose( session -> { |
| 171 | + var query = session.createSelectionQuery( |
| 172 | + "from FamousPerson p where p.status = :status order by p.name, p.id", |
| 173 | + FamousPerson.class |
| 174 | + ); |
| 175 | + final var firstPage = first( 2 ).keyedBy( List.of( |
| 176 | + Order.asc( FamousPerson.class, "name" ), |
| 177 | + Order.asc( FamousPerson.class, "id" ) |
| 178 | + ) ); |
| 179 | + return query.setParameter( "status", Status.LIVING ) |
| 180 | + .getReactiveKeyedResultList( firstPage ) |
| 181 | + .thenCompose( firstResults -> { |
| 182 | + assertThat( firstResults.getResultList() ).containsExactly( margaret, rebeccaActress ); |
| 183 | + assertThat( firstResults.getKeyList() ).hasSize( 2 ); |
| 184 | + assertThat( firstResults.isFirstPage() ).isTrue(); |
| 185 | + assertThat( firstResults.isLastPage() ).isFalse(); |
| 186 | + assertThat( firstResults.getPreviousPage() ).isNull(); |
| 187 | + return query.getReactiveKeyedResultList( firstResults.getNextPage() ) |
| 188 | + .thenAccept( secondResults -> { |
| 189 | + assertThat( secondResults.getResultList() ).containsExactly( rebeccaSinger ); |
| 190 | + assertThat( secondResults.getKeyList() ).hasSize( 1 ); |
| 191 | + assertThat( secondResults.isFirstPage() ).isFalse(); |
| 192 | + assertThat( secondResults.isLastPage() ).isTrue(); |
| 193 | + assertThat( secondResults.getPreviousPage() ).isNotNull(); |
| 194 | + } ); |
| 195 | + } ); |
| 196 | + } ) |
| 197 | + ); |
| 198 | + } |
| 199 | + |
166 | 200 | @Test |
167 | 201 | public void testMaxResultsWithStageAndPage(VertxTestContext context) { |
168 | 202 | test( context, enableFilter( openSession(), FamousPerson.IS_ALIVE_FILTER ) |
|
0 commit comments