public class AVQuery<T extends AVObject>
extends java.lang.Object
The AVQuery class defines a query that is used to fetch AVObjects. The most common use case is finding all objects that match a query through the findInBackground method, using a FindCallback. For example, this sample code fetches all objects of class "MyClass". It calls a different function depending on whether the fetch succeeded or not.
AVQueryquery = AVQuery.getQuery("MyClass"); query.findInBackground(new FindCallback () { public void done(List objects, AVException e) { if (e == null) { objectsWereRetrievedSuccessfully(objects); } else { objectRetrievalFailed(); } } }
A AVQuery can also be used to retrieve a single object whose id is known, through the getInBackground method, using a GetCallback. For example, this sample code fetches an object of class "MyClass" and id myId. It calls a different function depending on whether the fetch succeeded or not.
AVQueryquery = AVQuery.getQuery("MyClass"); query.getInBackground(myId, new GetCallback () { public void done(AVObject object, AVException e) { if (e == null) { objectWasRetrievedSuccessfully(object); } else { objectRetrievalFailed(); } } }
A AVQuery can also be used to count the number of objects that match the query without retrieving all of those objects. For example, this sample code counts the number of objects of the class "MyClass".
AVQueryquery = AVQuery.getQuery("MyClass"); query.countInBackground(new CountCallback() { public void done(int count, AVException e) { if (e == null) { objectsWereCounted(count); } else { objectCountFailed(); } } }
Using the callback methods is usually preferred because the network operation will not block the calling thread. However, in some cases it may be easier to use the find, get or count calls, which do block the calling thread. For example, if your application has already spawned a background task to perform work, that background task could use the blocking calls and avoid the code complexity of callbacks.
限定符和类型 | 类和说明 |
---|---|
static class |
AVQuery.CachePolicy |
构造器和说明 |
---|
AVQuery(java.lang.String theClassName)
Constructs a query.
|
限定符和类型 | 方法和说明 |
---|---|
AVQuery<T> |
addAscendingOrder(java.lang.String key)
Also sorts the results in ascending order by the given key.
|
AVQuery<T> |
addDescendingOrder(java.lang.String key)
Also sorts the results in descending order by the given key.
|
static <T extends AVObject> |
and(java.util.List<AVQuery<T>> queries) |
void |
cancel()
已过时。
|
static void |
clearAllCachedResults()
Clears the cached result for all queries.
|
void |
clearCachedResult()
Removes the previously cached result for this query, forcing the next find() to hit the
network.
|
AVQuery |
clone()
clone a new query object, which fully same to this.
|
int |
count()
Counts the number of objects that match this query.
|
void |
countInBackground(CountCallback callback)
Counts the number of objects that match this query in a background thread.
|
void |
deleteAll()
Delete all objects that are retrieved by this query.
|
void |
deleteAllInBackground(DeleteCallback cb)
Delete all objects that are retrieved by this query in background.
|
static AVCloudQueryResult |
doCloudQuery(java.lang.String cql)
通过cql查询对象
请在异步线程中调用此方法,在UI线程中,请调用doCloudQueryInBackground方法
|
static AVCloudQueryResult |
doCloudQuery(java.lang.String cql,
java.lang.Class<? extends AVObject> clazz)
通过cql查询对象
请在异步线程中调用此方法,在UI线程中,请调用doCloudQueryInBackground方法
|
static AVCloudQueryResult |
doCloudQuery(java.lang.String cql,
java.lang.Class<? extends AVObject> clazz,
java.lang.Object... params)
通过cql查询对象
|
static AVCloudQueryResult |
doCloudQuery(java.lang.String cql,
java.lang.Object... params)
通过cql查询对象
|
static void |
doCloudQueryInBackground(java.lang.String cql,
CloudQueryCallback<AVCloudQueryResult> callback)
通过cql查询对象
|
static void |
doCloudQueryInBackground(java.lang.String cql,
CloudQueryCallback<AVCloudQueryResult> callback,
java.lang.Class<? extends AVObject> clazz)
通过cql查询对象
|
static void |
doCloudQueryInBackground(java.lang.String cql,
CloudQueryCallback<AVCloudQueryResult> callback,
java.lang.Class<? extends AVObject> clazz,
java.lang.Object... params)
通过cql查询对象
|
static void |
doCloudQueryInBackground(java.lang.String cql,
CloudQueryCallback<AVCloudQueryResult> callback,
java.lang.Object... params)
通过cql查询对象
|
java.util.List<T> |
find()
Retrieves a list of AVObjects that satisfy this query.
|
void |
findInBackground(FindCallback<T> callback)
Retrieves a list of AVObjects that satisfy this query from the server in a background thread.
|
T |
get(java.lang.String theObjectId)
Constructs a AVObject whose id is already known by fetching data from the server.
|
AVQuery.CachePolicy |
getCachePolicy()
Accessor for the caching policy.
|
java.lang.String |
getClassName()
Accessor for the class name.
|
T |
getFirst()
Retrieves at most one AVObject that satisfies this query.
|
void |
getFirstInBackground(GetCallback<T> callback)
Retrieves at most one AVObject that satisfies this query from the server in a background
thread.
|
void |
getInBackground(java.lang.String objectId,
GetCallback<T> callback)
Constructs a AVObject whose id is already known by fetching data from the server in a
background thread.
|
int |
getLimit()
Accessor for the limit.
|
long |
getMaxCacheAge()
Gets the maximum age of cached data that will be considered in this query.
|
java.lang.String |
getOrder() |
AVQuery.CachePolicy |
getPolicy() |
static <T extends AVObject> |
getQuery(java.lang.Class<T> clazz)
Create a AVQuery with special sub-class.
|
static <T extends AVObject> |
getQuery(java.lang.String theClassName)
Constructs a query.
|
int |
getSkip()
Accessor for the skip value.
|
static AVQuery<AVUser> |
getUserQuery()
已过时。
|
boolean |
hasCachedResult()
Returns whether or not this query has a cached result.
|
AVQuery<T> |
include(java.lang.String key)
Include nested AVObjects for the provided key.
|
AVQuery<T> |
includeACL(boolean includeACL)
Include ACL attribute.
|
boolean |
isTrace() |
AVQuery<T> |
limit(int limit) |
static <T extends AVObject> |
or(java.util.List<AVQuery<T>> queries)
Constructs a query that is the or of the given queries.
|
AVQuery<T> |
order(java.lang.String order) |
AVQuery<T> |
orderByAscending(java.lang.String key)
Sorts the results in ascending order by the given key.
|
AVQuery<T> |
orderByDescending(java.lang.String key)
Sorts the results in descending order by the given key.
|
AVQuery<T> |
selectKeys(java.util.Collection<java.lang.String> keys)
Restrict the fields of returned AVObjects to only include the provided keys.
|
AVQuery<T> |
setCachePolicy(AVQuery.CachePolicy cachePolicy)
Change the caching policy of this query.
|
AVQuery<T> |
setClassName(java.lang.String className) |
AVQuery<T> |
setLimit(int limit)
Controls the maximum number of results that are returned.
|
AVQuery<T> |
setMaxCacheAge(long maxCacheAge)
Sets the maximum age of cached data that will be considered in this query.
|
AVQuery<T> |
setOrder(java.lang.String order)
Set query order fields.
|
AVQuery<T> |
setPolicy(AVQuery.CachePolicy policy)
Change the caching policy of this query.
|
AVQuery<T> |
setSkip(int skip)
Controls the number of results to skip before returning any results.
|
AVQuery<T> |
setTrace(boolean trace)
Turn on performance tracing of finds.
|
AVQuery<T> |
skip(int skip) |
AVQuery<T> |
whereContainedIn(java.lang.String key,
java.util.Collection<? extends java.lang.Object> values)
Add a constraint to the query that requires a particular key's value to be contained in the
provided list of values.
|
AVQuery<T> |
whereContains(java.lang.String key,
java.lang.String substring)
Add a constraint for finding string values that contain a provided string.
|
AVQuery<T> |
whereContainsAll(java.lang.String key,
java.util.Collection<?> values)
Add a constraint to the query that requires a particular key's value match another AVQuery.
|
AVQuery<T> |
whereDoesNotExist(java.lang.String key)
Add a constraint for finding objects that do not contain a given key.
|
AVQuery<T> |
whereDoesNotMatchKeyInQuery(java.lang.String key,
java.lang.String keyInQuery,
AVQuery<?> query)
Add a constraint to the query that requires a particular key's value does not match any value
for a key in the results of another AVQuery.
|
AVQuery<T> |
whereDoesNotMatchQuery(java.lang.String key,
AVQuery<?> query)
Add a constraint to the query that requires a particular key's value does not match another
AVQuery.
|
AVQuery<T> |
whereEndsWith(java.lang.String key,
java.lang.String suffix)
Add a constraint for finding string values that end with a provided string.
|
AVQuery<T> |
whereEqualTo(java.lang.String key,
java.lang.Object value)
Add a constraint to the query that requires a particular key's value to be equal to the
provided value.
|
AVQuery<T> |
whereExists(java.lang.String key)
Add a constraint for finding objects that contain the given key.
|
AVQuery<T> |
whereGreaterThan(java.lang.String key,
java.lang.Object value)
Add a constraint to the query that requires a particular key's value to be greater than the
provided value.
w
|
AVQuery<T> |
whereGreaterThanOrEqualTo(java.lang.String key,
java.lang.Object value)
Add a constraint to the query that requires a particular key's value to be greater or equal to
than the provided value.
|
AVQuery<T> |
whereLessThan(java.lang.String key,
java.lang.Object value)
Add a constraint to the query that requires a particular key's value to be less than the
provided value.
|
AVQuery<T> |
whereLessThanOrEqualTo(java.lang.String key,
java.lang.Object value)
Add a constraint to the query that requires a particular key's value to be less or equal to
than the provided value.
|
AVQuery<T> |
whereMatches(java.lang.String key,
java.lang.String regex)
Add a regular expression constraint for finding string values that match the provided regular
expression.
|
AVQuery<T> |
whereMatches(java.lang.String key,
java.lang.String regex,
java.lang.String modifiers)
Add a regular expression constraint for finding string values that match the provided regular
expression.
|
AVQuery<T> |
whereMatchesKeyInQuery(java.lang.String key,
java.lang.String keyInQuery,
AVQuery<?> query)
Add a constraint to the query that requires a particular key's value matches a value for a key
in the results of another AVQuery
|
AVQuery<T> |
whereMatchesQuery(java.lang.String key,
AVQuery<?> query)
Add a constraint to the query that requires a particular key's value match another AVQuery.
|
AVQuery<T> |
whereNear(java.lang.String key,
AVGeoPoint point)
Add a proximity based constraint for finding objects with key point values near the point
given.
|
AVQuery<T> |
whereNotContainedIn(java.lang.String key,
java.util.Collection<? extends java.lang.Object> values)
Add a constraint to the query that requires a particular key's value not be contained in the
provided list of values.
|
AVQuery<T> |
whereNotEqualTo(java.lang.String key,
java.lang.Object value)
Add a constraint to the query that requires a particular key's value to be not equal to the
provided value.
|
AVQuery<T> |
whereSizeEqual(java.lang.String key,
int size)
添加查询约束条件,查找key类型是数组,该数组的长度匹配提供的数值。
|
AVQuery<T> |
whereStartsWith(java.lang.String key,
java.lang.String prefix)
Add a constraint for finding string values that start with a provided string.
|
AVQuery<T> |
whereWithinGeoBox(java.lang.String key,
AVGeoPoint southwest,
AVGeoPoint northeast)
Add a constraint to the query that requires a particular key's coordinates be contained within
a given rectangular geographic bounding box.
|
AVQuery<T> |
whereWithinKilometers(java.lang.String key,
AVGeoPoint point,
double maxDistance)
Add a proximity based constraint for finding objects with key point values near the point given
and within the maximum distance given.
|
AVQuery<T> |
whereWithinKilometers(java.lang.String key,
AVGeoPoint point,
double maxDistance,
double minDistance)
Add a proximity based constraint for finding objects with key point values near the point given
and within the given ring area
Radius of earth used is 6371.0 kilometers.
|
AVQuery<T> |
whereWithinMiles(java.lang.String key,
AVGeoPoint point,
double maxDistance)
Add a proximity based constraint for finding objects with key point values near the point given
and within the maximum distance given.
|
AVQuery<T> |
whereWithinMiles(java.lang.String key,
AVGeoPoint point,
double maxDistance,
double minDistance)
Add a proximity based constraint for finding objects with key point values near the point
given and within the given ring.
|
AVQuery<T> |
whereWithinRadians(java.lang.String key,
AVGeoPoint point,
double maxDistance)
Add a proximity based constraint for finding objects with key point values near the point given
and within the maximum distance given.
|
AVQuery<T> |
whereWithinRadians(java.lang.String key,
AVGeoPoint point,
double maxDistance,
double minDistance)
Add a proximity based constraint for finding objects with key point values near the point given
and within the maximum distance given.
|
public AVQuery(java.lang.String theClassName)
theClassName
- The name of the class to retrieve AVObjects for.public java.lang.String getClassName()
public AVQuery.CachePolicy getCachePolicy()
public AVQuery<T> setCachePolicy(AVQuery.CachePolicy cachePolicy)
public AVQuery.CachePolicy getPolicy()
public AVQuery<T> setPolicy(AVQuery.CachePolicy policy)
public long getMaxCacheAge()
public AVQuery<T> setMaxCacheAge(long maxCacheAge)
public boolean isTrace()
public AVQuery<T> setTrace(boolean trace)
public AVQuery clone()
clone
在类中 java.lang.Object
public static <T extends AVObject> AVQuery<T> getQuery(java.lang.String theClassName)
theClassName
- The name of the class to retrieve AVObjects for.public static <T extends AVObject> AVQuery<T> getQuery(java.lang.Class<T> clazz)
clazz
- The AVObject subclass@Deprecated public void cancel()
public static void clearAllCachedResults()
public void clearCachedResult()
@Deprecated public static AVQuery<AVUser> getUserQuery()
AVUser.getQuery()
public boolean hasCachedResult()
public int getLimit()
public AVQuery<T> setLimit(int limit)
public AVQuery<T> limit(int limit)
limit
- setLimit(int)
public AVQuery<T> skip(int skip)
skip
- setSkip(int)
public int getSkip()
public AVQuery<T> setSkip(int skip)
public java.lang.String getOrder()
public AVQuery<T> setOrder(java.lang.String order)
order
- public AVQuery<T> order(java.lang.String order)
order
- setOrder(String)
public AVQuery<T> addAscendingOrder(java.lang.String key)
key
- The key to order bypublic AVQuery<T> addDescendingOrder(java.lang.String key)
key
- The key to order bypublic AVQuery<T> includeACL(boolean includeACL)
includeACL
- need ACL attribute returned or not.public AVQuery<T> include(java.lang.String key)
key
- The key that should be included.public AVQuery<T> selectKeys(java.util.Collection<java.lang.String> keys)
keys
- The set of keys to include in the result.public AVQuery<T> orderByAscending(java.lang.String key)
key
- The key to order by.public AVQuery<T> orderByDescending(java.lang.String key)
key
- The key to order by.public AVQuery<T> whereContainedIn(java.lang.String key, java.util.Collection<? extends java.lang.Object> values)
key
- The key to check.values
- The values that will match.public AVQuery<T> whereContains(java.lang.String key, java.lang.String substring)
key
- The key that the string to match is stored in.substring
- The substring that the value must contain.public AVQuery<T> whereSizeEqual(java.lang.String key, int size)
key
- 查询的keysize
- 数组的长度public AVQuery<T> whereContainsAll(java.lang.String key, java.util.Collection<?> values)
key
- The key to check. This key's value must be an array.values
- The values that will match.public AVQuery<T> whereDoesNotExist(java.lang.String key)
key
- The key that should not existpublic AVQuery<T> whereEndsWith(java.lang.String key, java.lang.String suffix)
key
- The key that the string to match is stored in.suffix
- The substring that the value must end with.public AVQuery<T> whereEqualTo(java.lang.String key, java.lang.Object value)
key
- The key to check.value
- The value that the AVObject must contain.public AVQuery<T> whereExists(java.lang.String key)
key
- The key that should exist.public AVQuery<T> whereGreaterThan(java.lang.String key, java.lang.Object value)
key
- The key to check.value
- The value that provides an lower bound.public AVQuery<T> whereGreaterThanOrEqualTo(java.lang.String key, java.lang.Object value)
key
- The key to check.value
- The value that provides an lower bound.public AVQuery<T> whereLessThan(java.lang.String key, java.lang.Object value)
key
- The key to check.value
- The value that provides an upper bound.public AVQuery<T> whereLessThanOrEqualTo(java.lang.String key, java.lang.Object value)
key
- The key to check.value
- The value that provides an lower bound.public AVQuery<T> whereMatches(java.lang.String key, java.lang.String regex)
key
- The key that the string to match is stored in.regex
- The regular expression pattern to match.public AVQuery<T> whereMatches(java.lang.String key, java.lang.String regex, java.lang.String modifiers)
key
- The key that the string to match is stored in.regex
- The regular expression pattern to match.modifiers
- Any of the following supported PCRE modifiers: i - Case insensitive search m -
Search across multiple lines of inputpublic AVQuery<T> whereNear(java.lang.String key, AVGeoPoint point)
key
- The key that the AVGeoPoint is stored in.point
- The reference AVGeoPoint that is used.public AVQuery<T> whereNotContainedIn(java.lang.String key, java.util.Collection<? extends java.lang.Object> values)
key
- The key to check.values
- The values that will not match.public AVQuery<T> whereNotEqualTo(java.lang.String key, java.lang.Object value)
key
- The key to check.value
- The value that must not be equalled.public AVQuery<T> whereStartsWith(java.lang.String key, java.lang.String prefix)
key
- The key that the string to match is stored in.prefix
- The substring that the value must start with.public AVQuery<T> whereWithinGeoBox(java.lang.String key, AVGeoPoint southwest, AVGeoPoint northeast)
key
- The key to be constrained.southwest
- The lower-left inclusive corner of the box.northeast
- The upper-right inclusive corner of the box.public AVQuery<T> whereWithinKilometers(java.lang.String key, AVGeoPoint point, double maxDistance)
key
- The key that the AVGeoPoint is stored in.point
- The reference AVGeoPoint that is used.maxDistance
- Maximum distance (in kilometers) of results to return.public AVQuery<T> whereWithinKilometers(java.lang.String key, AVGeoPoint point, double maxDistance, double minDistance)
key
- The key that the AVGeoPoint is stored in.point
- The reference AVGeoPoint that is used.maxDistance
- outer radius of the given ring in kilometersminDistance
- inner radius of the given ring in kilometerspublic AVQuery<T> whereWithinMiles(java.lang.String key, AVGeoPoint point, double maxDistance)
public AVQuery<T> whereWithinMiles(java.lang.String key, AVGeoPoint point, double maxDistance, double minDistance)
key
- point
- maxDistance
- minDistance
- public AVQuery<T> whereWithinRadians(java.lang.String key, AVGeoPoint point, double maxDistance)
key
- The key that the AVGeoPoint is stored in.point
- The reference AVGeoPoint that is used.maxDistance
- Maximum distance (in radians) of results to return.public AVQuery<T> whereWithinRadians(java.lang.String key, AVGeoPoint point, double maxDistance, double minDistance)
key
- point
- maxDistance
- minDistance
- public static <T extends AVObject> AVQuery<T> or(java.util.List<AVQuery<T>> queries)
queries
- The list of AVQueries to 'or' togetherpublic AVQuery<T> whereMatchesKeyInQuery(java.lang.String key, java.lang.String keyInQuery, AVQuery<?> query)
key
- The key whose value is being checkedkeyInQuery
- The key in the objects from the sub query to look inquery
- The sub query to runpublic AVQuery<T> whereMatchesQuery(java.lang.String key, AVQuery<?> query)
key
- The key to check.query
- The query that the value should matchpublic AVQuery<T> whereDoesNotMatchKeyInQuery(java.lang.String key, java.lang.String keyInQuery, AVQuery<?> query)
key
- The key whose value is being checked and excludedkeyInQuery
- The key in the objects from the sub query to look inquery
- The sub query to runpublic AVQuery<T> whereDoesNotMatchQuery(java.lang.String key, AVQuery<?> query)
key
- The key to check.query
- The query that the value should not matchpublic static AVCloudQueryResult doCloudQuery(java.lang.String cql, java.lang.Object... params) throws java.lang.Exception
cql
- cql语句params
- 查询参数列表java.lang.Exception
public static AVCloudQueryResult doCloudQuery(java.lang.String cql, java.lang.Class<? extends AVObject> clazz, java.lang.Object... params) throws java.lang.Exception
cql
- clazz
- params
- 查询参数列表java.lang.Exception
public static void doCloudQueryInBackground(java.lang.String cql, CloudQueryCallback<AVCloudQueryResult> callback, java.lang.Object... params)
cql
- callback
- params
- 查询参数列表public static void doCloudQueryInBackground(java.lang.String cql, CloudQueryCallback<AVCloudQueryResult> callback, java.lang.Class<? extends AVObject> clazz, java.lang.Object... params)
cql
- callback
- clazz
- params
- public static AVCloudQueryResult doCloudQuery(java.lang.String cql) throws java.lang.Exception
cql
- java.lang.Exception
public static AVCloudQueryResult doCloudQuery(java.lang.String cql, java.lang.Class<? extends AVObject> clazz) throws java.lang.Exception
cql
- clazz
- java.lang.Exception
public static void doCloudQueryInBackground(java.lang.String cql, CloudQueryCallback<AVCloudQueryResult> callback)
cql
- callback
- public static void doCloudQueryInBackground(java.lang.String cql, CloudQueryCallback<AVCloudQueryResult> callback, java.lang.Class<? extends AVObject> clazz)
cql
- callback
- clazz
- public void findInBackground(FindCallback<T> callback)
callback
- callback.done(objectList, e) is called when the find completes.public T get(java.lang.String theObjectId) throws AVException
theObjectId
- Object id of the AVObject to fetch.AVException
public T getFirst() throws AVException
AVException
public void getFirstInBackground(GetCallback<T> callback)
callback
- callback.done(object, e) is called when the find completes.public void getInBackground(java.lang.String objectId, GetCallback<T> callback)
objectId
- Object id of the AVObject to fetchcallback
- callback.done(object, e) will be called when the fetch completes.public int count() throws AVException
AVException
public void countInBackground(CountCallback callback)
callback
- callback.done(count, e) will be called when the count completes.public java.util.List<T> find() throws AVException
AVException
public void deleteAll() throws AVException
AVException
public void deleteAllInBackground(DeleteCallback cb)
cb
- The delete callback.Copyright © 2013 AVOS Systems Inc. All Rights Reserved.