Spring Data Slice in Cassandra

113 views Asked by At

Actually i'm using Slice to pagination in queries in Cassandra. My repository is declared like this:

@Repository
public interface MovementsRepository<T> extends CassandraRepository<Movements, MovementsPK> {

    @Query("SELECT movementNumber FROM KEYSPACE.MOVEMENTS)
    Slice<Movements> downOrder(@Param("agency") String agency, @Param("account") String account, @Param("initialDate") LocalDate initialDate, @Param("finalDate") LocalDate finalDate, Pageable pageable);

}

And I do the search in the first page this way:

Slice<Movements> slice = this.movementsRepository.downOrder(agency, account, initialDate, finalDate, CassandraPageRequest.first(1000));

To go for the next pages I can get the property slice.nextPageable() like this:

slice = this.movementsRepository.downOrder(agency, account, initialDate, finalDate, slice.nextPageable());

But I need to paginate every request, so I need to retrive in JSON the pagingState or whetever I can use to set nextPageable when the second, third... request comes to I know the next search is in next pages, it's possible to do this in the way I'm doing or other way? Thanks a lot

1

There are 1 answers

1
Steephen On

Slice can only navigate to the next slice. Also Slice provides details whether there is more data to fetch. So you can run it in a while loop as follows:

while(slice.hasNext()){
 slice = this.movementsRepository.downOrder(agency, account, 
             initialDate, finalDate, slice.nextPageable());
}