Skip to content

Commit de1c5db

Browse files
Annotated query paging and sorting (Azure#19527)
* eliminate duplicate class PageableAddress * add support for paging when using @query * add support for sorting when using @query * add support for pageable sort when using @query * preserve backwards compatibility * add reactive support for sorting when using @query * fixed broken test * use nextPageable to get next page * fixed javadoc * fixed checkstyle issues * fixed spotbugs issue
1 parent 1392104 commit de1c5db

22 files changed

+316
-270
lines changed

sdk/cosmos/azure-spring-data-cosmos-test/src/test/java/com/azure/spring/data/cosmos/common/PageTestUtils.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public static void validateLastPage(Page<?> page, int pageSize) {
1818
assertThat(pageable).isInstanceOf(CosmosPageRequest.class);
1919
assertTrue(continuationTokenIsNull((CosmosPageRequest) pageable));
2020
assertThat(pageable.getPageSize()).isEqualTo(pageSize);
21+
assertThat(page.hasNext()).isFalse();
2122
}
2223

2324
public static void validateNonLastPage(Page<?> page, int pageSize) {
@@ -27,6 +28,7 @@ public static void validateNonLastPage(Page<?> page, int pageSize) {
2728
assertThat(((CosmosPageRequest) pageable).getRequestContinuation()).isNotNull();
2829
assertThat(((CosmosPageRequest) pageable).getRequestContinuation()).isNotBlank();
2930
assertThat(pageable.getPageSize()).isEqualTo(pageSize);
31+
assertThat(page.hasNext()).isTrue();
3032
}
3133

3234
private static boolean continuationTokenIsNull(CosmosPageRequest pageRequest) {

sdk/cosmos/azure-spring-data-cosmos-test/src/test/java/com/azure/spring/data/cosmos/core/CosmosTemplateIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ public void testFindAllPageableMultiPages() {
395395
assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNotNull();
396396
assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics().getRequestCharge()).isGreaterThan(0);
397397

398-
final Page<Person> page2 = cosmosTemplate.findAll(page1.getPageable(), Person.class,
398+
final Page<Person> page2 = cosmosTemplate.findAll(page1.nextPageable(), Person.class,
399399
containerName);
400400
assertThat(page2.getContent().size()).isEqualTo(1);
401401
PageTestUtils.validateLastPage(page2, PAGE_SIZE_1);
@@ -520,7 +520,7 @@ public void testFindAllWithTwoPagesAndVerifySortOrder() {
520520
assertThat(firstPageResults.get(1).getFirstName()).isEqualTo(FIRST_NAME);
521521
assertThat(firstPageResults.get(2).getFirstName()).isEqualTo(testPerson5.getFirstName());
522522

523-
final Page<Person> secondPage = cosmosTemplate.findAll(firstPage.getPageable(), Person.class,
523+
final Page<Person> secondPage = cosmosTemplate.findAll(firstPage.nextPageable(), Person.class,
524524
containerName);
525525

526526
assertThat(secondPage.getContent().size()).isEqualTo(2);

sdk/cosmos/azure-spring-data-cosmos-test/src/test/java/com/azure/spring/data/cosmos/core/CosmosTemplatePartitionIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ public void testPartitionedFindAllPageableMultiPages() {
271271
assertThat(page1.getContent().size()).isEqualTo(PAGE_SIZE_1);
272272
PageTestUtils.validateNonLastPage(page1, PAGE_SIZE_1);
273273

274-
final Page<PartitionPerson> page2 = cosmosTemplate.findAll(page1.getPageable(),
274+
final Page<PartitionPerson> page2 = cosmosTemplate.findAll(page1.nextPageable(),
275275
PartitionPerson.class, containerName);
276276
assertThat(page2.getContent().size()).isEqualTo(1);
277277
PageTestUtils.validateLastPage(page2, PAGE_SIZE_1);

sdk/cosmos/azure-spring-data-cosmos-test/src/test/java/com/azure/spring/data/cosmos/domain/Address.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT License.
33
package com.azure.spring.data.cosmos.domain;
44

5+
import com.azure.spring.data.cosmos.common.TestConstants;
56
import com.azure.spring.data.cosmos.core.mapping.Container;
67
import com.azure.spring.data.cosmos.core.mapping.PartitionKey;
78
import org.springframework.data.annotation.Id;
@@ -10,6 +11,16 @@
1011

1112
@Container()
1213
public class Address {
14+
15+
public static final Address TEST_ADDRESS1_PARTITION1 = new Address(
16+
TestConstants.POSTAL_CODE, TestConstants.STREET, TestConstants.CITY);
17+
public static final Address TEST_ADDRESS2_PARTITION1 = new Address(
18+
TestConstants.POSTAL_CODE_0, TestConstants.STREET_0, TestConstants.CITY);
19+
public static final Address TEST_ADDRESS1_PARTITION2 = new Address(
20+
TestConstants.POSTAL_CODE_1, TestConstants.STREET_1, TestConstants.CITY_0);
21+
public static final Address TEST_ADDRESS4_PARTITION3 = new Address(
22+
TestConstants.POSTAL_CODE, TestConstants.STREET_2, TestConstants.CITY_1);
23+
1324
@Id
1425
String postalCode;
1526
String street;

sdk/cosmos/azure-spring-data-cosmos-test/src/test/java/com/azure/spring/data/cosmos/domain/Book.java

Lines changed: 0 additions & 84 deletions
This file was deleted.

sdk/cosmos/azure-spring-data-cosmos-test/src/test/java/com/azure/spring/data/cosmos/domain/PageableAddress.java

Lines changed: 0 additions & 85 deletions
This file was deleted.

sdk/cosmos/azure-spring-data-cosmos-test/src/test/java/com/azure/spring/data/cosmos/repository/integration/AddressRepositoryIT.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,17 @@
2828
import java.util.List;
2929
import java.util.Optional;
3030

31+
import static com.azure.spring.data.cosmos.domain.Address.TEST_ADDRESS1_PARTITION1;
32+
import static com.azure.spring.data.cosmos.domain.Address.TEST_ADDRESS1_PARTITION2;
33+
import static com.azure.spring.data.cosmos.domain.Address.TEST_ADDRESS2_PARTITION1;
34+
import static com.azure.spring.data.cosmos.domain.Address.TEST_ADDRESS4_PARTITION3;
3135
import static org.assertj.core.api.Assertions.assertThat;
3236
import static org.assertj.core.api.Assertions.fail;
3337

3438
@RunWith(SpringJUnit4ClassRunner.class)
3539
@ContextConfiguration(classes = TestRepositoryConfig.class)
3640
public class AddressRepositoryIT {
3741

38-
private static final Address TEST_ADDRESS1_PARTITION1 = new Address(
39-
TestConstants.POSTAL_CODE, TestConstants.STREET, TestConstants.CITY);
40-
private static final Address TEST_ADDRESS2_PARTITION1 = new Address(
41-
TestConstants.POSTAL_CODE_0, TestConstants.STREET_0, TestConstants.CITY);
42-
private static final Address TEST_ADDRESS1_PARTITION2 = new Address(
43-
TestConstants.POSTAL_CODE_1, TestConstants.STREET_1, TestConstants.CITY_0);
44-
private static final Address TEST_ADDRESS4_PARTITION3 = new Address(
45-
TestConstants.POSTAL_CODE, TestConstants.STREET_2, TestConstants.CITY_1);
46-
4742
private static final CosmosEntityInformation<Address, String> entityInformation
4843
= new CosmosEntityInformation<>(Address.class);
4944

0 commit comments

Comments
 (0)