Java 8 has reached end of support
and will be
deprecated
on January 31, 2026. After deprecation, you won't be able to deploy Java 8
applications, even if your organization previously used an organization policy to
re-enable deployments of legacy runtimes. Your existing Java
8 applications will continue to run and receive traffic after their
deprecation date. We recommend that
you
migrate to the latest supported version of Java.
Cursor (Google App Engine API for Java)
Stay organized with collections
Save and categorize content based on your preferences.
- java.lang.Object
-
- com.google.appengine.api.datastore.Cursor
-
- All Implemented Interfaces:
- java.io.Serializable
public final class Cursor
extends java.lang.Object
implements java.io.Serializable
A cursor that represents a position in a query.
To resume a Query
at the position defined by a Cursor
, the Cursor
must
be present in the FetchOptions
passed to a PreparedQuery
identical to the one it
was created from.
Cursors can be retrieved from PreparedQuery.asQueryResult*
functions. A typical use
case would be:
Cursor originalCursor = preparedQuery.asQueryResultList(withLimit(20)).getCursor();
String encodedCursor = original.toWebSafeString();
The encoded cursor can then be passed safely in a get or post arg of a web request and on another
request the next batch of results can be retrieved with:
Cursor decodedCursor = Cursor.fromWebSafeString(encodedCursor);
List<Entity> nextBatch = preparedQuery.asQueryResultList(withLimit(20).cursor(decoded));
- See Also:
- Serialized Form
-
-
Method Summary
-
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
-
-
Method Detail
-
reverse
@Deprecated
public Cursor reverse()
Deprecated.
- Returns:
- a cursor identical to
this
-
toWebSafeString
public java.lang.String toWebSafeString()
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in class java.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in class java.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in class java.lang.Object
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-06-16 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-06-16 UTC."],[[["\u003cp\u003eThe \u003ccode\u003eCursor\u003c/code\u003e class represents a position within a query, enabling the resumption of a \u003ccode\u003eQuery\u003c/code\u003e at that specific point.\u003c/p\u003e\n"],["\u003cp\u003eCursors are obtained from \u003ccode\u003ePreparedQuery.asQueryResult*\u003c/code\u003e functions and are used within \u003ccode\u003eFetchOptions\u003c/code\u003e to continue a query.\u003c/p\u003e\n"],["\u003cp\u003eA \u003ccode\u003eCursor\u003c/code\u003e can be encoded into a web-safe string using \u003ccode\u003etoWebSafeString()\u003c/code\u003e and later decoded using \u003ccode\u003efromWebSafeString(String)\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003ereverse()\u003c/code\u003e method is deprecated; cursors from a query can now be directly used in the reversed \u003ccode\u003eQuery\u003c/code\u003e.\u003c/p\u003e\n"]]],[],null,["# Cursor (Google App Engine API for Java)\n\ncom.google.appengine.api.datastore\n\nClass Cursor\n------------\n\n- java.lang.Object\n-\n - com.google.appengine.api.datastore.Cursor\n\n-\n\n All Implemented Interfaces:\n : java.io.Serializable\n\n *** ** * ** ***\n\n \u003cbr /\u003e\n\n ```\n public final class Cursor\n extends java.lang.Object\n implements java.io.Serializable\n ``` \n A cursor that represents a position in a query.\n\n To resume a [`Query`](../../../../../com/google/appengine/api/datastore/Query.html \"class in com.google.appengine.api.datastore\") at the position defined by a [`Cursor`](../../../../../com/google/appengine/api/datastore/Cursor.html \"class in com.google.appengine.api.datastore\"), the [`Cursor`](../../../../../com/google/appengine/api/datastore/Cursor.html \"class in com.google.appengine.api.datastore\") must\n be present in the [`FetchOptions`](../../../../../com/google/appengine/api/datastore/FetchOptions.html \"class in com.google.appengine.api.datastore\") passed to a [`PreparedQuery`](../../../../../com/google/appengine/api/datastore/PreparedQuery.html \"interface in com.google.appengine.api.datastore\") identical to the one it\n was created from.\n\n Cursors can be retrieved from `PreparedQuery.asQueryResult*` functions. A typical use\n case would be:\n\n \u003e ```\n \u003e Cursor originalCursor = preparedQuery.asQueryResultList(withLimit(20)).getCursor();\n \u003e String encodedCursor = original.toWebSafeString();\n \u003e \n \u003e ```\n The encoded cursor can then be passed safely in a get or post arg of a web request and on another request the next batch of results can be retrieved with:\n \u003e\n \u003e\n \u003e Cursor decodedCursor = Cursor.fromWebSafeString(encodedCursor);\n \u003e List\u003cEntity\u003e nextBatch = preparedQuery.asQueryResultList(withLimit(20).cursor(decoded));\n \u003e \n \u003cbr /\u003e\n\n \u003cbr /\u003e\n\n See Also:\n: [Serialized Form](../../../../../serialized-form.html#com.google.appengine.api.datastore.Cursor) \n-\n -\n\n ### Method Summary\n\n -\n\n ### Methods inherited from class java.lang.Object\n\n`getClass, notify, notifyAll, wait, wait, wait` \n-\n -\n\n ### Method Detail\n\n\n -\n\n #### reverse\n\n ```\n @Deprecated\n public Cursor reverse()\n ``` \n Deprecated. It is no longer necessary to call [`reverse()`](../../../../../com/google/appengine/api/datastore/Cursor.html#reverse--) on cursors.\n\n A cursor returned by a query may also be used in the query returned by [`Query.reverse()`](../../../../../com/google/appengine/api/datastore/Query.html#reverse--).\n\n Returns:\n : a cursor identical to `this`\n\n\n -\n\n #### toWebSafeString\n\n ```\n public java.lang.String toWebSafeString()\n ``` \n Encodes the current cursor as a web safe string that can later be decoded by [`fromWebSafeString(String)`](../../../../../com/google/appengine/api/datastore/Cursor.html#fromWebSafeString-java.lang.String-)\n\n\n -\n\n #### fromWebSafeString\n\n ```\n public static Cursor fromWebSafeString(java.lang.String encodedCursor)\n ``` \n Decodes the given encoded cursor\n\n Parameters:\n : `encodedCursor` -\n\n Returns:\n : the decoded cursor\n\n Throws:\n : `java.lang.IllegalArgumentException` - if the provided string is not a valid encoded cursor\n\n\n -\n\n #### equals\n\n ```\n public boolean equals(java.lang.Object obj)\n ```\n\n Overrides:\n : `equals` in class `java.lang.Object`\n\n\n -\n\n #### hashCode\n\n ```\n public int hashCode()\n ```\n\n Overrides:\n : `hashCode` in class `java.lang.Object`\n\n\n -\n\n #### toString\n\n ```\n public java.lang.String toString()\n ```\n\n Overrides:\n : `toString` in class `java.lang.Object`"]]