Created
February 18, 2019 11:59
-
-
Save mgezkaya/f90e19e8e86e35cabcf22bd97325cf3a to your computer and use it in GitHub Desktop.
Cassandra Forward Paging With Spring 2.x
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?