https://github.com/jusexton/spring-cassandra-pagination-example
Cassandra pagination example with spring boot.
https://github.com/jusexton/spring-cassandra-pagination-example
cassandra example-project java spring-boot
Last synced: about 1 year ago
JSON representation
Cassandra pagination example with spring boot.
- Host: GitHub
- URL: https://github.com/jusexton/spring-cassandra-pagination-example
- Owner: jusexton
- Created: 2019-07-30T03:19:03.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2021-07-29T05:42:53.000Z (almost 5 years ago)
- Last Synced: 2025-04-13T13:08:57.987Z (about 1 year ago)
- Topics: cassandra, example-project, java, spring-boot
- Language: Java
- Homepage:
- Size: 102 KB
- Stars: 11
- Watchers: 1
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Spring Cassandra Pagination Example with Spring Boot
Small CRUD application demonstration how to paginate results using Apache Cassandra with Spring Boot.
## How it Works
Simply put, Cassandra uses paging state to determine where to start reading results from. If no paging state is given,
cassandra will read the result set starting from the beginning.
The main key to this functionality in Spring Boot is creating the CassandraPageRequest.
Note the PageRequest object simply limits the number of results and does not determine where the results will be read from.
```java
private CassandraPageRequest createCassandraPageRequest(final Integer limit, final String pagingState) {
final PageRequest pageRequest = PageRequest.of(0, limit);
final PagingState pageState = pagingState != null ? PagingState.fromString(pagingState) : null;
return CassandraPageRequest.of(pageRequest, pageState);
}
```
Now simply use your CassandraPageRequest like it was any other page request.
```java
public CassandraPage getPageOfUsers(final CassandraPageRequest cassandraPageRequest) {
final Slice userSlice = userRepository.findAll(cassandraPageRequest);
return new CassandraPage<>(userSlice);
}
```
Paging state is acquired from page requests to cassandra. It can be extracted by using the following method.
```java
CassandraPageRequest pageRequest = (CassandraPageRequest) slice.nextPageable();
this.pagingState = Objects.requireNonNull(pageRequest.getPagingState()).toString();
```