Skip to content

Fix number of parameters in string based @Query queries. #1978

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading