com.shephertz.app42.paas.sdk.jme.storage
Class StorageService

java.lang.Object
  extended by com.shephertz.app42.paas.sdk.jme.storage.StorageService

public class StorageService
extends java.lang.Object

Storage service on cloud provides the way to store the JSON document in NoSQL database running on cloud. One can store the JSON document, update it , search it and can apply the map-reduce search on stored documents. Example : If one will store JSON doc {"date":"5Feb"} it will be stored with unique Object Id and stored JSON object will look like { "date" : "5Feb" , "_id" : { "$oid" : "4f423dcce1603b3f0bd560cf"}}. This oid can further be used to access/search the document.

See Also:
Storage, App42Response

Constructor Summary
StorageService(java.lang.String apiKey, java.lang.String secretKey, java.lang.String baseURL)
          this is a constructor that takes
 
Method Summary
 App42Response deleteDocumentById(java.lang.String dbName, java.lang.String collectionName, java.lang.String docId)
          Delete target document using Object Id from given db and collection.
 Storage findAllDocuments(java.lang.String dbName, java.lang.String collectionName)
          Find all documents stored in given database and collection.
 Storage findAllDocuments(java.lang.String dbName, java.lang.String collectionName, java.lang.Integer max, java.lang.Integer offset)
          Find all documents stored in given database and collection.
 App42Response findAllDocumentsCount(java.lang.String dbName, java.lang.String collectionName)
          Gets the count of all documents stored in given database and collection.
 Storage findDocsWithQueryPagingOrderBy(java.lang.String dbName, java.lang.String collectionName, Query query, java.lang.Integer max, java.lang.Integer offset, java.lang.String orderByKey, java.lang.String type)
          Find target document using Custom Query with paging and orderby.
 Storage findDocumentById(java.lang.String dbName, java.lang.String collectionName, java.lang.String docId)
          Find target document by given unique object id.
 Storage findDocumentByKeyValue(java.lang.String dbName, java.lang.String collectionName, java.lang.String key, java.lang.String value)
          Find target document using key value search parameter.
 Storage findDocumentsByQuery(java.lang.String dbName, java.lang.String collectionName, Query query)
          Find target document using Custom Query.
 Storage findDocumentsByQueryWithPaging(java.lang.String dbName, java.lang.String collectionName, Query query, java.lang.Integer max, java.lang.Integer offset)
          Find target document using Custom Query with paging.
 java.lang.String getJsonFromMap(java.util.Hashtable map)
           
 Storage insertJSONDocument(java.lang.String dbName, java.lang.String collectionName, java.lang.String json)
          Save the JSON document in given database name and collection name.
 Storage insertJsonDocUsingMap(java.lang.String dbName, java.lang.String collectionName, java.util.Hashtable map)
          Save the JSON document in given database name and collection name.
 java.lang.String mapReduce(java.lang.String dbName, java.lang.String collectionName, java.lang.String mapFunction, java.lang.String reduceFunction)
          Map reduce function to search the target document.
 Storage updateDocumentByDocId(java.lang.String dbName, java.lang.String collectionName, java.lang.String docId, java.lang.String newJsonDoc)
          Update target document using the document id.
 Storage updateDocumentByKeyValue(java.lang.String dbName, java.lang.String collectionName, java.lang.String key, java.lang.String value, java.lang.String newJsonDoc)
          Update target document using key value search parameter.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StorageService

public StorageService(java.lang.String apiKey,
                      java.lang.String secretKey,
                      java.lang.String baseURL)
this is a constructor that takes

Parameters:
apiKey -
secretKey -
baseURL -
Method Detail

deleteDocumentById

public App42Response deleteDocumentById(java.lang.String dbName,
                                        java.lang.String collectionName,
                                        java.lang.String docId)
                                 throws App42Exception
Delete target document using Object Id from given db and collection. The Object Id will be searched in the JSON doc stored on the cloud and matching Doc will be deleted.

Parameters:
dbName - - Unique handler for storage name
collectionName - - Name of collection under which JSON doc needs to be searched
docId - - Unique Object Id handler
Returns:
App42Response object if deleted successfully
Throws:
App42Exception

findAllDocuments

public Storage findAllDocuments(java.lang.String dbName,
                                java.lang.String collectionName)
                         throws App42Exception
Find all documents stored in given database and collection.

Parameters:
dbName - - Unique handler for storage name
collectionName - - Name of collection under which JSON doc needs to be searched
Returns:
Storage object
Throws:
App42Exception

findAllDocuments

public Storage findAllDocuments(java.lang.String dbName,
                                java.lang.String collectionName,
                                java.lang.Integer max,
                                java.lang.Integer offset)
                         throws App42Exception
Find all documents stored in given database and collection.

Parameters:
dbName - - Unique handler for storage name
collectionName - - Name of collection under which JSON doc needs to be searched
max - - Maximum number of records to be fetched
offset - - From where the records are to be fetched
Returns:
Storage object
Throws:
App42Exception

findAllDocumentsCount

public App42Response findAllDocumentsCount(java.lang.String dbName,
                                           java.lang.String collectionName)
                                    throws App42Exception
Gets the count of all documents stored in given database and collection.

Parameters:
dbName - - Unique handler for storage name
collectionName - - Name of collection under which JSON doc needs to be searched
Returns:
App42Response object
Throws:
App42Exception

findDocsWithQueryPagingOrderBy

public Storage findDocsWithQueryPagingOrderBy(java.lang.String dbName,
                                              java.lang.String collectionName,
                                              Query query,
                                              java.lang.Integer max,
                                              java.lang.Integer offset,
                                              java.lang.String orderByKey,
                                              java.lang.String type)
                                       throws App42Exception
Find target document using Custom Query with paging and orderby.

Parameters:
dbName - - Unique handler for storage name
collectionName - - Name of collection under which JSON doc needs to be searched
Query - - Query Object containing custom query for searching docs
max - - max result parameter
offset - - offset result parameter
Returns:
Storage object
Throws:
App42Exception

findDocumentById

public Storage findDocumentById(java.lang.String dbName,
                                java.lang.String collectionName,
                                java.lang.String docId)
                         throws App42Exception
Find target document by given unique object id.

Parameters:
dbName - - Unique handler for storage name
collectionName - - Name of collection under which JSON doc needs to be searched
docId - - Unique Object Id handler
Returns:
Storage object
Throws:
App42Exception

findDocumentByKeyValue

public Storage findDocumentByKeyValue(java.lang.String dbName,
                                      java.lang.String collectionName,
                                      java.lang.String key,
                                      java.lang.String value)
                               throws App42Exception
Find target document using key value search parameter. This key value pair will be searched in the JSON doc stored on the cloud and matching Doc will be returned as a result of this method.

Parameters:
dbName - - Unique handler for storage name
collectionName - - Name of collection under which JSON doc needs to be searched
key - - Key to be searched for target JSON doc
value - - Value to be searched for target JSON doc
Returns:
Storage object
Throws:
App42Exception

findDocumentsByQuery

public Storage findDocumentsByQuery(java.lang.String dbName,
                                    java.lang.String collectionName,
                                    Query query)
                             throws App42Exception
Find target document using Custom Query.

Parameters:
dbName - - Unique handler for storage name
collectionName - - Name of collection under which JSON doc needs to be searched
Query - - Query Object containing custom query for searching docs
Returns:
Storage object
Throws:
App42Exception

findDocumentsByQueryWithPaging

public Storage findDocumentsByQueryWithPaging(java.lang.String dbName,
                                              java.lang.String collectionName,
                                              Query query,
                                              java.lang.Integer max,
                                              java.lang.Integer offset)
                                       throws App42Exception
Find target document using Custom Query with paging.

Parameters:
dbName - - Unique handler for storage name
collectionName - - Name of collection under which JSON doc needs to be searched
Query - - Query Object containing custom query for searching docs
max - - max result parameter
offset - - offset result parameter
Returns:
Storage object
Throws:
App42Exception

getJsonFromMap

public java.lang.String getJsonFromMap(java.util.Hashtable map)
                                throws App42Exception
Parameters:
map -
Returns:
Throws:
App42Exception

insertJSONDocument

public Storage insertJSONDocument(java.lang.String dbName,
                                  java.lang.String collectionName,
                                  java.lang.String json)
                           throws App42Exception
Save the JSON document in given database name and collection name.

Parameters:
dbName - - Unique handler for storage name
collectionName - - Name of collection under which JSON doc has to be saved
json - - Target JSON document to be saved
Returns:
Storage object
Throws:
App42Exception

insertJsonDocUsingMap

public Storage insertJsonDocUsingMap(java.lang.String dbName,
                                     java.lang.String collectionName,
                                     java.util.Hashtable map)
                              throws App42Exception
Save the JSON document in given database name and collection name. It accepts the HashMap containing key-value and convert it into JSON. Converted JSON doc further saved on the cloud using given db name and collection name.

Parameters:
dbName - - Unique handler for storage name
collectionName - - Name of collection under which JSON doc has to be saved
map - - HashMap containing key-value pairs
Returns:
Storage object
Throws:
App42Exception

mapReduce

public java.lang.String mapReduce(java.lang.String dbName,
                                  java.lang.String collectionName,
                                  java.lang.String mapFunction,
                                  java.lang.String reduceFunction)
                           throws App42Exception
Map reduce function to search the target document. Please see detail information on map-reduce http://en.wikipedia.org/wiki/MapReduce

Parameters:
dbName - - Unique handler for storage name
collectionName - - Name of collection under which JSON doc needs to be searched
mapFunction - - Map function to be used to search the document
reduceFunction - - Reduce function to be used to search the document
Returns:
Returns the target JSON document.
Throws:
App42Exception

updateDocumentByDocId

public Storage updateDocumentByDocId(java.lang.String dbName,
                                     java.lang.String collectionName,
                                     java.lang.String docId,
                                     java.lang.String newJsonDoc)
                              throws App42Exception
Update target document using the document id.

Parameters:
dbName - - Unique handler for storage name
collectionName - - Name of collection under which JSON doc needs to be searched
docId - - Id of the document to be searched for target JSON doc
newJsonDoc - - New Json document to be added
Returns:
Storage object
Throws:
App42Exception

updateDocumentByKeyValue

public Storage updateDocumentByKeyValue(java.lang.String dbName,
                                        java.lang.String collectionName,
                                        java.lang.String key,
                                        java.lang.String value,
                                        java.lang.String newJsonDoc)
                                 throws App42Exception
Update target document using key value search parameter. This key value pair will be searched in the JSON doc stored in the cloud and matching Doc will be updated with new value passed.

Parameters:
dbName - - Unique handler for storage name
collectionName - - Name of collection under which JSON doc needs to be searched
key - - Key to be searched for target JSON doc
value - - Value to be searched for target JSON doc
newJsonDoc - - New Json document to be added
Returns:
Storage object
Throws:
App42Exception