com.stackmob.sdk.api
Class StackMobDatastore

java.lang.Object
  extended by com.stackmob.sdk.api.StackMobDatastore

public class StackMobDatastore
extends Object

Make calls to StackMob's API directly. This class lets you call CRUD methods, as well as talk to any custom APIs you have.


Constructor Summary
StackMobDatastore(ExecutorService executor, StackMobSession session, String host, StackMobRedirectedCallback redirectedCallback)
           
 
Method Summary
 void count(StackMobQuery query, StackMobRawCallback callback)
          retrieve the number of objects for a query on the StackMob platform
 void count(String path, StackMobRawCallback callback)
          retrieve the number of objects for a schema on the StackMob platform
 void delete(String path, String id, StackMobRawCallback callback)
          do a DELETE request to the StackMob platform
<T> void
deleteIdFrom(String path, String primaryId, String field, T idToDelete, boolean cascadeDelete, StackMobRawCallback callback)
          atomically remove elements from an array or has many relationship
<T> void
deleteIdsFrom(String path, String primaryId, String field, List<T> idsToDelete, boolean cascadeDeletes, StackMobRawCallback callback)
          atomically remove elements from an array or has many relationship
 void get(StackMobQuery query, StackMobOptions options, StackMobRawCallback callback)
          do a get request on the StackMob platform
 void get(StackMobQuery query, StackMobRawCallback callback)
          do a get request on the StackMob platform
 void get(String path, StackMobOptions options, StackMobRawCallback callback)
          do a get request on the StackMob platform
 void get(String path, StackMobRawCallback callback)
          do a get request on the StackMob platform
 void post(String path, Object requestObject, StackMobOptions options, StackMobRawCallback callback)
          do a post request on the StackMob platform for a single object
 void post(String path, Object requestObject, StackMobRawCallback callback)
          do a post request on the StackMob platform for a single object
 void post(String path, String body, StackMobOptions options, StackMobRawCallback callback)
          do a POST request on the StackMob platform for a single object
 void post(String path, String body, StackMobRawCallback callback)
          do a post request on the StackMob platform for a single object
<T> void
postBulk(String path, List<T> requestObjects, StackMobRawCallback callback)
          do a post request on the StackMob platform with a list of objects
 void postRelated(String path, String primaryId, String relatedField, Object relatedObject, StackMobRawCallback callback)
          post a new related object to an existing object.
 void postRelated(String path, String primaryId, String relatedField, String relatedObject, StackMobRawCallback callback)
          post a new related object to an existing object.
<T> void
postRelatedBulk(String path, String primaryId, String relatedField, List<T> relatedObjects, StackMobRawCallback callback)
          post a list of new related objects to an existing object.
 void put(String path, String id, Object requestObject, StackMobRawCallback callback)
          do a PUT request on the StackMob platform
 void put(String path, String id, String body, StackMobRawCallback callback)
          do a put request on the StackMob platform
 void putAndUpdateAtomicCounters(String path, String id, Object requestObject, List<String> counterFields, StackMobRawCallback callback)
          do a PUT request on the StackMob platform, treating some of the fields as counters to be incremented rather than as values to set
<T> void
putRelated(String path, String primaryId, String relatedField, List<T> relatedIds, StackMobRawCallback callback)
          do a an atomic put request on the StackMob platform with the contents of the has-many relation
 void setSession(StackMobSession session)
          set a specific session
 void updateAtomicCounter(String path, String id, String field, int value, StackMobRawCallback callback)
          do an atomic update on a an integer field in a particular object and schema
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StackMobDatastore

public StackMobDatastore(ExecutorService executor,
                         StackMobSession session,
                         String host,
                         StackMobRedirectedCallback redirectedCallback)
Method Detail

setSession

public void setSession(StackMobSession session)
set a specific session

Parameters:
session - the session to set

get

public void get(String path,
                StackMobRawCallback callback)
do a get request on the StackMob platform

Parameters:
path - the path to get
callback - callback to be called when the server returns. may execute in a separate thread

get

public void get(String path,
                StackMobOptions options,
                StackMobRawCallback callback)
do a get request on the StackMob platform

Parameters:
path - the path to get
options - additional options, such as headers, to modify the request
callback - callback to be called when the server returns. may execute in a separate thread

get

public void get(StackMobQuery query,
                StackMobRawCallback callback)
do a get request on the StackMob platform

Parameters:
query - the query to run
callback - callback to be called when the server returns. may execute in a separate thread

get

public void get(StackMobQuery query,
                StackMobOptions options,
                StackMobRawCallback callback)
do a get request on the StackMob platform

Parameters:
query - the query to run
options - additional options, such as headers, to modify the request
callback - callback to be called when the server returns. may execute in a separate thread

post

public void post(String path,
                 Object requestObject,
                 StackMobRawCallback callback)
do a post request on the StackMob platform for a single object

Parameters:
path - the path to get
requestObject - the object to serialize and send in the POST body. this object will be serialized with Gson
callback - callback to be called when the server returns. may execute in a separate thread

post

public void post(String path,
                 Object requestObject,
                 StackMobOptions options,
                 StackMobRawCallback callback)
do a post request on the StackMob platform for a single object

Parameters:
path - the path to get
requestObject - the object to serialize and send in the POST body. this object will be serialized with Gson
options - additional options, such as headers, to modify the request
callback - callback to be called when the server returns. may execute in a separate thread

post

public void post(String path,
                 String body,
                 StackMobRawCallback callback)
do a post request on the StackMob platform for a single object

Parameters:
path - the path to get
body - the json body
callback - callback to be called when the server returns. may execute in a separate thread

post

public void post(String path,
                 String body,
                 StackMobOptions options,
                 StackMobRawCallback callback)
do a POST request on the StackMob platform for a single object

Parameters:
path - the path to get
body - the json body
options - any additional headers to send
callback - callback to be called when the server returns. may execute in a separate thread

postBulk

public <T> void postBulk(String path,
                         List<T> requestObjects,
                         StackMobRawCallback callback)
do a post request on the StackMob platform with a list of objects

Parameters:
path - the path to get
requestObjects - List of objects to serialize and send in the POST body. the list will be serialized with Gson
callback - callback to be called when the server returns. may execute in a separate thread

postRelated

public void postRelated(String path,
                        String primaryId,
                        String relatedField,
                        Object relatedObject,
                        StackMobRawCallback callback)
post a new related object to an existing object. the relation of the root object is updated

Parameters:
path - the path to get
primaryId - id of the object with the relation
relatedField - name of the relation
relatedObject - related object to post
callback - callback to be called when the server returns. may execute in a separate thread

postRelated

public void postRelated(String path,
                        String primaryId,
                        String relatedField,
                        String relatedObject,
                        StackMobRawCallback callback)
post a new related object to an existing object. the relation of the root object is updated

Parameters:
path - the path to get
primaryId - id of the object with the relation
relatedField - name of the relation
relatedObject - related object to post
callback - callback to be called when the server returns. may execute in a separate thread

postRelatedBulk

public <T> void postRelatedBulk(String path,
                                String primaryId,
                                String relatedField,
                                List<T> relatedObjects,
                                StackMobRawCallback callback)
post a list of new related objects to an existing object. the relation of the root object is updated

Parameters:
path - the path to get
primaryId - id of the object with the relation
relatedField - name of the relation
relatedObjects - list of related objects to post. the list will be serialized with Gson
callback - callback to be called when the server returns. may execute in a separate thread

put

public void put(String path,
                String id,
                Object requestObject,
                StackMobRawCallback callback)
do a PUT request on the StackMob platform

Parameters:
path - the path to PUT
id - the id of the object to PUT
requestObject - the object to serialize and send in the PUT body. this object will be serialized with Gson
callback - callback to be called when the server returns. may execute in a separate thread

put

public void put(String path,
                String id,
                String body,
                StackMobRawCallback callback)
do a put request on the StackMob platform

Parameters:
path - the path to put
id - the id of the object to put
body - the json body
callback - callback to be called when the server returns. may execute in a separate thread

putAndUpdateAtomicCounters

public void putAndUpdateAtomicCounters(String path,
                                       String id,
                                       Object requestObject,
                                       List<String> counterFields,
                                       StackMobRawCallback callback)
do a PUT request on the StackMob platform, treating some of the fields as counters to be incremented rather than as values to set

Parameters:
path - the path to put
id - the id of the object to put
requestObject - the object to serialize and send in the PUT body. this object will be serialized with Gson
counterFields - a list of the fields in the object to be treated as counters being incremented
callback - callback to be called when the server returns. may execute in a separate thread

updateAtomicCounter

public void updateAtomicCounter(String path,
                                String id,
                                String field,
                                int value,
                                StackMobRawCallback callback)
do an atomic update on a an integer field in a particular object and schema

Parameters:
path - the path to put
id - the id of the object to put
field - the field to increment
value - the value to increment by
callback - callback to be called when the server returns. may execute in a separate thread

putRelated

public <T> void putRelated(String path,
                           String primaryId,
                           String relatedField,
                           List<T> relatedIds,
                           StackMobRawCallback callback)
do a an atomic put request on the StackMob platform with the contents of the has-many relation

Parameters:
path - the path to get
primaryId - id of the object with the relation
relatedField - name of the relation
relatedIds - list of ids to atomically add to the relation. The type should be the same type as the primary key field of the related object
callback - callback to be called when the server returns. may execute in a separate thread

delete

public void delete(String path,
                   String id,
                   StackMobRawCallback callback)
do a DELETE request to the StackMob platform

Parameters:
path - the path to delete
id - the id of the object to put
callback - callback to be called when the server returns. may execute in a separate thread

deleteIdsFrom

public <T> void deleteIdsFrom(String path,
                              String primaryId,
                              String field,
                              List<T> idsToDelete,
                              boolean cascadeDeletes,
                              StackMobRawCallback callback)
atomically remove elements from an array or has many relationship

Parameters:
path - the path to get
primaryId - id of the object with the relation
field - name of the relation or array field to delete from
idsToDelete - list of ids to atomically remove from field. ids should be same type as the primary id of the related type (most likely String or Integer)
cascadeDeletes - true if related objects specified in idsToDelete should also be deleted
callback - callback to be called when the server returns. may execute in a separate thread

deleteIdFrom

public <T> void deleteIdFrom(String path,
                             String primaryId,
                             String field,
                             T idToDelete,
                             boolean cascadeDelete,
                             StackMobRawCallback callback)
atomically remove elements from an array or has many relationship

Parameters:
path - the path to get
primaryId - id of the object with the relation
field - name of the relation or array field to delete from
idToDelete - id to atomically remove from field. should be same type as the primary id of the related type (most likely String or Integer)
cascadeDelete - true if related object specified in idToDelete should also be deleted
callback - callback to be called when the server returns. may execute in a separate thread

count

public void count(String path,
                  StackMobRawCallback callback)
retrieve the number of objects for a schema on the StackMob platform

Parameters:
path - the path to get
callback - callback to be called when the server returns. may execute in a separate thread

count

public void count(StackMobQuery query,
                  StackMobRawCallback callback)
retrieve the number of objects for a query on the StackMob platform

Parameters:
query - the query to send
callback - callback to be called when the server returns. may execute in a separate thread


Copyright © 2013 StackMob. All Rights Reserved.