Skip to content

Commit

Permalink
Fix number of parameters in string based @query queries.
Browse files Browse the repository at this point in the history
Closed #1977.
  • Loading branch information
mikereiche committed Oct 10, 2024
1 parent 395c7aa commit 24164f3
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -711,8 +711,11 @@ private static Object[] getParameters(ParameterAccessor accessor) {
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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
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;

Expand Down Expand Up @@ -154,6 +155,11 @@ Long countFancyExpression(@Param("projectIds") List<String> projectIds, @Param("
@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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,31 @@ void sortedRepository() {
}
}

@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();
Expand Down

0 comments on commit 24164f3

Please sign in to comment.