API Reference

com.kinvey.android.store

Class DataStore<T extends GenericJson>

  • com.kinvey.android.store.DataStore<T>
  • Direct Known Subclasses:
    LinkedDataStore


    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":

    See Also:
    class DataStore
    • Constructor Summary

      Constructors 
      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.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method and Description
      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) 
      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.
    • Constructor Detail

      • DataStore

        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.

        Parameters:
        collectionName - Name of the appData collection
        myClass - Class Type to marshall data between
        isDeltaSetCachingEnabled - Delta Cache switcher
        client - Kinvey client
        storeType - storeType.
      • DataStore

        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.

        Parameters:
        collectionName - Name of the appData collection
        myClass - Class Type to marshall data between
        client - Kinvey client
        storeType - StoreType parameter
        networkManager - NetworkManager object.
    • Method Detail

      • find

        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:

        Parameters:
        entityID - entityID to fetch
        callback - either successfully returns list of resolved entities or an error
        cachedCallback - either successfully returns list of resolved entities from cache or an error
      • find

        public 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:

        Parameters:
        entityID - entityID to fetch
        callback - either successfully returns list of resolved entities or an error
      • find

        public 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:

        Parameters:
        ids - A list of _ids to query by.
        callback - either successfully returns list of resolved entities or an error
        cachedCallback - either successfully returns list of resolved entities from cache or an error
      • find

        public 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:

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

        public 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:

        Parameters:
        query - Query to filter the results.
        callback - either successfully returns list of resolved entities or an error
        cachedCallback - either successfully returns list of resolved entities from cache or an error
      • find

        public 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:

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

        public 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. *

        Parameters:
        query - Query to filter the results.
        callback - either successfully returns list of resolved entities, count of all items or an error
      • find

        public 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:

        Parameters:
        callback - either successfully returns list of resolved entities or an error
        cachedCallback - either successfully returns list of resolved entities from cache or an error
      • find

        public 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:

        Parameters:
        callback - either successfully returns list of resolved entities or an error
      • count

        public void count(KinveyCountCallback callback)

        Get items count in collection

        Parameters:
        callback - return items count in collection
      • count

        public void count(KinveyCountCallback callback,
                          com.kinvey.java.cache.KinveyCachedClientCallback<java.lang.Integer> cachedCallback)

        Get items count in collection

        Parameters:
        callback - return items count in collection
        cachedCallback - is using with StoreType.CACHE to get items count in collection
      • save

        public 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:

        Parameters:
        entity - The entity to save
        callback - KinveyClientCallback
      • create

        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:

        Parameters:
        entities - The list of entities to create
        callback - KinveyClientCallback
      • create

        public 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:

        Parameters:
        entity - The entity to create
        callback - KinveyClientCallback
      • save

        public void save(java.util.List<? extends T> entities,
                         com.kinvey.java.core.KinveyClientCallback<java.util.List> callback)
        Deprecated. 

        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:

        Parameters:
        entities - The list of entities to save
        callback - KinveyClientCallback>
      • delete

        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:

        Parameters:
        entityID - the ID to delete
        callback - KinveyDeleteCallback
      • delete

        public 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:

        Parameters:
        entityIDs - the ID to delete
        callback - KinveyDeleteCallback
      • delete

        public 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:

        Parameters:
        query - Query to filter the results.
        callback - KinveyDeleteCallback
      • push

        public 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:

        Parameters:
        callback - KinveyPushCallback
        See Also:
        class KinveyPushResponse
      • pull

        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:

        Parameters:
        callback - KinveyPullCallback
      • pull

        public 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:

        Parameters:
        query - Query to filter the results.
        isAutoPagination - true if auto-pagination is used
        callback - KinveyPullCallback
      • pull

        public 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:

        Parameters:
        pageSize - Page size for auto-pagination
        callback - KinveyPullCallback
      • pull

        public 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:

        Parameters:
        isAutoPagination - true if auto-pagination is used
        callback - KinveyPullCallback
      • pull

        public 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:

        Parameters:
        query - Query to filter the results.
        pageSize - Page size for auto-pagination
        callback - KinveyPullCallback
      • pull

        public 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:

        Parameters:
        query - Query to filter the results.
        callback - KinveyPullCallback
      • purge

        public 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:

        Parameters:
        callback - KinveyPurgeCallback
        See Also:
        interface KinveyPurgeCallback
      • purge

        public void purge(com.kinvey.java.Query query,
                          KinveyPurgeCallback callback)

        Asynchronous request to clear all the pending requests from the sync storage by query.

        Parameters:
        query - query to filter pending requests for deleting
        callback - KinveyPurgeCallback
      • sync

        public 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:

        Parameters:
        query - Query to filter the results or null if you don't want to query.
        callback - KinveyDeleteCallback
        See Also:
        interface KinveySyncCallback
      • sync

        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:

        Parameters:
        query - Query to filter the results or null if you don't want to query.
        callback - KinveyDeleteCallback
        See Also:
        interface KinveySyncCallback
      • sync

        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:

        Parameters:
        query - Query to filter the results or null if you don't want to query.
        pageSize - Page size for auto-pagination
        callback - KinveyDeleteCallback
        See Also:
        interface KinveySyncCallback
      • sync

        public void sync(KinveySyncCallback callback)

        Alias for .sync where query equals null

        Parameters:
        callback - callback to notify working thread on operation status update
        See Also:
        .sync
      • sync

        public void sync(int pageSize,
                         KinveySyncCallback callback)

        Alias for .sync where query equals null

        Parameters:
        pageSize - Page size for auto-pagination
        callback - callback to notify working thread on operation status update
        See Also:
        .sync
      • query

        public com.kinvey.java.Query query()
      • syncCount

        public long syncCount()

        This methods gets a count of entities modified locally and pending a push to the backend

        Returns:
        the count of sync objects for given collection
      • group

        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.

        Parameters:
        aggregateType - AggregateType (such as min, max, sum, count, average)
        fields - fields for group by
        reduceField - field for apply reduce function
        query - query to filter results
      • subscribe

        public void subscribe(com.kinvey.java.store.KinveyDataStoreLiveServiceCallback<T> storeLiveServiceCallback,
                              com.kinvey.java.core.KinveyClientCallback<java.lang.Boolean> callback)

        Subscribe the specified callback.

        Parameters:
        storeLiveServiceCallback - KinveyDataStoreLiveServiceCallback
        callback -
      • unsubscribe

        public void unsubscribe(com.kinvey.java.core.KinveyClientCallback<java.lang.Void> callback)

        Unsubscribe this instance.

        Parameters:
        callback -
      • collection

        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)