public class DataStoreManager extends Object implements DataStoreService<DataStoreContext>, Stoppable
DataStoreService
. This implementation specifically provides
persistence using Cassandra DB. The applications simply use the OSGi
DataStoreService for persistence operations and need not know the specific
implementation of the service. If there is a need for another database,
we need to implement one more DataStoreManager specific to that new database
design.
The DatastoreManager creates a UnitOfWork object for each incoming query. This UnitOfWork object executes a query in its context. This way, DataStoreManager can handle queries in parallel without any interference.
Constructor and Description |
---|
DataStoreManager(EntityManagerFactory emf,
KeySpaceConfig cassandraConfig)
DataStoreManager#DataStoreManager is called from only from the
proxy of this implementation.
|
Modifier and Type | Method and Description |
---|---|
<T> T |
execute(ReadQuery<T,DataStoreContext> query)
DataStoreManager#execute(ReadQuery) provides an implementation
to execute a Read operation on the persistent database.
|
<T> T |
execute(WriteQuery<T,DataStoreContext> update)
DataStoreManager#execute(WriteQuery) provides an implementation
to execute a Read operation on the persistent database.
|
void |
stop()
Stops (shutdowns) operations.
|
public DataStoreManager(EntityManagerFactory emf, KeySpaceConfig cassandraConfig) throws PersistenceConnException
The proxy is created in the application to create a OSGi service for DataStoreService interface.
emf
- This is the EntityManagerFactory that will
create an entity manager object on demand.cassandraConfig
- This is the basic Cassandra Configuration.
It contains the Cluster Name, KeySpace Name and
the Seed IP address needed for instantiating the
Cassandra Client.PersistenceConnException
public <T> T execute(ReadQuery<T,DataStoreContext> query) throws PersistenceException, PersistenceConnException, com.netflix.astyanax.connectionpool.exceptions.ConnectionException
This method does the following.
1. Validate Input
2. Create a UnitOfWork object
3. Delegate the read query execution to the UnitOfWork
execute
in interface DataStoreService<DataStoreContext>
T
- type of the query result.query
- the read query to execute.PersistenceException
- This exception is thrown if any of the
query operations did not succeed.PersistenceConnException
- This exception is thrown on database
connection issuescom.netflix.astyanax.connectionpool.exceptions.ConnectionException
public <T> T execute(WriteQuery<T,DataStoreContext> update) throws PersistenceException, PersistenceConnException
This method does the following.
1. Validate Input
2. Create a UnitOfWork object
3. Delegate the read query execution to the UnitOfWork
execute
in interface DataStoreService<DataStoreContext>
T
- type of the transaction result.update
- the write query to execute.PersistenceException
- This exception is thrown if any of the
query operations did not succeed.PersistenceConnException
- This exception is thrown on database
connection issuesCopyright © 2015. All Rights Reserved.