Skip to content

Instantly share code, notes, and snippets.

@mgezkaya
Created February 18, 2019 11:59
Show Gist options
  • Save mgezkaya/f90e19e8e86e35cabcf22bd97325cf3a to your computer and use it in GitHub Desktop.
Save mgezkaya/f90e19e8e86e35cabcf22bd97325cf3a to your computer and use it in GitHub Desktop.
Cassandra Forward Paging With Spring 2.x
public PagedData findUsersByActivationStatusWithPaging(UserActivationStatus activationStatus, String pagingState) {
logger.info("Finding users by activation status {}...", activationStatus);
Select select = QueryBuilder
.select()
.from("user");
select.where(eq("activationStatus", activationStatus.name()));
select.setFetchSize(pagingFetchSize);
if (pagingState != null) {
select.setPagingState(PagingState.fromString(pagingState));
}
Slice<User> users = cassandraTemplate.slice(select, User.class);
logger.info("Found {} users with/by activation status {}", users.getContent().size(), activationStatus);
if(users.hasNext()) {
CassandraPageRequest next = (CassandraPageRequest) users.nextPageable();
return new PagedData(next.getPagingState().toString(), users.hasNext(), users.getContent());
}else{
return new PagedData(null,false,users.getContent());
}
}
@ramazanapa20
Copy link

thank u so much you saved my life

@bnsk
Copy link

bnsk commented Oct 3, 2019

I want to wait infinitely for new inserts into the table and as soon as the result set equals the batch size, I want to consume it. Can you please let me know how to implement this scenario?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment