com.google.appengine.api.datastore
Class FetchOptions

java.lang.Object
  extended by com.google.appengine.api.datastore.FetchOptions

public final class FetchOptions
extends java.lang.Object

Describes the limit, offset, and chunk size to be applied when executing a PreparedQuery.

limit is the maximum number of results the query will return.

offset is the number of result to skip before returning any results. Results that are skipped due to offset do not count against limit.

cursor is a previously generated cursor that points to a location in a result set. Queries executed with a cursor start at that location.

prefetchSize is the number of results retrieved on the first call to the datastore.

chunkSize determines the internal chunking strategy of the Iterator returned by PreparedQuery.asIterator(FetchOptions) and the Iterable returned by PreparedQuery.asIterable(FetchOptions).

Note that unlike limit, offset and cursor, prefetchSize and chunkSize have no impact on the result of the PreparedQuery, but rather only the performance of the PreparedQuery.

Notes on usage:
The recommended way to instantiate a FetchOptions object is to statically import FetchOptions.Builder.* and invoke a static creation method followed by an instance mutator (if needed):

 import static com.google.appengine.api.datastore.FetchOptions.Builder.*;

 ...

 // limit 10
 datastoreService.prepare(query).asList(withLimit(10));

 // limit 10, offset 5
 datastoreService.prepare(query).asList(withLimit(10).offset(5));

 


Nested Class Summary
static class FetchOptions.Builder
          Contains static creation methods for FetchOptions.
 
Field Summary
static int DEFAULT_CHUNK_SIZE
          Deprecated. Instead of using DEFAULT_CHUNK_SIZE, do not specify a chunk size.
 
Method Summary
 FetchOptions chunkSize(int chunkSize)
          Sets the chunk size.
 FetchOptions cursor(Cursor cursor)
          Sets the cursor to start the query from.
 java.lang.Integer getChunkSize()
           
 Cursor getCursor()
           
 java.lang.Integer getLimit()
           
 java.lang.Integer getOffset()
           
 java.lang.Integer getPrefetchSize()
           
 FetchOptions limit(int limit)
          Sets the limit.
 FetchOptions offset(int offset)
          Sets the offset.
 FetchOptions prefetchSize(int prefetchSize)
          Sets the number of entities to prefetch.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_CHUNK_SIZE

@Deprecated
public static final int DEFAULT_CHUNK_SIZE
Deprecated. Instead of using DEFAULT_CHUNK_SIZE, do not specify a chunk size.
See Also:
Constant Field Values
Method Detail

limit

public FetchOptions limit(int limit)
Sets the limit. Please read the class javadoc for an explanation of how limit is used.

Parameters:
limit - The limit to set. Must be greater than 0.
Returns:
this (for chaining)

offset

public FetchOptions offset(int offset)
Sets the offset. Please read the class javadoc for an explanation of how offset is used.

Parameters:
offset - The offset to set. Must be 0 or greater.
Returns:
this (for chaining)

chunkSize

public FetchOptions chunkSize(int chunkSize)
Sets the chunk size. Please read the class javadoc for an explanation of how chunk size is used.

Parameters:
chunkSize - The chunk size to set. Must be greater than 0.
Returns:
this (for chaining)

prefetchSize

public FetchOptions prefetchSize(int prefetchSize)
Sets the number of entities to prefetch.

Parameters:
prefetchSize - The prefetch size to set. Must be >= 0.
Returns:
this (for chaining)

cursor

public FetchOptions cursor(Cursor cursor)
Sets the cursor to start the query from.

Parameters:
cursor - the cursor to set
Returns:
this (for chaining)

getLimit

public java.lang.Integer getLimit()
Returns:
The limit, or null if no limit was provided.

getOffset

public java.lang.Integer getOffset()
Returns:
The offset, or null if no offset was provided.

getChunkSize

public java.lang.Integer getChunkSize()
Returns:
The chunk size, or null if no chunk size was provided.

getPrefetchSize

public java.lang.Integer getPrefetchSize()
Returns:
The prefetch size, or null if no prefetch size was provided.

getCursor

public Cursor getCursor()
Returns:
The cursor, or null if no cursor was provided.