com.stackmob.sdkapi
Interface DataService


public interface DataService

DataService allows you to interact with your data on StackMob


Method Summary
 SMObject addRelatedObjects(String schema, SMValue objectId, String relation, List<SMValue> relatedIds)
          Adds the specified IDs to the specified relationship
 long countObjects(String schema)
          Get the number of objects in a schema
 SMObject createObject(String schema, SMObject toCreate)
          Creates a new object in the datastore.
 BulkResult createRelatedObjects(String schema, SMValue objectId, String relatedField, List<SMObject> relatedObjectsToCreate)
          Creates a number of new objects in the datastore.
 Boolean deleteObject(String schema, SMValue id)
          Deletes an object in the datastore.
 Boolean deleteObject(String schema, String id)
          Deletes an object in the datastore.
 Set<String> getObjectModelNames()
          Retrieves a list of the object models declared for the current application.
 List<SMObject> readObjects(String schema, List<SMCondition> conditions)
          Reads a list of objects matching the given query fields from the datastore.
 List<SMObject> readObjects(String schema, List<SMCondition> conditions, int expandDepth)
          Reads a list of objects matching the given query fields from the datastore, expanding relationships.
 List<SMObject> readObjects(String schema, List<SMCondition> conditions, int expandDepth, ResultFilters resultFilters)
          Reads a list of objects matching the given query fields from the datastore subject to several conditions.
 List<SMObject> readObjects(String schema, List<SMCondition> conditions, List<String> fields)
          Reads a list of objects matching the given query fields from the datastore, returning only the specified fields.
 void removeRelatedObjects(String schema, SMValue objectId, String relation, List<SMValue> relatedIds, boolean cascadeDelete)
          Removes any number of related objects from a relationship.
 SMObject updateObject(String schema, SMValue id, List<SMCondition> conditions, List<SMUpdate> updateActions)
          Updates an object in the datastore, if and only if it meets additional conditions.
 SMObject updateObject(String schema, SMValue id, List<SMUpdate> updateActions)
          Updates an object in the datastore.
 SMObject updateObject(String schema, String id, List<SMUpdate> updateActions)
          Updates an object in the datastore.
 void updateObjects(String schema, List<SMCondition> conditions, List<SMUpdate> updateActions)
          Updates all objects matching the given query in the datastore
 

Method Detail

createObject

SMObject createObject(String schema,
                      SMObject toCreate)
                      throws InvalidSchemaException,
                             DatastoreException
Creates a new object in the datastore. Each such object should be represented as a map of field names to objects, where each sub-object is a List, Map, String, Long, or Double depending on the type of the field in question.

Parameters:
schema - the name of the relevant object schema
toCreate - the object to create; must match the schema declared for the relevant object type
Returns:
the object created
Throws:
InvalidSchemaException - if the object to create does not match the relevant schema
DatastoreException - if the connection to the datastore fails or the datastore encounters an error

createRelatedObjects

BulkResult createRelatedObjects(String schema,
                                SMValue objectId,
                                String relatedField,
                                List<SMObject> relatedObjectsToCreate)
                                throws InvalidSchemaException,
                                       DatastoreException
Creates a number of new objects in the datastore. Each such object should be represented as a map of field names to objects, where each sub-object is a List, Map, String, Long, or Double depending on the type of the field in question.

Parameters:
schema - the name of the schema which contains the relation to the object to be inserted
objectId - the ID value of the object to relate to the inserted object
relatedField - the field name of the relationship
relatedObjectsToCreate - the related objects to insert
Returns:
a BulkResult containing the ids of objects which were successful, and objects which failed to insert
Throws:
InvalidSchemaException - if the object to create does not match the relevant schema
DatastoreException - if the connection to the datastore fails or the datastore encounters an error

readObjects

List<SMObject> readObjects(String schema,
                           List<SMCondition> conditions)
                           throws InvalidSchemaException,
                                  DatastoreException
Reads a list of objects matching the given query fields from the datastore.

Parameters:
schema - the name of the relevant object model
conditions - the list of conditions which comprise the query
Returns:
a list of all documents matching the query
Throws:
InvalidSchemaException - if the schema specified does not exist, or the query is incompatible with the schema
DatastoreException - if the connection to the datastore fails or the datastore encounters an error

readObjects

List<SMObject> readObjects(String schema,
                           List<SMCondition> conditions,
                           List<String> fields)
                           throws InvalidSchemaException,
                                  DatastoreException
Reads a list of objects matching the given query fields from the datastore, returning only the specified fields.

Parameters:
schema - the name of the relevant object model
conditions - the list of conditions which comprise the query
fields - the list of fields to be returned; regardless of what is specified, the id will always be returned; if null, all fields will be returned
Returns:
a list of all documents matching the query
Throws:
InvalidSchemaException - if the schema specified does not exist, or the query is incompatible with the schema
DatastoreException - if the connection to the datastore fails or the datastore encounters an error

readObjects

List<SMObject> readObjects(String schema,
                           List<SMCondition> conditions,
                           int expandDepth)
                           throws InvalidSchemaException,
                                  DatastoreException
Reads a list of objects matching the given query fields from the datastore, expanding relationships.

Parameters:
schema - the name of the relevant object model
conditions - the list of conditions which comprise the query
expandDepth - the depth to which a query should be expanded
Returns:
a list of all documents matching the query
Throws:
InvalidSchemaException - if the schema specified does not exist, or the query is incompatible with the schema
DatastoreException - if the connection to the datastore fails or the datastore encounters an error

readObjects

List<SMObject> readObjects(String schema,
                           List<SMCondition> conditions,
                           int expandDepth,
                           ResultFilters resultFilters)
                           throws InvalidSchemaException,
                                  DatastoreException
Reads a list of objects matching the given query fields from the datastore subject to several conditions.

Parameters:
schema - the name of the relevant object model
conditions - the list of conditions which comprise the query
expandDepth - the depth to which a query should be expanded
resultFilters - the options to be used when filtering the resultset
Returns:
a list of all documents matching the query
Throws:
InvalidSchemaException - if the schema specified does not exist, or the query is incompatible with the schema
DatastoreException - if the connection to the datastore fails or the datastore encounters an error

updateObject

SMObject updateObject(String schema,
                      String id,
                      List<SMUpdate> updateActions)
                      throws InvalidSchemaException,
                             DatastoreException
Updates an object in the datastore.

Parameters:
schema - the name of the relevant object model; must be a type already declared for the current application
id - the id of the object to update
updateActions - the actions to take on the object being updated
Returns:
the updated object
Throws:
InvalidSchemaException - if the schema does not exist, or the update actions are incompatible with it
DatastoreException - if the connection to the datastore fails or the datastore encounters an error

updateObject

SMObject updateObject(String schema,
                      SMValue id,
                      List<SMUpdate> updateActions)
                      throws InvalidSchemaException,
                             DatastoreException
Updates an object in the datastore.

Parameters:
schema - the name of the relevant object model; must be a type already declared for the current application
id - the id of the object to update
updateActions - the actions to take on the object being updated
Returns:
the updated object
Throws:
InvalidSchemaException - if the schema does not exist, or the update actions are incompatible with it
DatastoreException - if the connection to the datastore fails or the datastore encounters an error

updateObject

SMObject updateObject(String schema,
                      SMValue id,
                      List<SMCondition> conditions,
                      List<SMUpdate> updateActions)
                      throws InvalidSchemaException,
                             DatastoreException
Updates an object in the datastore, if and only if it meets additional conditions.

Parameters:
schema - the name of the relevant object model; must be a type already declared for the current application
id - the id of the object to update
conditions - the conditions which must be met for the update to occur
updateActions - the actions to take on the object being updated
Returns:
the updated object, or null if no object meets the given conditions
Throws:
InvalidSchemaException - if the schema does not exist, or the update actions are incompatible with it
DatastoreException - if the connection to the datastore fails or the datastore encounters an error

updateObjects

void updateObjects(String schema,
                   List<SMCondition> conditions,
                   List<SMUpdate> updateActions)
                   throws InvalidSchemaException,
                          DatastoreException
Updates all objects matching the given query in the datastore

Parameters:
schema - the name of the relevant object model; must be a type already declared for the current application
query - the query used to find objects to update
updateActions - the actions to take on the object being updated
Throws:
InvalidSchemaException - if the schema does not exist, or the update actions are incompatible with it
DatastoreException - if the connection to the datastore fails or the datastore encounters an error

addRelatedObjects

SMObject addRelatedObjects(String schema,
                           SMValue objectId,
                           String relation,
                           List<SMValue> relatedIds)
                           throws InvalidSchemaException,
                                  DatastoreException
Adds the specified IDs to the specified relationship

Parameters:
schema - the name of the relevant object model; must be a type already declared for the current application
objectId - the id of the object to which relations should be added
relation - the relation field to follow
relatedIds - the ids of all objects to be related to the specified parent object
Throws:
InvalidSchemaException - if the schema does not exist, or the update actions are incompatible with it
DatastoreException - if the connection to the datastore fails or the datastore encounters an error

deleteObject

Boolean deleteObject(String schema,
                     String id)
                     throws InvalidSchemaException,
                            DatastoreException
Deletes an object in the datastore.

Parameters:
schema - the name of the relevant object model; must be a type already declared for the current application
id - the id of the object to delete
Returns:
a Boolean object representing success (Boolean.TRUE) or failure (Boolean.FALSE)
Throws:
InvalidSchemaException - if the object model specified does not exist
DatastoreException - if the connection to the datastore fails or the datastore encounters an error

deleteObject

Boolean deleteObject(String schema,
                     SMValue id)
                     throws InvalidSchemaException,
                            DatastoreException
Deletes an object in the datastore.

Parameters:
schema - the name of the relevant object model; must be a type already declared for the current application
id - the id of the object to delete
Returns:
a Boolean object representing success (Boolean.TRUE) or failure (Boolean.FALSE)
Throws:
InvalidSchemaException - if the object model specified does not exist
DatastoreException - if the connection to the datastore fails or the datastore encounters an error

removeRelatedObjects

void removeRelatedObjects(String schema,
                          SMValue objectId,
                          String relation,
                          List<SMValue> relatedIds,
                          boolean cascadeDelete)
                          throws InvalidSchemaException,
                                 DatastoreException
Removes any number of related objects from a relationship. May also delete the objects removed from the relationship.

Parameters:
schema - the name of the relevant object model; must be a type already declared for the current application
objectId - the id of the object to which relations should be removed
related - the relation field to follow
relatedIds - the ids of the objects to be removed from the relationship
cascadeDelete - should be set to true if and only if you wish to also delete from the datastore all objects removed from the relationship
Throws:
InvalidSchemaException - if the object model specified does not exist
DatastoreException - if the connection to the datastore fails or the datastore encounters an error

countObjects

long countObjects(String schema)
                  throws InvalidSchemaException,
                         DatastoreException
Get the number of objects in a schema

Parameters:
schema - the name of the object model to count
Returns:
the number of objects in the datastore for the given object model
Throws:
InvalidSchemaException - if the object model specified does not exist
DatastoreException - if the connection to the datastore fails or the datastore encounters an error

getObjectModelNames

Set<String> getObjectModelNames()
                                throws ConnectException
Retrieves a list of the object models declared for the current application.

Returns:
the set of all valid object model names
Throws:
ConnectException - if the list of object models cannot be retrieved


Copyright © 2012 StackMob. All Rights Reserved.