-
Notifications
You must be signed in to change notification settings - Fork 311
Closed as not planned
Closed as not planned
Copy link
Labels
for: stackoverflowA question that's better suited to stackoverflow.comA question that's better suited to stackoverflow.comstatus: invalidAn issue that we don't feel is validAn issue that we don't feel is valid
Description
Java: 19
Springboot: 3.0
Dependency:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-cassandra</artifactId>
</dependency>
Repository
PersonRepository extends ReactiveCassandraRepository<Person, Integer> {
Mono<Slice<Person>> findAll(Pageable page);
Mono<Slice<Person>> findAllByType(String type, Pageable page);
}
Service:
public Mono<Slice<Person>> findPaginatedPerson(int limit, int offset) {
int page = offset / limit;
//only working with page = 0
Pageable pageRequest = CassandraPageRequest.of(page,limit);
Mono<Slice<Person>> persons = personRepository.findAll(pageRequest);
//working for first page only
//Mono<Slice<Person>> persons = personRepository.findAll(CassandraPageRequest.first(1));
return persons;
}
Controller:
@GetMapping("/persons")
public List<Person> findPaginated(@RequestParam int limit, @RequestParam int offset) {
Mono<Slice<Person>> personPage = personService.findPaginatedPerson(limit, offset);
return personPage.block().getContent();
}
I tried below changes
public List<Person> findFoo(int limit, int offset) {
int page = offset / limit;
int currpage = 0, size = 2;
Pageable pageRequest = CassandraPageRequest.of(size, limit);
Slice< Person > persons = personRepository.findAllByAssetType(pageRequest);
while(persons.hasNext() && currpage < page) {
persons = personRepository.findAllByAssetType(persons.nextPageable());
currpage++;
}
return persons.getContent();
}
and created an workaround which is super inefficient
public List<Person> findPaginatedPerson(int limit, int offset) {
int page =0;
int noOfrecords = offset * limit;
Pageable pageRequest = CassandraPageRequest.of(page, noOfrecords);
Mono<Slice<Person>> persons = personRepository.findAll(pageRequest);
return persons.block().getContent().stream().skip(noOfrecords-limit).collect(Collectors.toList());
}
would like to know, the best way to implement it .
From this PR #128
allow slice queries using reactive repositories. it seems it is possible, there is definitely I am missing something.
Metadata
Metadata
Assignees
Labels
for: stackoverflowA question that's better suited to stackoverflow.comA question that's better suited to stackoverflow.comstatus: invalidAn issue that we don't feel is validAn issue that we don't feel is valid