com.leanengine
Class LeanQuery

java.lang.Object
  extended by com.leanengine.LeanQuery

public class LeanQuery
extends java.lang.Object

Class to perform data queries against server datastore.


Nested Class Summary
static class LeanQuery.FilterOperator
          FilterOperator specifies what type of operation you want to apply to your filter.
static class LeanQuery.SortDirection
          SortDirection controls the order of a sort.
 
Constructor Summary
LeanQuery(java.lang.String kind)
          Constructor to initialize query.
 
Method Summary
 LeanQuery addFilter(java.lang.String property, LeanQuery.FilterOperator operator, java.lang.Object value)
          Adds a filter on the specified property.
 LeanQuery addSort(java.lang.String property, LeanQuery.SortDirection direction)
          Adds a sort on the specified property.
 LeanEntity[] fetch()
          Executes the query and fetches the initial data set.
 void fetchInBackground(NetworkCallback<LeanEntity> callback)
          Executes the query and fetches the initial data set.
 LeanEntity[] fetchNext()
          Executes the query and fetches the next data set.
 void fetchNextInBackground(NetworkCallback<LeanEntity> callback)
          Executes the query and fetches the next data set.
 java.util.List<QueryFilter> getFilters()
          Returns a list of QueryFilters set on this query.
 java.lang.String getKind()
          Returns the kind (name) of entities this query is fetching.
 int getLimit()
          Returns the limit set on this query - the size of result set to return when fetching.
 int getOffset()
          Returns the offset set on this query - the number of results to skip before returning any results.
 java.util.List<QuerySort> getSorts()
          Returns a list of QuerySorts set on this query.
 LeanQuery limit(int limit)
          The size of result set returned by this query's fetch methods.
 LeanQuery offset(int offset)
          Sets the offset - the number of results to skip before returning any results.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LeanQuery

public LeanQuery(java.lang.String kind)
Constructor to initialize query.

Parameters:
kind - The kind (name) of entities to search for.
Method Detail

fetchInBackground

public void fetchInBackground(NetworkCallback<LeanEntity> callback)
Executes the query and fetches the initial data set. This method executes in the background thread.

The result set returned depends on the limit(int) and offset(int) called on this query. The defaults are: limit = 20 and offset = 0 as defined by the Google AppEngine.

To get the next batch of results use fetchNextInBackground(NetworkCallback) or fetchNext().

Parameters:
callback - NetworkCallback that will be invoked when background task is done.

fetchNextInBackground

public void fetchNextInBackground(NetworkCallback<LeanEntity> callback)
                           throws java.lang.IllegalStateException
Executes the query and fetches the next data set. This method executes in the background thread.

This method may only be called after fetch() or fetchInBackground(NetworkCallback) are invoked.

Query parameters must not be changed between invocation of fetch() and fetchNext() methods.

Parameters:
callback - NetworkCallback that will be invoked when background task is done.
Throws:
java.lang.IllegalStateException - If called before fetch() or fetchInBackground(NetworkCallback).

fetch

public LeanEntity[] fetch()
                   throws LeanException
Executes the query and fetches the initial data set.

The results returned depend on the limit(int) and offset(int) called on this query. The defaults are: limit = 20 and offset = 0 as defined by the Google AppEngine.

To get the next batch of results use fetchNext() or fetchNextInBackground(NetworkCallback).

Returns:
The array of LeanEntities representing the result of query.
Throws:
LeanException - In case of errors a LeanException is thrown.
java.lang.IllegalStateException - If called before fetch() or fetchInBackground(NetworkCallback).

fetchNext

public LeanEntity[] fetchNext()
                       throws LeanException
Executes the query and fetches the next data set.

This method may only be called after fetch() or fetchInBackground(NetworkCallback) are invoked.

Query parameters must not be changed between invocation of fetch() and fetchNext() methods.

Returns:
The array of LeanEntities representing the result of query.
Throws:
LeanException - In case of errors a LeanException is thrown.
java.lang.IllegalStateException - If called before fetch() or fetchInBackground(NetworkCallback).

addFilter

public LeanQuery addFilter(java.lang.String property,
                           LeanQuery.FilterOperator operator,
                           java.lang.Object value)
Adds a filter on the specified property.

Parameters:
property - The name of the property to which the filter applies.
operator - A LeanQuery.FilterOperator to use.
value - An instance of a supported datastore type.
Returns:
this (for chaining)

addSort

public LeanQuery addSort(java.lang.String property,
                         LeanQuery.SortDirection direction)
Adds a sort on the specified property.

Parameters:
property - The name of the property to which the sort applies.
direction - A LeanQuery.SortDirection to use.
Returns:
this (for chaining)

getKind

public java.lang.String getKind()
Returns the kind (name) of entities this query is fetching.

Returns:
Kind of entity.

getSorts

public java.util.List<QuerySort> getSorts()
Returns a list of QuerySorts set on this query.

Returns:
List<QuerySort>

getFilters

public java.util.List<QueryFilter> getFilters()
Returns a list of QueryFilters set on this query.

Returns:
List<QueryFilter>

limit

public LeanQuery limit(int limit)
The size of result set returned by this query's fetch methods.

Parameters:
limit - The size of result set.
Returns:
this (for chaining)

getLimit

public int getLimit()
Returns the limit set on this query - the size of result set to return when fetching. See limit(int)

Returns:
The size of result set.

getOffset

public int getOffset()
Returns the offset set on this query - the number of results to skip before returning any results. See offset(int)

Returns:
The number of results to skip before returning the result set.

offset

public LeanQuery offset(int offset)
Sets the offset - the number of results to skip before returning any results.

Note: this method has a high cost in terms of datastore access charges - all entities skipped by the offset count as retrieved in AppEngine billing.

Parameters:
offset - The number of results to skip before returning the result set.
Returns:
this (for chaining)