Quantcast
Channel: CodeSection,代码区,数据库(综合) - CodeSec
Viewing all articles
Browse latest Browse all 6262

Cassandra Resuming pagination

$
0
0

Cassandra provides the page state information and it can be reused to get next iteration.

Statement stmt = QueryBuilder
.select()
.all()
.from("users")
.where(eq("email", emailUpper));
ResultSet resultSet = getSession().execute(stmt);
PagingState pagingState = resultSet.getExecutionInfo().getPagingState();

Then it can be serialized in below way

String savedStringState = pagingState.toString();
byte[] savedBytesState = pagingState.toBytes();

It can be reconstructed and resume the query as shown following example.

PagingState pagingState = PagingState.fromString(string);
Statement stmt = QueryBuilder
.select()
.all()
.from("users")
.where(eq("email", emailUpper));
PagingState pagingState = resultSet.getExecutionInfo().getPagingState();
// restore state from the saved string
PagingState pagingState = PagingState.fromString(savedStringState);
stmt.setPagingState(pagingState);
ResultSet resultSet = getSession().execute(stmt);

Viewing all articles
Browse latest Browse all 6262

Trending Articles