public class

AsyncAppData

extends AppData<T>
java.lang.Object
   ↳ com.kinvey.java.AppData<T>
     ↳ com.kinvey.android.AsyncAppData<T>

Class Overview

Wraps the com.kinvey.java.AppData public methods in asynchronous functionality using native Android AsyncTask.

This functionality can be accessed through the appData(String, Class) convenience method. AppData gets and saves entities that extend com.google.api.client.json.GenericJson. A class that extends GenericJson can map class members to KinveyCollection properties using com.google.api.client.util.Key attributes. For example, the following will map a string "city" to a Kinvey collection attributed named "city":

     @Key
     private String city;
 

The @Key attribute also can take an optional name, which will map the member to a different attribute name in the Kinvey collection.

     @Key("_id")
     private String customerID;
 

Methods in this API use either KinveyListCallback for retrieving entity sets, KinveyDeleteCallback for deleting appData, or the general-purpose KinveyClientCallback used for retrieving single entites or saving Entities.

Entity Set sample:

 AppData<EventEntity> myAppData = kinveyClient.appData("myCollection",EventEntity.class);
     myAppData.get(appData().query, new KinveyListCallback<EventEntity> {
         public void onFailure(Throwable t) { ... 
         public void onSuccess(EventEntity[] entities) { ... }
     });
 }
 

Summary

[Expand]
Inherited Constants
From class com.kinvey.java.AppData
Public Methods
void average(ArrayList<String> fields, String averageField, Query query, KinveyClientCallback callback)
Asynchronous request to retrieve a group by AVERAGE on a collection or filtered collection

Generates an asynchronous request to group a collection and provide the average value of records based on a field or groups of fields.

void count(ArrayList<String> fields, Query query, KinveyClientCallback callback)
Asynchronous request to retrieve a group by COUNT on a collection or filtered collection.
void delete(String entityID, KinveyDeleteCallback callback)
Asynchronous request to delete an entity to a collection.
void delete(Query query, KinveyDeleteCallback callback)
Asynchronous request to delete a collection of entites from a collection by Query.
void get(String[] ids, KinveyListCallback<T> callback)
Asynchronous request to fetch an array of Entities using an array of _ids.
void get(KinveyListCallback<T> callback)
Asynchronous request to fetch an array of all Entities in a collection.
void get(Query query, KinveyListCallback<T> callback)
Asynchronous request to fetch an array of Entities using a Query object.
void get(Query q, String[] resolves, KinveyListCallback<T> callback)
Asynchronous request to execute a query and resolve KinveyReferences.
void getEntity(String id, String[] resolves, KinveyClientCallback<T> callback)
Asynchronous request to fetch a single entity by _id and resolve KinveyReferences.
void getEntity(String entityID, KinveyClientCallback<T> callback)
Asynchronous request to fetch a single Entity by ID.
boolean isOnline()
Method to check if the current runtime environment has an active connection to the internet, this implementation is tightly coupled with the Android Operating System
void max(ArrayList<String> fields, String maxField, Query query, KinveyClientCallback callback)
Asynchronous request to retrieve a group by MAX on a collection or filtered collection

Generates an asynchronous request to group a collection and provide the max value of records based on a field or groups of fields.

void min(ArrayList<String> fields, String minField, Query query, KinveyClientCallback callback)
Asynchronous request to retrieve a group by MIN on a collection or filtered collection

Generates an asynchronous request to group a collection and provide the min value of records based on a field or groups of fields.

void save(T entity, KinveyClientCallback<T> callback)
Asynchronous request to save or update an entity to a collection.
void setOffline(OfflinePolicy policy, OfflineStore store)
Set an OfflinePolicy on AppData, allowing requests to be executed locally

Sample Usage:

 {@code
     AsyncAppData offline = kinveyClient.appData("events", EventEntity.class);
     offline.setOffline(OfflinePolicy.ALWAYS_ONLINE, new SqlLiteOfflineStore(getContext()));
 

void sum(ArrayList<String> fields, String sumField, Query query, KinveyClientCallback callback)
Asynchronous request to retrieveBlocking a group by SUM on a collection or filtered collection

Generates an asynchronous request to group a collection and provide a sumBlocking of records based on a field or groups of fields.

[Expand]
Inherited Methods
From class com.kinvey.java.AppData
From class java.lang.Object

Public Methods

public void average (ArrayList<String> fields, String averageField, Query query, KinveyClientCallback callback)

Asynchronous request to retrieve a group by AVERAGE on a collection or filtered collection

Generates an asynchronous request to group a collection and provide the average value of records based on a field or groups of fields. The aggregate will reduce an entire collection, or a collection filtered by a Query

Sample Usage:

 AppData<GenericJson> aggregate = kinveyClient.appData("events", EventEntity.class);
     ArrayList<String> fields = new ArrayList<String>();
     fields.add("userName");
     aggregate.average(fields, "orderTotal", null, new KinveyClientCallback<EventEntity>() {
         public void onSuccess(EventEntity event) { ... 
         public void onFailure(Throwable T) {...}
     });
 }
 

Parameters
fields ArrayList of fields to aggregate on
averageField Field to get the maxBlocking value from
query Optional query object for filtering results to aggregate on. Set to null for entire collection.
callback KinveyClientCallback

public void count (ArrayList<String> fields, Query query, KinveyClientCallback callback)

Asynchronous request to retrieve a group by COUNT on a collection or filtered collection.

Generates an asynchronous request to group a collection and provide a count of records based on a field or groups of fields. The aggregate will reduce an entire collection, or a collection filtered by a Query

Sample Usage:

 AppData<GenericJson> aggregate = kinveyClient.appData("events", EventEntity.class);
     ArrayList<String> fields = new ArrayList<String>();
     fields.add("userName");
     aggregate.count(fields, null, new KinveyClientCallback<EventEntity>() {
         public void onSuccess(EventEntity event) { ... 
         public void onFailure(Throwable T) {...}
     });
 }
 

Parameters
fields ArrayList of fields to aggregate on
query Optional query object for filtering results to aggregate on. Set to null for entire collection.
callback KinveyClientCallback

public void delete (String entityID, KinveyDeleteCallback callback)

Asynchronous request to delete an entity to a collection.

Creates an asynchronous request to delete a group of entities from a collection based on a Query object. Uses KinveyDeleteCallback to return a KinveyDeleteResponse. Queries can be constructed with Query. An empty Query object will delete all items in the collection.

Sample Usage:

 AppData<EventEntity> myAppData = kinveyClient.appData("myCollection", EventEntity.class);
     myAppData.delete(myQuery, new KinveyDeleteCallback {
         public void onFailure(Throwable t) { ... 
         public void onSuccess(EventEntity[] entities) { ... }
     });
 }
 

Parameters
entityID the ID to delete
callback KinveyDeleteCallback

public void delete (Query query, KinveyDeleteCallback callback)

Asynchronous request to delete a collection of entites from a collection by Query.

Creates an asynchronous request to delete an entity from a collection by Entity ID. Uses KinveyDeleteCallback to return a KinveyDeleteResponse.

Sample Usage:

 AppData<EventEntity> myAppData = kinveyClient.appData("myCollection", EventEntity.class);
     Query myQuery = new Query();
     myQuery.equals("age",21);
     myAppData.delete(myQuery, new KinveyDeleteCallback {
         public void onFailure(Throwable t) { ... 
         public void onSuccess(EventEntity[] entities) { ... }
     });
 }
 

Parameters
query Query to filter the results.
callback KinveyDeleteCallback

public void get (String[] ids, KinveyListCallback<T> callback)

Asynchronous request to fetch an array of Entities using an array of _ids.

Constructs an asynchronous request to fetch an Array of Entities, filtering by the provided list of _ids. Uses KinveyListCallback to return an Array of type T. This method uses a Query Query.

Sample Usage:

 AppData<EventEntity> myAppData = kinveyClient.appData("myCollection", EventEntity.class);
     myAppData.get(new String[]{"189472023", "10193583", new KinveyListCallback {
         public void onFailure(Throwable t) { ... }
         public void onSuccess(EventEntity[] entities) { ... }
     });
 }
 

Parameters
ids A list of _ids to query by.
callback either successfully returns list of resolved entities or an error

public void get (KinveyListCallback<T> callback)

Asynchronous request to fetch an array of all Entities in a collection.

Constructs an asynchronous request to fetch an Array of all entities in a collection. Uses KinveyListCallback to return an Array of type T.

Sample Usage:

 AppData<EventEntity> myAppData = kinveyClient.appData("myCollection", EventEntity.class);
     myAppData.get(new KinveyListCallback<EventEntity> {
         public void onFailure(Throwable t) { ... 
         public void onSuccess(EventEntity[] entities) { ... }
     });
 }
 

Parameters
callback either successfully returns list of resolved entities or an error

public void get (Query query, KinveyListCallback<T> callback)

Asynchronous request to fetch an array of Entities using a Query object.

Constructs an asynchronous request to fetch an Array of Entities, filtering by a Query object. Uses KinveyListCallback to return an Array of type T. Queries can be constructed with Query. An empty Query object will return all items in the collection.

Sample Usage:

 AppData<EventEntity> myAppData = kinveyClient.appData("myCollection", EventEntity.class);
     Query myQuery = new Query();
     myQuery.equals("age",21);
     myAppData.get(myQuery, new KinveyListCallback<EventEntity> {
         public void onFailure(Throwable t) { ... 
         public void onSuccess(EventEntity[] entities) { ... }
     });
 }
 

Parameters
query Query to filter the results.
callback either successfully returns list of resolved entities or an error

public void get (Query q, String[] resolves, KinveyListCallback<T> callback)

Asynchronous request to execute a query and resolve KinveyReferences. The Query will be used to determine which entities to retrieve, and the resolves array defines which json keys are KinveyReferences that should be resolved.

Sample Usage:

 Query q = new Query();
     q.equals("displayName", "myDisplayName");
     AppData<EventEntity> myAppData = kinveyClient.appData("myCollection", EventEntity.class);
     myAppData.get(q, new String[]{"myReferencedField", new KinveyListCallback {
         public void onFailure(Throwable t) { ... }
         public void onSuccess(EventEntity[] entities) { ... }
     });
 }
 

Parameters
q - the Query to execute determining which entities to retrieve.
resolves - an array of json keys maintaining KinveyReferences to be resolved
callback - results of execution, either success or failure

public void getEntity (String id, String[] resolves, KinveyClientCallback<T> callback)

Asynchronous request to fetch a single entity by _id and resolve KinveyReferences. The resolves array defines which json keys are KinveyReferences that should be resolved.

Sample Usage:

 {@code
     AppData<EventEntity> myAppData = kinveyClient.appData("myCollection", EventEntity.class);
     myAppData.get(myEntityID, new String[]{"ReferencedField", new KinveyListCallback {
         public void onFailure(Throwable t) { ... }
         public void onSuccess(EventEntity[] entities) { ... }
     });
 }
 

Parameters
id - the _id of the entity to retrieve
resolves - an array of json keys maintaining KinveyReferences to be resolved
callback - results of execution, either success or failure

public void getEntity (String entityID, KinveyClientCallback<T> callback)

Asynchronous request to fetch a single Entity by ID.

Constructs an asynchronous request to fetch a single Entity by its Entity ID. Returns an instance of that Entity via KinveyClientCallback

Sample Usage:

 AppData<EventEntity> myAppData = kinveyClient.appData("myCollection", EventEntity.class).get("123",
             new KinveyClientCallback<EventEntity> {
         public void onFailure(Throwable t) { ... 
         public void onSuccess(EventEntity entity) { ... }
     });
 }
 

Parameters
entityID entityID to fetch
callback either successfully returns list of resolved entities or an error

public boolean isOnline ()

Method to check if the current runtime environment has an active connection to the internet, this implementation is tightly coupled with the Android Operating System

Returns
  • true if the device is connected or connecting

public void max (ArrayList<String> fields, String maxField, Query query, KinveyClientCallback callback)

Asynchronous request to retrieve a group by MAX on a collection or filtered collection

Generates an asynchronous request to group a collection and provide the max value of records based on a field or groups of fields. The aggregate will reduce an entire collection, or a collection filtered by a Query

Sample Usage:

 AppData<GenericJson> aggregate = kinveyClient.appData("events", EventEntity.class");
     ArrayList<String> fields = new ArrayList<String>();
     fields.add("userName");
     aggregate.max(fields, "orderTotal", null, new KinveyClientCallback<EventEntity>() {
         public void onSuccess(EventEntity event) { ... 
         public void onFailure(Throwable T) {...}
     });
 }
 

Parameters
fields ArrayList of fields to aggregate on
maxField Field to get the max value from
query Optional query object for filtering results to aggregate on. Set to null for entire collection.
callback KinveyClientCallback

public void min (ArrayList<String> fields, String minField, Query query, KinveyClientCallback callback)

Asynchronous request to retrieve a group by MIN on a collection or filtered collection

Generates an asynchronous request to group a collection and provide the min value of records based on a field or groups of fields. The aggregate will reduce an entire collection, or a collection filtered by a Query

Sample Usage:

 AppData<GenericJson> aggregate = kinveyClient.appData("events", EventEntity.class");
     ArrayList<String> fields = new ArrayList<String>();
     fields.add("userName");
     aggregate.min(fields, "orderTotal", null, new KinveyClientCallback<EventEntity>() {
         public void onSuccess(EventEntity event) { ... 
         public void onFailure(Throwable T) {...}
     });
 }
 

Parameters
fields ArrayList of fields to aggregate on
minField Field to get the min value from
query Optional query object for filtering results to aggregate on. Set to null for entire collection.
callback KinveyClientCallback

public void save (T entity, KinveyClientCallback<T> callback)

Asynchronous request to save or update an entity to a collection.

Constructs an asynchronous request to save an entity of type T to a collection. Creates the entity if it doesn't exist, updates it if it does exist. If an "_id" property is not present, the Kinvey backend will generate one.

Sample Usage:

 AppData<EventEntity> myAppData = kinveyClient.appData("myCollection", EventEntity.class);
     myAppData.save(entityID, new KinveyClientCallback<EventEntity> {
         public void onFailure(Throwable t) { ... 
         public void onSuccess(EventEntity[] entities) { ... }
     });
 }
 

Parameters
entity The entity to save
callback KinveyClientCallback

public void setOffline (OfflinePolicy policy, OfflineStore store)

Set an OfflinePolicy on AppData, allowing requests to be executed locally

Sample Usage:

 {@code
     AsyncAppData offline = kinveyClient.appData("events", EventEntity.class);
     offline.setOffline(OfflinePolicy.ALWAYS_ONLINE, new SqlLiteOfflineStore(getContext()));
 

Parameters
policy the policy defining behavior of offline sync
store the type of store to be used, commonly SqlLiteOfflineStore

public void sum (ArrayList<String> fields, String sumField, Query query, KinveyClientCallback callback)

Asynchronous request to retrieveBlocking a group by SUM on a collection or filtered collection

Generates an asynchronous request to group a collection and provide a sumBlocking of records based on a field or groups of fields. The aggregate will reduce an entire collection, or a collection filtered by a Query

Sample Usage:

 AppData<GenericJson> aggregate = kinveyClient.appData("events", EventEntity.class");
     ArrayList<String> fields = new ArrayList<String>();
     fields.add("userName");
     aggregate.sumBlocking(fields, "orderTotal", null, new KinveyClientCallback<EventEntity>() {
         public void onSuccess(EventEntity event) { ... 
         public void onFailure(Throwable T) {...}
     });
 }
 

Parameters
fields ArrayList of fields to aggregate on
sumField Field to sumBlocking
query Optional query object for filtering results to aggregate on. Set to null for entire collection.
callback KinveyClientCallback