Class SimpleQueryImpl<T>

java.lang.Object
com.googlecode.objectify.impl.SimpleQueryImpl<T>
All Implemented Interfaces:
QueryExecute<T>, QueryResultIterable<T>, SimpleQuery<T>, Iterable<T>
Direct Known Subclasses:
QueryImpl

public abstract class SimpleQueryImpl<T> extends Object implements SimpleQuery<T>
Base for command classes that include methods for defining a query (filter, order, limit, etc). Does not include the methods for executing a query.
Author:
Jeff Schnitzer invalid input: '<'[email protected]>
  • Field Details

    • loader

      protected final com.googlecode.objectify.impl.LoaderImpl loader
  • Method Details

    • filterKey

      public QueryImpl<T> filterKey(String condition, Object value)
      Description copied from interface: SimpleQuery

      Create a filter on the key of an entity. Examples:

      • filterKey(">=", key) (standard inequalities)
      • filterKey("=", key) (wouldn't you rather do a load-by-key?)
      • filterKey("", key) (if no operator, = is assumed)
      • filterKey("!=", key)
      • filterKey("in", keyList) (wouldn't you rather do a batch load-by-key?)

      The key parameter can be anything key-ish; a Keyinvalid input: '<'?>, a native datastore key, a Ref, a pojo entity, etc.

      See the Google documentation for indexes for an explanation of what you can and cannot filter for.

      All command objects are immutable; this method returns a new object instead of modifying the current command object.

      Specified by:
      filterKey in interface SimpleQuery<T>
      Returns:
      a new immutable query object that applies the filter
    • filterKey

      public QueryImpl<T> filterKey(Object value)
      Description copied from interface: SimpleQuery
      An alias for filterKey("=", value)

      All command objects are immutable; this method returns a new object instead of modifying the current command object.

      Specified by:
      filterKey in interface SimpleQuery<T>
      Returns:
      a new immutable query object that applies the filter
    • orderKey

      public QueryImpl<T> orderKey(boolean descending)
      Description copied from interface: SimpleQuery
      Orders results by the key.
      Specified by:
      orderKey in interface SimpleQuery<T>
      Parameters:
      descending - if true, specifies a descending (aka reverse) sort

      All command objects are immutable; this method returns a new object instead of modifying the current command object.

      Returns:
      a new immutable query object that applies the sort order
    • ancestor

      public QueryImpl<T> ancestor(Object keyOrEntity)
      Description copied from interface: SimpleQuery
      Restricts result set only to objects which have the given ancestor somewhere in the chain. Doesn't need to be the immediate parent. The specified ancestor itself will be included in the result set (if it exists).

      All command objects are immutable; this method returns a new object instead of modifying the current command object.

      Specified by:
      ancestor in interface SimpleQuery<T>
      Parameters:
      keyOrEntity - can be a Key, a Key, or an Objectify entity object.
      Returns:
      a new immutable query object that applies the ancestor filter
    • limit

      public QueryImpl<T> limit(int value)
      Description copied from interface: SimpleQuery
      Limit the fetched result set to a certain number of values.

      All command objects are immutable; this method returns a new object instead of modifying the current command object.

      Specified by:
      limit in interface SimpleQuery<T>
      Parameters:
      value - must be >= 0. A value of 0 indicates no limit.
      Returns:
      a new immutable query object that applies the limit
    • offset

      public QueryImpl<T> offset(int value)
      Description copied from interface: SimpleQuery
      Starts the query results at a particular zero-based offset. This can be extraordinarily expensive because each skipped entity is billed as a "minor datastore operation". If you can, you probably want to use cursors instead.

      All command objects are immutable; this method returns a new object instead of modifying the current command object.

      Specified by:
      offset in interface SimpleQuery<T>
      Parameters:
      value - must be >= 0
      Returns:
      a new immutable query object that applies the offset
    • startAt

      public QueryImpl<T> startAt(com.google.cloud.datastore.Cursor value)
      Description copied from interface: SimpleQuery
      Starts query results at the specified Cursor. You can obtain a Cursor from a QueryResultIterator by calling the getCursor() method.

      All command objects are immutable; this method returns a new object instead of modifying the current command object.

      Note that limit() and offset() are NOT encoded within a cursor; they operate on the results of the query after a cursor is established.
      Specified by:
      startAt in interface SimpleQuery<T>
      Returns:
      a new immutable query object that applies the cursor
    • endAt

      public QueryImpl<T> endAt(com.google.cloud.datastore.Cursor value)
      Description copied from interface: SimpleQuery
      Ends query results at the specified Cursor. You can obtain a Cursor from a QueryResultIterator by calling the getCursor() method.

      All command objects are immutable; this method returns a new object instead of modifying the current command object.

      Note that limit() and offset() are NOT encoded within a cursor; they operate on the results of the query after a cursor is established.
      Specified by:
      endAt in interface SimpleQuery<T>
      Returns:
      a new immutable query object that applies the cursor
    • chunk

      public QueryImpl<T> chunk(int value)
      Description copied from interface: SimpleQuery
      Sets the internal chunking and prefetching strategy within the low-level API. Affects performance only; the result set will be the same.

      All command objects are immutable; this method returns a new object instead of modifying the current command object.

      Specified by:
      chunk in interface SimpleQuery<T>
      Parameters:
      value - must be >= 0
      Returns:
      a new immutable query object that applies the chunk size
    • hybrid

      public QueryImpl<T> hybrid(boolean force)
      Description copied from interface: SimpleQuery

      This method forces Objectify to (or not to) hybridize the query into a keys-only fetch plus batch get.

      If Objectify knows you are fetching an entity type that can be cached, it automatically converts queries into a "hybrid" of keys-only query followed by a batch fetch of the keys. This is cheaper, and if the cache hits, significantly faster. However, there are some circumstances in which you may wish to force behavior one way or another:

      • Issuing a kindless query (which Objectify will not auto-hybridize) when you know a significant portion of the result set is cacheable.
      • Some exotic queries cannot be made keys-only, and produce an exception from the Low-Level API when you try to execute the query. Objectify tries to detect these cases but since the underlying implementation may change, you may need to force hybridization off in some cases.

      Note that in hybrid queries, the chunk size defines the batch size.

      All command objects are immutable; this method returns a new object instead of modifying the current command object.

      Specified by:
      hybrid in interface SimpleQuery<T>
      Returns:
      a new immutable query object that forces hybridization on or off
    • chunkAll

      public QueryImpl<T> chunkAll()
      Description copied from interface: SimpleQuery

      Sets the internal chunking and prefetching strategy within the low-level API to attempt to get all results at once. Affects performance only; the result set will be the same.

      All command objects are immutable; this method returns a new object instead of modifying the current command object.

      Same as chunk(Integer.MAX_VALUE).

      Specified by:
      chunkAll in interface SimpleQuery<T>
      Returns:
      a new immutable query object that applies the chunk size
    • keys

      public QueryKeys<T> keys()
      Description copied from interface: SimpleQuery
      Switches to a keys-only query. Keys-only responses are billed as "minor datastore operations" which are faster and free compared to fetching whole entities.

      All command objects are immutable; this method returns a new object instead of modifying the current command object.

      Specified by:
      keys in interface SimpleQuery<T>
      Returns:
      a new immutable query object that returns keys rather than whole entities
    • distinct

      public QueryImpl<T> distinct(boolean value)
      Description copied from interface: SimpleQuery
      Determines whether this is a SELECT DISTINCT query.

      All command objects are immutable; this method returns a new object instead of modifying the current command object.

      Specified by:
      distinct in interface SimpleQuery<T>
      Returns:
      a new immutable query object that applies the distinct operator
    • project

      public QueryImpl<T> project(String... fields)
      Description copied from interface: SimpleQuery

      Converts this query into a projection query. Projection queries allow values to be selected directly out of an index rather than loading the whole entity. While this allows data to be fetched quickly and cheaply, it is limited to selecting data that exists in an index.

      Entities returned from projection queries are NOT kept in the session cache. However, @Load annotations are processed normally.

      This method can be called more than once; it will have the same effect as passing all the fields in to a single call.

      Specified by:
      project in interface SimpleQuery<T>
      Parameters:
      fields - is one or more field names
      Returns:
      a new immutable query object that projects the specified fields