com.h3c.util.persistence.cassandra

## Class DataStoreManager

- java.lang.Object
- - com.h3c.util.persistence.cassandra.DataStoreManager

- All Implemented Interfaces:
    DataStoreService<DataStoreContext>

      public class DataStoreManager
      extends Object
      implements DataStoreService<DataStoreContext>

  DataStoreManager provides an implementation of the `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 Summary

    Constructors
    Constructor and Description
    `DataStoreManager(EntityManagerFactory emf, KeySpaceConfig cassandraConfig)` DataStoreManager#DataStoreManager is called from only from the proxy of this implementation.

  - ### Method Summary

    Methods
    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` | `resetClientContext()`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### DataStoreManager

          public DataStoreManager(EntityManagerFactory emf,
                          KeySpaceConfig cassandraConfig)
                           throws PersistenceConnException

      DataStoreManager#DataStoreManager is called from only from the proxy of this implementation.

      The proxy is created in the application to create a OSGi service for DataStoreService interface.

      Parameters:
        `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.
      Throws:
        `PersistenceConnException` - If the ConnectionManager instantiation fails, this exception is thrown. This exception will mean that the DataStoreService is not available.

  - ### Method Detail

    - #### execute

          public <T> T execute(ReadQuery<T,DataStoreContext> query)
                    throws PersistenceException

      DataStoreManager#execute(ReadQuery) provides an implementation to execute a Read operation on the persistent database.

      This method does the following.

      1. Validate Input

      2. Create a UnitOfWork object

      3. Delegate the read query execution to the UnitOfWork

      Specified by:
        `execute` in interface `DataStoreService<DataStoreContext>`
      Type Parameters:
        `T` - type of the query result.
      Parameters:
        `query` - the read query to execute.
      Returns:
        the query result.
      Throws:
        `PersistenceException` - This exception is thrown if any of the query operations did not succeed.

    - #### execute

          public <T> T execute(WriteQuery<T,DataStoreContext> update)
                    throws PersistenceException

      DataStoreManager#execute(WriteQuery) provides an implementation to execute a Read operation on the persistent database.

      This method does the following.

      1. Validate Input

      2. Create a UnitOfWork object

      3. Delegate the read query execution to the UnitOfWork

      Specified by:
        `execute` in interface `DataStoreService<DataStoreContext>`
      Type Parameters:
        `T` - type of the transaction result.
      Parameters:
        `update` - the write query to execute.
      Returns:
        the transaction result.
      Throws:
        `PersistenceException` - This exception is thrown if any of the query operations did not succeed.

    - #### resetClientContext

          public void resetClientContext()

      Specified by:
        `resetClientContext` in interface `DataStoreService<DataStoreContext>`

Copyright © 2014. All Rights Reserved.