|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.google.appengine.api.datastore.Query
public final class Query
Query
encapsulates a request for zero or more Entity
objects
out of the datastore. It supports querying on zero or more properties,
querying by ancestor, and sorting. Entity
objects which match the
query can be retrieved in a single list, or with an unbounded iterator.
Nested Class Summary | |
---|---|
static class |
Query.FilterOperator
FilterOperator specifies what type of operation you want to apply to your filter. |
static class |
Query.FilterPredicate
FilterPredicate is a data container that holds a single filter predicate. |
static class |
Query.SortDirection
SortDirection controls the order of a sort. |
static class |
Query.SortPredicate
SortPredicate is a data container that holds a single sort predicate. |
Field Summary | |
---|---|
static java.lang.String |
KIND_METADATA_KIND
A metadata kind that can be used to query for kinds that exist in the datastore. |
static java.lang.String |
NAMESPACE_METADATA_KIND
A metadata kind that can be used to query for namespaces that exist in the datastore. |
static java.lang.String |
PROPERTY_METADATA_KIND
A metadata kind that can be used to query for properties that exist in the datastore. |
Constructor Summary | |
---|---|
Query()
Create a new kindless Query that finds Entity objects. |
|
Query(Key ancestor)
Create a new Query that finds Entity objects with
the specified Key as an ancestor. |
|
Query(java.lang.String kind)
Create a new Query that finds Entity objects with
the specified kind . |
|
Query(java.lang.String kind,
Key ancestor)
Create a new Query that finds Entity objects with
the specified kind and the specified ancestor . |
Method Summary | |
---|---|
Query |
addFilter(java.lang.String propertyName,
Query.FilterOperator operator,
java.lang.Object value)
Add a filter on the specified property. |
Query |
addSort(java.lang.String propertyName)
Specify how the query results should be sorted. |
Query |
addSort(java.lang.String propertyName,
Query.SortDirection direction)
Specify how the query results should be sorted. |
boolean |
equals(java.lang.Object o)
|
Key |
getAncestor()
Gets the current ancestor for this query, or null if there is no ancestor specified. |
java.util.List<Query.FilterPredicate> |
getFilterPredicates()
Returns an unmodifiable list of the current filter predicates. |
java.lang.String |
getKind()
Only Entity objects whose kind matches this value will be
returned. |
java.util.List<Query.SortPredicate> |
getSortPredicates()
Returns an unmodifiable list of the current sort predicates. |
int |
hashCode()
|
boolean |
isKeysOnly()
Returns true if this query will fetch and return keys only, false if it will fetch and return full entities. |
Query |
reverse()
Creates a query sorted in the exact opposite direction as the current one. |
Query |
setAncestor(Key ancestor)
Sets an ancestor for this query. |
Query |
setKeysOnly()
Makes this query fetch and return only keys, not full entities. |
java.lang.String |
toString()
Outputs a SQL like string representing the query. |
Methods inherited from class java.lang.Object |
---|
getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String KIND_METADATA_KIND
public static final java.lang.String PROPERTY_METADATA_KIND
public static final java.lang.String NAMESPACE_METADATA_KIND
Constructor Detail |
---|
public Query()
Query
that finds Entity
objects.
Note that kindless queries are not yet supported in the Java dev
appserver.
Currently the only operations supported on a kindless query are filter by
__key__, ancestor, and order by __key__ ascending.
public Query(java.lang.String kind)
Query
that finds Entity
objects with
the specified kind
. Note that kindless queries are not yet
supported in the Java dev appserver.
kind
- the kind or null to create a kindless querypublic Query(Key ancestor)
Query
that finds Entity
objects with
the specified Key
as an ancestor.
ancestor
- the ancestor key or null
java.lang.IllegalArgumentException
- If ancestor is not complete.public Query(java.lang.String kind, Key ancestor)
Query
that finds Entity
objects with
the specified kind
and the specified ancestor
. Note that
kindless queries are not yet supported in the Java dev appserver.
kind
- the kind or null to create a kindless queryancestor
- the ancestor key or null
java.lang.IllegalArgumentException
- If the ancestor is not complete.Method Detail |
---|
public java.lang.String getKind()
Entity
objects whose kind matches this value will be
returned.
public Key getAncestor()
public Query setAncestor(Key ancestor)
null
as a parameter does not query for entities without
ancestors (this type of query is not currently supported).
this
(for chaining)
java.lang.IllegalArgumentException
- If the ancestor key is incomplete, or if
you try to unset an ancestor and have not set a kind, or if you try to
unset an ancestor and have not previously set an ancestor.public Query addFilter(java.lang.String propertyName, Query.FilterOperator operator, java.lang.Object value)
propertyName
- The name of the property to which the filter applies.operator
- The filter operator.value
- An instance of a supported datastore type. Note that
entities with multi-value properties identified by propertyName
will match this filter if the multi-value property has at least one
value that matches the condition expressed by operator
and
value
. For more information on multi-value property filtering
please see the
datastore documentation.
this
(for chaining)
java.lang.NullPointerException
- If propertyName
or operator
is null.
java.lang.IllegalArgumentException
- If value
is not of a
type supported by the datastore. See
DataTypeUtils.isSupportedType(Class)
. Note that unlike
Entity.setProperty(String, Object)
, you cannot provide
a Collection
containing instances of supported types
to this method.public java.util.List<Query.FilterPredicate> getFilterPredicates()
public Query addSort(java.lang.String propertyName)
addSort(String,SortDirection)
.
Note that entities with multi-value properties identified by
propertyName
will be sorted by the smallest value in the list.
For more information on sorting properties with multiple values please see
the
datastore documentation.
this
(for chaining)
java.lang.NullPointerException
- If any argument is null.public Query addSort(java.lang.String propertyName, Query.SortDirection direction)
direction
is Query.SortDirection.ASCENDING
,
entities with multi-value properties identified by
propertyName
will be sorted by the smallest value in the list. If
direction
is Query.SortDirection.DESCENDING
, entities with
multi-value properties identified by propertyName
will be sorted
by the largest value in the list. For more information on sorting
properties with multiple values please see
the
datastore documentation.
this
(for chaining)
java.lang.NullPointerException
- If any argument is null.public java.util.List<Query.SortPredicate> getSortPredicates()
public Query setKeysOnly()
this
(for chaining)public boolean isKeysOnly()
public Query reverse()
Entity.KEY_RESERVED_PROPERTY
to guarantee that each entity is uniquely identified by the set of properties
used in the sort (which is required to exactly reverse the order of a query).
Advanced users can reverse the sort orders manually if they know the set of
sorted properties meets this requirement without a order on Entity.KEY_RESERVED_PROPERTY
.
Cursors
from the original query can be converted for use with
the reverse query through Cursor.reverse()
.
java.lang.IllegalStateException
- if the current query is not sorted by
Entity.KEY_RESERVED_PROPERTY
.public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |