Fix slice support. (#1324)

Fix slice support. Also discontinue use of deprecated class.

Closes #1323.
This commit is contained in:
Michael Reiche
2022-02-08 09:45:20 -08:00
committed by GitHub
parent 1438bf9cf7
commit c88a35c152
5 changed files with 54 additions and 31 deletions

View File

@@ -39,6 +39,7 @@ import org.springframework.data.couchbase.repository.ScanConsistency;
import org.springframework.data.couchbase.repository.Scope;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
@@ -177,6 +178,12 @@ public interface AirportRepository extends CouchbaseRepository<Airport, String>,
@ScanConsistency(query = QueryScanConsistency.REQUEST_PLUS)
Airport findByKey(String id);
@Query("#{#n1ql.selectEntity} WHERE #{#n1ql.filter} AND iata between $1 and $2")
Slice<Airport> fetchSlice(String startIata, String iata, Pageable pageable);
@Query("#{#n1ql.selectEntity} WHERE #{#n1ql.filter} AND iata between $1 and $2")
Page<Airport> fetchPage(String startIata, String iata, Pageable pageable);
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.METHOD, ElementType.TYPE })
// @Meta

View File

@@ -91,6 +91,7 @@ import org.springframework.data.couchbase.util.IgnoreWhen;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.domain.Sort;
import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
import org.springframework.data.repository.core.support.DefaultRepositoryMetadata;
@@ -639,7 +640,7 @@ public class CouchbaseRepositoryQueryIntegrationTests extends ClusterAwareIntegr
}
@Test
void count() {
void countSlicePage() {
airportRepository.withOptions(QueryOptions.queryOptions().scanConsistency(REQUEST_PLUS)).deleteAll();
String[] iatas = { "JFK", "IAD", "SFO", "SJC", "SEA", "LAX", "PHX" };
@@ -677,6 +678,18 @@ public class CouchbaseRepositoryQueryIntegrationTests extends ClusterAwareIntegr
airportCount = airportRepository.countByIataIn("XXX");
assertEquals(0, airportCount);
pageable = PageRequest.of(1, 2, Sort.by("iata"));
Slice<Airport> airportSlice = airportRepository.fetchSlice("AAA", "zzz", pageable);
assertEquals(2, airportSlice.getSize());
assertEquals("LAX", airportSlice.getContent().get(0).getIata());
assertEquals("PHX", airportSlice.getContent().get(1).getIata());
pageable = PageRequest.of(1, 2, Sort.by("iata"));
Page<Airport> airportPage = airportRepository.fetchPage("AAA", "zzz", pageable);
assertEquals(2, airportPage.getSize());
assertEquals("LAX", airportPage.getContent().get(0).getIata());
assertEquals("PHX", airportPage.getContent().get(1).getIata());
} finally {
airportRepository
.deleteAllById(Arrays.stream(iatas).map((iata) -> "airports::" + iata).collect(Collectors.toSet()));
@@ -833,7 +846,8 @@ public class CouchbaseRepositoryQueryIntegrationTests extends ClusterAwareIntegr
}
}
@Test // DATACOUCH-650
@Test
// DATACOUCH-650
void deleteAllById() {
Airport vienna = new Airport("airports::vie", "vie", "LOWW");