Fix number of parameters in string based @Query queries. (#1978)
Closed #1977.
This commit is contained in:
@@ -711,8 +711,11 @@ public class StringBasedN1qlQueryParser {
|
||||
for (Object o : accessor) {
|
||||
params.add(o);
|
||||
}
|
||||
params.add(accessor.getPageable());
|
||||
params.add(accessor.getSort());
|
||||
if( accessor.getPageable().isPaged()) {
|
||||
params.add(accessor.getPageable());
|
||||
} else if (accessor.getSort().isSorted()) {
|
||||
params.add(accessor.getSort());
|
||||
}
|
||||
return params.toArray();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ 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.domain.Sort;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@@ -154,6 +155,11 @@ public interface AirportRepository extends CouchbaseRepository<Airport, String>,
|
||||
@Query("#{#n1ql.selectEntity} WHERE #{#n1ql.filter} AND iata != $1")
|
||||
Page<Airport> getAllByIataNot(String iata, Pageable pageable);
|
||||
|
||||
@ScanConsistency(query = QueryScanConsistency.REQUEST_PLUS)
|
||||
@Query("#{#n1ql.selectEntity} WHERE #{#n1ql.filter} AND iata != $1")
|
||||
List<Airport> getAllByIataNotSort(String iata, Sort sort);
|
||||
|
||||
|
||||
@ScanConsistency(query = QueryScanConsistency.REQUEST_PLUS)
|
||||
@Query("SELECT iata, \"\" as __id, 0 as __cas from #{#n1ql.bucket} WHERE #{#n1ql.filter} order by meta().id")
|
||||
List<String> getStrings();
|
||||
|
||||
@@ -884,6 +884,31 @@ public class CouchbaseRepositoryQueryIntegrationTests extends ClusterAwareIntegr
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void countSlicePageTest() {
|
||||
airportRepository.withOptions(QueryOptions.queryOptions().scanConsistency(REQUEST_PLUS)).deleteAll();
|
||||
String[] iatas = { "JFK", "IAD", "SFO", "SJC", "SEA", "LAX", "PHX" };
|
||||
|
||||
airportRepository.countOne();
|
||||
try {
|
||||
airportRepository.saveAll(
|
||||
Arrays.stream(iatas).map((iata) -> new Airport("airports::" + iata, iata, iata.toLowerCase(Locale.ROOT)))
|
||||
.collect(Collectors.toSet()));
|
||||
|
||||
Pageable sPageable = PageRequest.of(0, 2).withSort(Sort.by("iata"));
|
||||
Page<Airport> sPage = airportRepository.getAllByIataNot("JFK", sPageable);
|
||||
System.out.println(sPage);
|
||||
|
||||
Sort sort = Sort.by("iata");
|
||||
List<Airport> sList = airportRepository.getAllByIataNotSort("JFK", sort);
|
||||
System.out.println(sList);
|
||||
|
||||
} finally {
|
||||
airportRepository
|
||||
.deleteAllById(Arrays.stream(iatas).map((iata) -> "airports::" + iata).collect(Collectors.toSet()));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void countSlicePage() {
|
||||
airportRepository.withOptions(QueryOptions.queryOptions().scanConsistency(REQUEST_PLUS)).deleteAll();
|
||||
|
||||
Reference in New Issue
Block a user