public class DataStore<T extends GenericJson>
Wraps the BaseDataStore public methods in asynchronous functionality using native Android AsyncTask.
This functionality can be accessed through the class DataStore
convenience method. BaseDataStore
gets and saves and sync 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":
class DataStore
Modifier and Type | Class and Description |
---|---|
static class |
DataStore.Companion |
static class |
DataStore.CreateListBatchRequest<T extends GenericJson> |
static class |
DataStore.SaveListBatchRequest<T extends GenericJson> |
static class |
DataStore.SaveListRequest<T extends GenericJson> |
static class |
DataStore.SaveRequest<T extends GenericJson> |
Modifier and Type | Field and Description |
---|---|
static DataStore.Companion |
Companion |
Constructor and Description |
---|
DataStore(java.lang.String collectionName,
java.lang.Class<T> myClass,
boolean isDeltaSetCachingEnabled,
com.kinvey.java.AbstractClient<?> client,
com.kinvey.java.store.StoreType storeType)
Constructor to instantiate the DataStore class.
|
DataStore(java.lang.String collectionName,
java.lang.Class<T> myClass,
com.kinvey.java.AbstractClient<?> client,
com.kinvey.java.store.StoreType storeType,
com.kinvey.java.network.NetworkManager<T> networkManager)
Constructor to instantiate the DataStore class.
|
Modifier and Type | Method and Description |
---|---|
static <T extends GenericJson,C extends AbstractClient<?>> |
collection(java.lang.String collectionName,
java.lang.Class<T> myClass,
com.kinvey.java.store.StoreType storeType,
C client) |
void |
count(KinveyCountCallback callback)
Get items count in collection
|
void |
count(KinveyCountCallback callback,
com.kinvey.java.cache.KinveyCachedClientCallback<java.lang.Integer> cachedCallback)
Get items count in collection
|
void |
create(java.util.List<? extends T> entities,
com.kinvey.java.core.KinveyClientCallback<com.kinvey.java.model.KinveySaveBatchResponse> callback)
Asynchronous request to create an list of entities to a collection.
|
void |
create(T entity,
com.kinvey.java.core.KinveyClientCallback<T> callback)
Asynchronous request to create an entity to a collection.
|
void |
delete(java.lang.String entityID,
KinveyDeleteCallback callback)
Asynchronous request to delete an entity to a collection.
|
void |
delete(java.lang.Iterable<java.lang.String> entityIDs,
KinveyDeleteCallback callback)
Asynchronous request to delete an entities from a collection.
|
void |
delete(com.kinvey.java.Query query,
KinveyDeleteCallback callback)
Asynchronous request to delete a collection of entities from a collection by Query.
|
void |
find(java.lang.String entityID,
com.kinvey.java.core.KinveyClientCallback<T> callback,
com.kinvey.java.cache.KinveyCachedClientCallback<T> cachedCallback)
Asynchronous request to fetch a single Entity by ID with additional callback with data from cache.
|
void |
find(java.lang.String entityID,
com.kinvey.java.core.KinveyClientCallback<T> callback)
Asynchronous request to fetch a single Entity by ID with additional callback with data from cache.
|
void |
find(java.lang.Iterable<java.lang.String> ids,
KinveyReadCallback<T> callback,
com.kinvey.java.cache.KinveyCachedClientCallback<com.kinvey.java.model.KinveyReadResponse> cachedCallback)
Asynchronous request to fetch an list of Entities using an list of _ids.
|
void |
find(java.lang.Iterable<java.lang.String> ids,
KinveyReadCallback<T> callback)
Asynchronous request to fetch an list of Entities using an list of _ids.
|
void |
find(com.kinvey.java.Query query,
KinveyReadCallback<T> callback,
com.kinvey.java.cache.KinveyCachedClientCallback<com.kinvey.java.model.KinveyReadResponse> cachedCallback)
Asynchronous request to fetch an list of Entities using a Query object.
|
void |
find(com.kinvey.java.Query query,
KinveyReadCallback<T> callback)
Asynchronous request to fetch an list of Entities using a Query object.
|
void |
find(KinveyReadCallback<T> callback,
com.kinvey.java.cache.KinveyCachedClientCallback<com.kinvey.java.model.KinveyReadResponse> cachedCallback)
Asynchronous request to fetch an list of all Entities in a collection.
|
void |
find(KinveyReadCallback<T> callback)
Asynchronous request to fetch an list of all Entities in a collection.
|
void |
findWithCount(com.kinvey.java.Query query,
KinveyReadCallback<T> callback)
Asynchronous request to fetch an list of Entities using a Query object with getting count of all items in collection.
|
void |
group(com.kinvey.java.model.AggregateType aggregateType,
java.util.ArrayList<java.lang.String> fields,
java.lang.String reduceField,
com.kinvey.java.Query query,
com.kinvey.java.core.KinveyAggregateCallback callback,
com.kinvey.java.core.KinveyCachedAggregateCallback cachedCallback)
Asynchronous request to collect all entities with the same value for fields,
and then apply a reduce function (such as count or average) on all those items.
|
void |
pull(KinveyPullCallback callback)
Asynchronous request to pull a collection of entities from backend.
|
void |
pull(com.kinvey.java.Query query,
boolean isAutoPagination,
KinveyPullCallback callback)
Asynchronous request to pull a collection of entities from backend using auto-pagination.
|
void |
pull(int pageSize,
KinveyPullCallback callback)
Asynchronous request to pull a collection of entities from backend.
|
void |
pull(boolean isAutoPagination,
KinveyPullCallback callback)
Asynchronous request to pull a collection of entities from backend.
|
void |
pull(com.kinvey.java.Query query,
int pageSize,
KinveyPullCallback callback)
Asynchronous request to pull a collection of entities from backend using auto-pagination.
|
void |
pull(com.kinvey.java.Query query,
KinveyPullCallback callback)
Asynchronous request to pull a collection of entities from backend.
|
void |
purge(KinveyPurgeCallback callback)
Asynchronous request to clear all the pending requests from the sync storage
|
void |
purge(com.kinvey.java.Query query,
KinveyPurgeCallback callback)
Asynchronous request to clear all the pending requests from the sync storage by query.
|
void |
push(KinveyPushCallback callback)
Asynchronous request to push a collection of entities to backend.
|
com.kinvey.java.Query |
query() |
void |
save(T entity,
com.kinvey.java.core.KinveyClientCallback<T> callback)
Asynchronous request to save or update an entity to a collection.
|
void |
save(java.util.List<? extends T> entities,
com.kinvey.java.core.KinveyClientCallback<java.util.List> callback)
Deprecated.
|
void |
subscribe(com.kinvey.java.store.KinveyDataStoreLiveServiceCallback<T> storeLiveServiceCallback,
com.kinvey.java.core.KinveyClientCallback<java.lang.Boolean> callback)
Subscribe the specified callback.
|
void |
sync(com.kinvey.java.Query query,
KinveySyncCallback callback)
Asynchronous request to sync a collection of entities from a network collection by Query.
|
void |
sync(com.kinvey.java.Query query,
boolean isAutoPagination,
KinveySyncCallback callback)
Asynchronous request to sync a collection of entities from a network collection by Query.
|
void |
sync(com.kinvey.java.Query query,
int pageSize,
KinveySyncCallback callback)
Asynchronous request to sync a collection of entities from a network collection by Query.
|
void |
sync(KinveySyncCallback callback)
Alias for .sync where query equals null
|
void |
sync(int pageSize,
KinveySyncCallback callback)
Alias for .sync where query equals null
|
long |
syncCount()
This methods gets a count of entities modified locally and pending a push to the backend
|
void |
unsubscribe(com.kinvey.java.core.KinveyClientCallback<java.lang.Void> callback)
Unsubscribe this instance.
|
public static DataStore.Companion Companion
public DataStore(java.lang.String collectionName, java.lang.Class<T> myClass, boolean isDeltaSetCachingEnabled, com.kinvey.java.AbstractClient<?> client, com.kinvey.java.store.StoreType storeType)
Constructor to instantiate the DataStore class.
collectionName
- Name of the appData collectionmyClass
- Class Type to marshall data betweenisDeltaSetCachingEnabled
- Delta Cache switcherclient
- Kinvey clientstoreType
- storeType.public DataStore(java.lang.String collectionName, java.lang.Class<T> myClass, com.kinvey.java.AbstractClient<?> client, com.kinvey.java.store.StoreType storeType, com.kinvey.java.network.NetworkManager<T> networkManager)
Constructor to instantiate the DataStore class.
collectionName
- Name of the appData collectionmyClass
- Class Type to marshall data betweenclient
- Kinvey clientstoreType
- StoreType parameternetworkManager
- NetworkManager object.public void find(java.lang.String entityID, com.kinvey.java.core.KinveyClientCallback<T> callback, com.kinvey.java.cache.KinveyCachedClientCallback<T> cachedCallback)
Asynchronous request to fetch a single Entity by ID with additional callback with data from cache.
Constructs an asynchronous request to fetch a single Entity by its Entity ID. Returns an instance of that Entity via KinveyClientCallback *
Sample Usage:
entityID
- entityID to fetchcallback
- either successfully returns list of resolved entities or an errorcachedCallback
- either successfully returns list of resolved entities from cache or an errorpublic void find(java.lang.String entityID, com.kinvey.java.core.KinveyClientCallback<T> callback)
Asynchronous request to fetch a single Entity by ID with additional callback with data from cache.
Constructs an asynchronous request to fetch a single Entity by its Entity ID. Returns an instance of that Entity via KinveyClientCallback *
Sample Usage:
entityID
- entityID to fetchcallback
- either successfully returns list of resolved entities or an errorpublic void find(java.lang.Iterable<java.lang.String> ids, KinveyReadCallback<T> callback, com.kinvey.java.cache.KinveyCachedClientCallback<com.kinvey.java.model.KinveyReadResponse> cachedCallback)
Asynchronous request to fetch an list of Entities using an list of _ids.
Constructs an asynchronous request to fetch an List of Entities, filtering by the provided list of _ids. Uses KinveyReadCallback to return an List of type T. This method uses a Query Query. *
Sample Usage:
ids
- A list of _ids to query by.callback
- either successfully returns list of resolved entities or an errorcachedCallback
- either successfully returns list of resolved entities from cache or an errorpublic void find(java.lang.Iterable<java.lang.String> ids, KinveyReadCallback<T> callback)
Asynchronous request to fetch an list of Entities using an list of _ids.
Constructs an asynchronous request to fetch an List of Entities, filtering by the provided list of _ids. Uses KinveyReadCallback to return an List of type T. This method uses a Query Query. *
Sample Usage:
ids
- A list of _ids to query by.callback
- either successfully returns list of resolved entities or an errorpublic void find(com.kinvey.java.Query query, KinveyReadCallback<T> callback, com.kinvey.java.cache.KinveyCachedClientCallback<com.kinvey.java.model.KinveyReadResponse> cachedCallback)
Asynchronous request to fetch an list of Entities using a Query object.
Constructs an asynchronous request to fetch an List of Entities, filtering by a Query object. Uses KinveyReadCallback to return an List of type T. Queries can be constructed with Query. An empty Query object will return all items in the collection. *
Sample Usage:
query
- Query to filter the results.callback
- either successfully returns list of resolved entities or an errorcachedCallback
- either successfully returns list of resolved entities from cache or an errorpublic void find(com.kinvey.java.Query query, KinveyReadCallback<T> callback)
Asynchronous request to fetch an list of Entities using a Query object.
Constructs an asynchronous request to fetch an List of Entities, filtering by a Query object. Uses KinveyReadCallback to return an List of type T. Queries can be constructed with Query. An empty Query object will return all items in the collection. *
Sample Usage:
query
- Query to filter the results.callback
- either successfully returns list of resolved entities or an errorpublic void findWithCount(com.kinvey.java.Query query, KinveyReadCallback<T> callback)
Asynchronous request to fetch an list of Entities using a Query object with getting count of all items in collection.
Constructs an asynchronous request to fetch an List of Entities, filtering by a Query object with getting count of all items in collection. Uses KinveyReadCallback to return an List of type T, count of all items which contains in collection for the query. Queries can be constructed with Query. An empty Query object will return all items in the collection. *
query
- Query to filter the results.callback
- either successfully returns list of resolved entities, count of all items or an errorpublic void find(KinveyReadCallback<T> callback, com.kinvey.java.cache.KinveyCachedClientCallback<com.kinvey.java.model.KinveyReadResponse> cachedCallback)
Asynchronous request to fetch an list of all Entities in a collection.
Constructs an asynchronous request to fetch an List of all entities in a collection. Uses KinveyReadCallback to return an List of type T. *
Sample Usage:
callback
- either successfully returns list of resolved entities or an errorcachedCallback
- either successfully returns list of resolved entities from cache or an errorpublic void find(KinveyReadCallback<T> callback)
Asynchronous request to fetch an list of all Entities in a collection.
Constructs an asynchronous request to fetch an List of all entities in a collection. Uses KinveyReadCallback to return an List of type T. *
Sample Usage:
callback
- either successfully returns list of resolved entities or an errorpublic void count(KinveyCountCallback callback)
Get items count in collection
callback
- return items count in collectionpublic void count(KinveyCountCallback callback, com.kinvey.java.cache.KinveyCachedClientCallback<java.lang.Integer> cachedCallback)
Get items count in collection
callback
- return items count in collectioncachedCallback
- is using with StoreType.CACHE to get items count in collectionpublic void save(T entity, com.kinvey.java.core.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:
entity
- The entity to savecallback
- KinveyClientCallback
public void create(java.util.List<? extends T> entities, com.kinvey.java.core.KinveyClientCallback<com.kinvey.java.model.KinveySaveBatchResponse> callback)
Asynchronous request to create an list of entities to a collection.
Constructs an asynchronous request to save a list of entities to a collection. Creates the entity if it doesn't exist, return error in error list of response for entity if it does exist. If an "_id" property is not present, the Kinvey backend will generate one. *
Sample Usage:
entities
- The list of entities to createcallback
- KinveyClientCallbackpublic void create(T entity, com.kinvey.java.core.KinveyClientCallback<T> callback)
Asynchronous request to create an entity to a collection.
Constructs an asynchronous request to create an entity to a collection. Creates the entity if it doesn't exist, return error for entity if it does exist. If an "_id" property is not present, the Kinvey backend will generate one. *
Sample Usage:
entity
- The entity to createcallback
- KinveyClientCallback
public void save(java.util.List<? extends T> entities, com.kinvey.java.core.KinveyClientCallback<java.util.List> callback)
Asynchronous request to save or update an list of entities to a collection.
Constructs an asynchronous request to save a list of entities 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:
entities
- The list of entities to savecallback
- KinveyClientCallback>
public void delete(java.lang.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 com.kinvey.java.model.KinveyDeleteResponse. Queries can be constructed with Query. An empty Query object will delete all items in the collection.
Sample Usage:
entityID
- the ID to deletecallback
- KinveyDeleteCallbackpublic void delete(java.lang.Iterable<java.lang.String> entityIDs, KinveyDeleteCallback callback)
Asynchronous request to delete an entities from a collection.
Creates an asynchronous request to delete a group of entities from a collection based on a passed entities ids. Uses KinveyDeleteCallback to return a com.kinvey.java.model.KinveyDeleteResponse.
Sample Usage:
entityIDs
- the ID to deletecallback
- KinveyDeleteCallbackpublic void delete(com.kinvey.java.Query query, KinveyDeleteCallback callback)
Asynchronous request to delete a collection of entities from a collection by Query.
Creates an asynchronous request to delete an entity from a collection by Entity ID. Uses KinveyDeleteCallback to return a com.kinvey.java.model.KinveyDeleteResponse.
Sample Usage:
query
- Query to filter the results.callback
- KinveyDeleteCallbackpublic void push(KinveyPushCallback callback)
Asynchronous request to push a collection of entities to backend.
Creates an asynchronous request to push a collection of entities. Uses KinveyPushCallback to return a
class KinveyPushResponse
.
Sample Usage:
callback
- KinveyPushCallbackclass KinveyPushResponse
public void pull(KinveyPullCallback callback)
Asynchronous request to pull a collection of entities from backend.
Creates an asynchronous request to pull an entity from backend. Uses KinveyPullCallback to return a KinveyPullResponse.
Sample Usage:
callback
- KinveyPullCallbackpublic void pull(com.kinvey.java.Query query, boolean isAutoPagination, KinveyPullCallback callback)
Asynchronous request to pull a collection of entities from backend using auto-pagination.
Creates an asynchronous request to pull an entity from backend. Uses KinveyPullCallback to return a KinveyPullResponse.
Sample Usage:
query
- Query to filter the results.isAutoPagination
- true if auto-pagination is usedcallback
- KinveyPullCallbackpublic void pull(int pageSize, KinveyPullCallback callback)
Asynchronous request to pull a collection of entities from backend.
Creates an asynchronous request to pull all entity from backend. Uses KinveyPullCallback to return a KinveyPullResponse.
Sample Usage:
pageSize
- Page size for auto-paginationcallback
- KinveyPullCallbackpublic void pull(boolean isAutoPagination, KinveyPullCallback callback)
Asynchronous request to pull a collection of entities from backend.
Creates an asynchronous request to pull all entity from backend. Uses KinveyPullCallback to return a KinveyPullResponse.
Sample Usage:
isAutoPagination
- true if auto-pagination is usedcallback
- KinveyPullCallbackpublic void pull(com.kinvey.java.Query query, int pageSize, KinveyPullCallback callback)
Asynchronous request to pull a collection of entities from backend using auto-pagination.
Creates an asynchronous request to pull an entity from backend. Uses KinveyPullCallback to return a KinveyPullResponse. *
Sample Usage:
query
- Query to filter the results.pageSize
- Page size for auto-paginationcallback
- KinveyPullCallbackpublic void pull(com.kinvey.java.Query query, KinveyPullCallback callback)
Asynchronous request to pull a collection of entities from backend.
Creates an asynchronous request to pull an entity from backend. Uses KinveyPullCallback to return a KinveyPullResponse. *
Sample Usage:
query
- Query to filter the results.callback
- KinveyPullCallbackpublic void purge(KinveyPurgeCallback callback)
Asynchronous request to clear all the pending requests from the sync storage
Creates an asynchronous request to clear all the pending requests from the sync storage.
Uses KinveyPullCallback to return a interface KinveyPurgeCallback
.
Sample Usage:
callback
- KinveyPurgeCallbackinterface KinveyPurgeCallback
public void purge(com.kinvey.java.Query query, KinveyPurgeCallback callback)
Asynchronous request to clear all the pending requests from the sync storage by query.
query
- query to filter pending requests for deletingcallback
- KinveyPurgeCallbackpublic void sync(com.kinvey.java.Query query, KinveySyncCallback callback)
Asynchronous request to sync a collection of entities from a network collection by Query.
Creates an asynchronous request to sync local entities and network entries matched query from
a given collection by Query. Uses KinveySyncCallback to return a
interface KinveySyncCallback
.
Sample Usage:
query
- Query to filter the results or null if you don't want to query.callback
- KinveyDeleteCallbackinterface KinveySyncCallback
public void sync(com.kinvey.java.Query query, boolean isAutoPagination, KinveySyncCallback callback)
Asynchronous request to sync a collection of entities from a network collection by Query.
Creates an asynchronous request to sync local entities and network entries matched query from
a given collection by Query. Uses KinveySyncCallback to return a
interface KinveySyncCallback
.
Sample Usage:
query
- Query to filter the results or null if you don't want to query.callback
- KinveyDeleteCallbackinterface KinveySyncCallback
public void sync(com.kinvey.java.Query query, int pageSize, KinveySyncCallback callback)
Asynchronous request to sync a collection of entities from a network collection by Query.
Creates an asynchronous request to sync local entities and network entries matched query from
a given collection by Query. Uses KinveySyncCallback to return a
interface KinveySyncCallback
.
Sample Usage:
query
- Query to filter the results or null if you don't want to query.pageSize
- Page size for auto-paginationcallback
- KinveyDeleteCallbackinterface KinveySyncCallback
public void sync(KinveySyncCallback callback)
Alias for .sync where query equals null
callback
- callback to notify working thread on operation status updatepublic void sync(int pageSize, KinveySyncCallback callback)
Alias for .sync where query equals null
pageSize
- Page size for auto-paginationcallback
- callback to notify working thread on operation status updatepublic com.kinvey.java.Query query()
public long syncCount()
This methods gets a count of entities modified locally and pending a push to the backend
public void group(com.kinvey.java.model.AggregateType aggregateType, java.util.ArrayList<java.lang.String> fields, java.lang.String reduceField, com.kinvey.java.Query query, com.kinvey.java.core.KinveyAggregateCallback callback, com.kinvey.java.core.KinveyCachedAggregateCallback cachedCallback)
Asynchronous request to collect all entities with the same value for fields, and then apply a reduce function (such as count or average) on all those items.
aggregateType
- AggregateType (such as min, max, sum, count, average)fields
- fields for group byreduceField
- field for apply reduce functionquery
- query to filter resultspublic void subscribe(com.kinvey.java.store.KinveyDataStoreLiveServiceCallback<T> storeLiveServiceCallback, com.kinvey.java.core.KinveyClientCallback<java.lang.Boolean> callback)
Subscribe the specified callback.
storeLiveServiceCallback
- KinveyDataStoreLiveServiceCallbackcallback
- public void unsubscribe(com.kinvey.java.core.KinveyClientCallback<java.lang.Void> callback)
Unsubscribe this instance.
callback
- public static <T extends GenericJson,C extends AbstractClient<?>> DataStore<T> collection(java.lang.String collectionName, java.lang.Class<T> myClass, com.kinvey.java.store.StoreType storeType, C client)