@@ -267,8 +267,9 @@ public int getFetchSize() {
267267 * This will cause the next execution of this statement to fetch results from a given
268268 * page, rather than restarting from the beginning.
269269 * <p>
270- * You get the paging state from a previous execution of the statement. This is typically
271- * used to iterate in a "stateless" manner (e.g. across HTTP requests):
270+ * You get the paging state from a previous execution of the statement (see
271+ * {@link ExecutionInfo#getPagingState()}.
272+ * This is typically used to iterate in a "stateless" manner (e.g. across HTTP requests):
272273 * <pre>
273274 * {@code
274275 * Statement st = new SimpleStatement("your query");
@@ -296,9 +297,17 @@ public int getFetchSize() {
296297 * }
297298 * </pre>
298299 * <p>
299- * Note that the paging state can only be reused between perfectly identical statements
300+ * The paging state can only be reused between perfectly identical statements
300301 * (same query string, same bound parameters). Altering the contents of the paging state
301302 * or trying to set it on a different statement will cause this method to fail.
303+ * <p>
304+ * Note that, due to internal implementation details, the paging state is not portable
305+ * across native protocol versions (see the
306+ * <a href="http://datastax.github.io/java-driver/features/native_protocol">online documentation</a>
307+ * for more explanations about the native protocol).
308+ * This means that {@code PagingState} instances generated with an old version won't work
309+ * with a higher version. If that is a problem for you, consider using the "unsafe" API (see
310+ * {@link #setPagingStateUnsafe(byte[])}).
302311 *
303312 * @param pagingState the paging state to set, or {@code null} to remove any state that was
304313 * previously set on this statement.
@@ -323,6 +332,30 @@ public Statement setPagingState(PagingState pagingState) {
323332 return this ;
324333 }
325334
335+ /**
336+ * Sets the paging state.
337+ * <p>
338+ * Contrary to {@link #setPagingState(PagingState)}, this method takes the "raw" form of the
339+ * paging state (previously extracted with {@link ExecutionInfo#getPagingStateUnsafe()}.
340+ * It won't validate that this statement matches the one that the paging state was extracted from.
341+ * If the paging state was altered in any way, you will get unpredictable behavior from
342+ * Cassandra (ranging from wrong results to a query failure). If you decide to use this variant,
343+ * it is strongly recommended to add your own validation (for example, signing the raw state with
344+ * a private key).
345+ *
346+ * @param pagingState the paging state to set, or {@code null} to remove any state that was
347+ * previously set on this statement.
348+ * @return this {@code Statement} object.
349+ */
350+ public Statement setPagingStateUnsafe (byte [] pagingState ) {
351+ if (pagingState == null ) {
352+ this .pagingState = null ;
353+ } else {
354+ this .pagingState = ByteBuffer .wrap (pagingState );
355+ }
356+ return this ;
357+ }
358+
326359 ByteBuffer getPagingState () {
327360 return pagingState ;
328361 }
0 commit comments