eu.emi.dsr.db.mongodb
Class MongoDBServiceDatabase

java.lang.Object
  extended by eu.emi.dsr.db.mongodb.MongoDBServiceDatabase
All Implemented Interfaces:
ServiceDatabase

public class MongoDBServiceDatabase
extends Object
implements ServiceDatabase

Author:
martoni, a.memon, g.szigeti

Constructor Summary
MongoDBServiceDatabase()
           
MongoDBServiceDatabase(String hostname, Integer port, String dbName, String colName)
           
 
Method Summary
 void deleteAll()
           
 void deleteByUrl(String url)
          Delete multiple items from the persistent store
 void dropCollection()
           
 void dropDB()
           
 List<ServiceObject> findAll()
           
 void findAndDelete(String query)
          Query and delete the matching documents
 String getDBVersion()
          Get version of the database
 ServiceObject getServiceByUrl(String identifier)
          Get an item from the persistent store
 void insert(com.mongodb.DBObject item)
           
 void insert(ServiceObject item)
          Insert service description to the persistent store.
 org.codehaus.jettison.json.JSONArray paginatedQuery(String query, Integer pageSize, String id)
           
 List<ServiceObject> query(String query)
          Query the persistent store
 List<ServiceObject> query(String query, Integer skip)
          Querying the collection
 List<ServiceObject> query(String query, Integer limit, Integer skip)
          Querying the collection
 org.codehaus.jettison.json.JSONArray queryDistinctJSON(String attributeName)
          Get distinct values for a given attribute
 org.codehaus.jettison.json.JSONArray queryJSON(String query)
           
 org.codehaus.jettison.json.JSONArray queryJSON(String query, Integer skip)
           
 org.codehaus.jettison.json.JSONArray queryJSON(String query, Integer limit, Integer skip)
           
 org.codehaus.jettison.json.JSONArray queryJSONWithLimit(String s, Integer limit)
           
 void update(ServiceObject sObj)
          Update an existing item in the persistent store
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MongoDBServiceDatabase

public MongoDBServiceDatabase()

MongoDBServiceDatabase

public MongoDBServiceDatabase(String hostname,
                              Integer port,
                              String dbName,
                              String colName)
Parameters:
hostname - - default localhost
port - - default 27017
dbName - - default emiregistry
colName - - default services
Method Detail

insert

public void insert(ServiceObject item)
            throws ExistingResourceException,
                   PersistentStoreFailureException
Description copied from interface: ServiceDatabase
Insert service description to the persistent store. If it throws an exception if the item already exists

Specified by:
insert in interface ServiceDatabase
Parameters:
item - an item to insert into the database
Throws:
ExistingResourceException - throws exception if the element already exists
PersistentStoreFailureException - throws exception if the persistent store is unavailable

insert

public void insert(com.mongodb.DBObject item)
            throws ExistingResourceException,
                   PersistentStoreFailureException
Throws:
ExistingResourceException
PersistentStoreFailureException

getServiceByUrl

public ServiceObject getServiceByUrl(String identifier)
                              throws MultipleResourceException,
                                     NonExistingResourceException,
                                     PersistentStoreFailureException
Description copied from interface: ServiceDatabase
Get an item from the persistent store

Specified by:
getServiceByUrl in interface ServiceDatabase
Parameters:
identifier - unique identifier of an object in the persistent store (url)
Returns:
the stored content of the specified object
Throws:
MultipleResourceException - throws exception if the identifier specifies more than one item
NonExistingResourceException - throws exception if the item specified by identifier is not existing in the persistent store
PersistentStoreFailureException - throws exception if persistent store level error occurs

deleteByUrl

public void deleteByUrl(String url)
                 throws MultipleResourceException,
                        NonExistingResourceException,
                        PersistentStoreFailureException
Description copied from interface: ServiceDatabase
Delete multiple items from the persistent store

Specified by:
deleteByUrl in interface ServiceDatabase
Throws:
MultipleResourceException - throws exception if the identifier specifies more than one item
NonExistingResourceException - throws exception if the item specified by identifier is not existing in the persistent store
PersistentStoreFailureException - throws exception if persistent store level error occurs TODO: support list of urls

update

public void update(ServiceObject sObj)
            throws MultipleResourceException,
                   NonExistingResourceException,
                   PersistentStoreFailureException
Description copied from interface: ServiceDatabase
Update an existing item in the persistent store

Specified by:
update in interface ServiceDatabase
Throws:
MultipleResourceException - throws exception if the identifier specifies more than one item
NonExistingResourceException - throws exception if the item specified by identifier is not existing in the persistent store
PersistentStoreFailureException - throws exception if persistent store level error occurs

query

public List<ServiceObject> query(String query)
                          throws QueryException,
                                 PersistentStoreFailureException
Description copied from interface: ServiceDatabase
Query the persistent store

Specified by:
query in interface ServiceDatabase
Parameters:
query - (a JSON String)
Returns:
a collection of matching entries from the persistent store if any or an empty collection
Throws:
QueryException - throws exception if the query contains any query specific error
PersistentStoreFailureException - throws exception if persistent store level error occurs

query

public List<ServiceObject> query(String query,
                                 Integer limit,
                                 Integer skip)
                          throws QueryException,
                                 PersistentStoreFailureException
Description copied from interface: ServiceDatabase
Querying the collection

Specified by:
query in interface ServiceDatabase
Parameters:
query - the json string containing the query
limit - total number of results to return
skip - skipping the query result
Returns:
returns a list with (limit-skip) number of records - within the same limit
Throws:
QueryException
PersistentStoreFailureException

query

public List<ServiceObject> query(String query,
                                 Integer skip)
                          throws QueryException,
                                 PersistentStoreFailureException
Description copied from interface: ServiceDatabase
Querying the collection

Specified by:
query in interface ServiceDatabase
Parameters:
query - the json string containing the query
skip - skipping the query result
Returns:
the list containing total-skip number of matching ServiceObjects
Throws:
QueryException
PersistentStoreFailureException

queryJSON

public org.codehaus.jettison.json.JSONArray queryJSON(String query)
                                               throws QueryException,
                                                      PersistentStoreFailureException,
                                                      com.mongodb.MongoException,
                                                      org.codehaus.jettison.json.JSONException
Specified by:
queryJSON in interface ServiceDatabase
Returns:
Throws:
QueryException
PersistentStoreFailureException
com.mongodb.MongoException
org.codehaus.jettison.json.JSONException

queryJSON

public org.codehaus.jettison.json.JSONArray queryJSON(String query,
                                                      Integer limit,
                                                      Integer skip)
                                               throws QueryException,
                                                      PersistentStoreFailureException
Specified by:
queryJSON in interface ServiceDatabase
Returns:
Throws:
QueryException
PersistentStoreFailureException

queryJSON

public org.codehaus.jettison.json.JSONArray queryJSON(String query,
                                                      Integer skip)
                                               throws QueryException,
                                                      PersistentStoreFailureException
Specified by:
queryJSON in interface ServiceDatabase
Returns:
Throws:
QueryException
PersistentStoreFailureException

queryJSONWithLimit

public org.codehaus.jettison.json.JSONArray queryJSONWithLimit(String s,
                                                               Integer limit)
Specified by:
queryJSONWithLimit in interface ServiceDatabase
Returns:

queryDistinctJSON

public org.codehaus.jettison.json.JSONArray queryDistinctJSON(String attributeName)
Description copied from interface: ServiceDatabase
Get distinct values for a given attribute

Specified by:
queryDistinctJSON in interface ServiceDatabase
Returns:

paginatedQuery

public org.codehaus.jettison.json.JSONArray paginatedQuery(String query,
                                                           Integer pageSize,
                                                           String id)
Specified by:
paginatedQuery in interface ServiceDatabase

deleteAll

public void deleteAll()
Specified by:
deleteAll in interface ServiceDatabase

findAll

public List<ServiceObject> findAll()
                            throws org.codehaus.jettison.json.JSONException
Specified by:
findAll in interface ServiceDatabase
Throws:
org.codehaus.jettison.json.JSONException

findAndDelete

public void findAndDelete(String query)
Description copied from interface: ServiceDatabase
Query and delete the matching documents

Specified by:
findAndDelete in interface ServiceDatabase

dropCollection

public void dropCollection()

dropDB

public void dropDB()

getDBVersion

public String getDBVersion()
Description copied from interface: ServiceDatabase
Get version of the database

Specified by:
getDBVersion in interface ServiceDatabase
Returns:
String, version of the database


Copyright © 2012. All Rights Reserved.