public final class MesosferQuery<T extends com.eyro.mesosfer.CoreObject>
extends java.lang.Object
The MesosferQuery
class defines a query that is used to fetch MesosferData
s. The most
common use case is finding all objects that match a query through the findAsync(FindCallback)
method, using a FindCallback
. For example, this sample code fetches all objects of bucket
"MyBucket"
. It calls a different function depending on whether the fetch succeeded or not.
MesosferQuery<MesosferData> query = MesosferData.getQuery("MyBucket"); query.findAsync(new FindCallback<MesosferData>() { public void done(List<MesosferData> objects, ParseException e) { if (e == null) { objectsWereRetrievedSuccessfully(objects); } else { objectRetrievalFailed(); } } }
A MesosferQuery
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 "MyBucket"
.
MesosferQuery<MesosferData> query = MesosferQuery.getQuery("MyBucket"); query.countAsync(new CountCallback() { public void done(int count, ParseException 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.
Modifier and Type | Method and Description |
---|---|
MesosferQuery<T> |
addAscendingOrder(java.lang.String key)
Also sorts the results in ascending order by the given key.
|
MesosferQuery<T> |
addDescendingOrder(java.lang.String key)
Also sorts the results in descending order by the given key.
|
void |
countAsync(CountCallback callback)
Counts the number of objects that match this query in a background thread.
|
void |
findAsync(FindCallback<T> callback)
Retrieves a list of
MesosferData s or MesosferUser s that satisfy this
query from the source in a background thread. |
void |
getAsync(java.lang.String objectId,
GetCallback<T> callback)
Constructs a
MesosferData whose id is already known by fetching data from the
source in a background thread. |
static <T extends com.eyro.mesosfer.CoreObject> |
or(java.util.List<MesosferQuery<T>> queries)
Constructs a query that is the
or of the given queries. |
MesosferQuery<T> |
orderByAscending(java.lang.String key)
Sorts the results in ascending order by the given key.
|
MesosferQuery<T> |
orderByDescending(java.lang.String key)
Sorts the results in descending order by the given key.
|
MesosferQuery<T> |
setLimit(int newLimit)
Controls the maximum number of results that are returned.
|
MesosferQuery<T> |
setSkip(int newSkip)
Controls the number of results to skip before returning any results.
|
MesosferQuery<T> |
whereContains(java.lang.String key,
java.lang.String substring)
Add a constraint for finding string values that contain a provided string.
|
MesosferQuery<T> |
whereDoesNotExist(java.lang.String key)
Add a constraint for finding objects that do not contain a given key.
|
MesosferQuery<T> |
whereEndsWith(java.lang.String key,
java.lang.String suffix)
Add a constraint for finding string values that end with a provided string.
|
MesosferQuery<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.
|
MesosferQuery<T> |
whereExists(java.lang.String key)
Add a constraint for finding objects that contain the given key.
|
MesosferQuery<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.
|
MesosferQuery<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 than or
equal to the provided value.
|
MesosferQuery<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.
|
MesosferQuery<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 than or equal
to the provided value.
|
MesosferQuery<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.
|
MesosferQuery<T> |
whereStartsWith(java.lang.String key,
java.lang.String prefix)
Add a constraint for finding string values that start with a provided string.
|
public MesosferQuery<T> whereEqualTo(java.lang.String key, java.lang.Object value)
key
- The key to check.value
- The value that the MesosferObject
must contain.public MesosferQuery<T> whereLessThan(java.lang.String key, java.lang.Object value)
key
- The key to check.value
- The value that provides an upper bound.public MesosferQuery<T> whereNotEqualTo(java.lang.String key, java.lang.Object value)
key
- The key to check.value
- The value that must not be equalled.public MesosferQuery<T> whereGreaterThan(java.lang.String key, java.lang.Object value)
key
- The key to check.value
- The value that provides an lower bound.public MesosferQuery<T> whereLessThanOrEqualTo(java.lang.String key, java.lang.Object value)
key
- The key to check.value
- The value that provides an upper bound.public MesosferQuery<T> whereGreaterThanOrEqualTo(java.lang.String key, java.lang.Object value)
key
- The key to check.value
- The value that provides an lower bound.public MesosferQuery<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 MesosferQuery<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 MesosferQuery<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 MesosferQuery<T> whereExists(java.lang.String key)
key
- The key that should exist.public MesosferQuery<T> whereDoesNotExist(java.lang.String key)
key
- The key that should not existpublic MesosferQuery<T> orderByAscending(java.lang.String key)
key
- The key to order by.public MesosferQuery<T> addAscendingOrder(java.lang.String key)
key
- The key to order bypublic MesosferQuery<T> orderByDescending(java.lang.String key)
key
- The key to order by.public MesosferQuery<T> addDescendingOrder(java.lang.String key)
key
- The key to order bypublic MesosferQuery<T> setLimit(int newLimit)
100
,
with a maximum of 1000
results being returned at a time.newLimit
- The new limit.public MesosferQuery<T> setSkip(int newSkip)
newSkip
- The new skippublic static <T extends com.eyro.mesosfer.CoreObject> MesosferQuery<T> or(java.util.List<MesosferQuery<T>> queries)
or
of the given queries.queries
- The list of MesosferQuery
s to 'or' togetherMesosferQuery
that is the 'or' of the passed in queriespublic void getAsync(java.lang.String objectId, GetCallback<T> callback)
Constructs a MesosferData
whose id is already known by fetching data from the
source in a background thread. This does not use caching.
MesosferData.createWithObjectId(String)
, unless
your code is already running in a background thread.objectId
- Object id of the MesosferData
to fetch.callback
- callback.done(object, e) will be called when the fetch completes.public void countAsync(CountCallback callback)
callback
- callback.done(count, e) will be called when the count completes.public void findAsync(FindCallback<T> callback)
MesosferData
s or MesosferUser
s that satisfy this
query from the source in a background thread.callback
- callback.done(objectList, e) is called when the find completes.