Class PersistenceServiceWrapper

java.lang.Object
uk.ac.diamond.daq.persistence.manager.PersistenceServiceWrapper
All Implemented Interfaces:
uk.ac.diamond.daq.application.persistence.service.PersistenceService

@OsgiService(PersistenceServiceWrapper.class) public class PersistenceServiceWrapper extends Object implements uk.ac.diamond.daq.application.persistence.service.PersistenceService
Loads and saves items from an abstracted data store.

The classes of stored items must have the Persistable annotation. Also theses classes must also contain an id and version members which are both logs with the Id and Version annotations.

The service uses Jackson behind the seen to serialise the objects to json to be stored. Therefore any class that is serialisable by Jackson will be able to be persisted by the service. If the class contains members that cannot be serialised by Jackson the CustomPersistable annotation can be used to specify a custom serialiser.

If the item's class contains other classes that are Persistable then these are saved independently to the containing item. Should the nested item be updated by another process the latest version of the nested item will be returned with the containing item.

Members of the class that have the Listable annotation will be returned as part of the object search, and can be used as parameters for specific searches. If a Listable item with the attribute primary is true then any update to that member will cause a new item to be created.

An archive of all persisted item is retained.

  • Constructor Summary

    Constructors
    Constructor
    Description
    PersistenceServiceWrapper(uk.ac.diamond.daq.application.persistence.factory.PersistenceServiceFactory persistenceServiceFactory)
    Create the persistence wrapper from a factory
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    delete(long persistenceId)
    Deletes an item with the specified ID note that archived items are not deleted
    <T> T
    get(long persistenceId, Class<T> clazz)
    Get the current version of item
    <T> uk.ac.diamond.daq.application.persistence.data.SearchResult
    get(Class<T> clazz)
    Finds all items stored of a type.
    <T> uk.ac.diamond.daq.application.persistence.data.SearchResult
    get(Map<String,Object> searchParameters, Class<T> clazz)
    Finds all items stored of a type using search parameters The search parameters are made from key value pairs of Listable value against the string value of the Listable field.
    <T> T
    getArchive(long persistenceId, long version, Class<T> clazz)
    Get a specific version of an item from the archive
    getVersions(long persistenceId)
    List the versions available of an item.
    <T> void
    save(T item)
    Saves the an item that is persistable, and archived copy of the item is also stored

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • PersistenceServiceWrapper

      public PersistenceServiceWrapper(uk.ac.diamond.daq.application.persistence.factory.PersistenceServiceFactory persistenceServiceFactory)
      Create the persistence wrapper from a factory
      Parameters:
      persistenceServiceFactory -
  • Method Details

    • save

      public <T> void save(T item) throws uk.ac.diamond.daq.application.persistence.service.PersistenceException
      Saves the an item that is persistable, and archived copy of the item is also stored
      Specified by:
      save in interface uk.ac.diamond.daq.application.persistence.service.PersistenceService
      Type Parameters:
      T - class
      Parameters:
      item - persistable item
      Throws:
      uk.ac.diamond.daq.application.persistence.service.PersistenceException - if the storage system fails to save the item
    • delete

      public boolean delete(long persistenceId) throws uk.ac.diamond.daq.application.persistence.service.PersistenceException
      Deletes an item with the specified ID note that archived items are not deleted
      Specified by:
      delete in interface uk.ac.diamond.daq.application.persistence.service.PersistenceService
      Parameters:
      persistenceId - id of the item
      Returns:
      whether the item was found and deleted
      Throws:
      uk.ac.diamond.daq.application.persistence.service.PersistenceException - if the there is an issue with the storage system
    • get

      public <T> uk.ac.diamond.daq.application.persistence.data.SearchResult get(Class<T> clazz) throws uk.ac.diamond.daq.application.persistence.service.PersistenceException
      Finds all items stored of a type. Items inherited from the class are also returned. The results are only a summary of each item based of the Listable annotations applied to the method and fields of each items class i.e. different classes may return differing summaries that are contained in the same SearchResult
      Specified by:
      get in interface uk.ac.diamond.daq.application.persistence.service.PersistenceService
      Type Parameters:
      T - class or interface to be found
      Parameters:
      clazz - class or interface to be found
      Returns:
      results of the
      Throws:
      uk.ac.diamond.daq.application.persistence.service.PersistenceException - if error in storage layer
    • get

      public <T> uk.ac.diamond.daq.application.persistence.data.SearchResult get(Map<String,Object> searchParameters, Class<T> clazz) throws uk.ac.diamond.daq.application.persistence.service.PersistenceException
      Finds all items stored of a type using search parameters The search parameters are made from key value pairs of Listable value against the string value of the Listable field.
      Specified by:
      get in interface uk.ac.diamond.daq.application.persistence.service.PersistenceService
      Type Parameters:
      T - class
      Parameters:
      searchParameters - map of @Listable field name to String value of the field
      clazz - base class of the items to be returned
      Returns:
      matching items
      Throws:
      uk.ac.diamond.daq.application.persistence.service.PersistenceException - if searchParameters is null or storage system error
    • get

      public <T> T get(long persistenceId, Class<T> clazz) throws uk.ac.diamond.daq.application.persistence.service.PersistenceException
      Get the current version of item
      Specified by:
      get in interface uk.ac.diamond.daq.application.persistence.service.PersistenceService
      Type Parameters:
      T - base class of the item
      Parameters:
      persistenceId - id of the item
      clazz - base class of the item
      Returns:
      instance of that item
      Throws:
      uk.ac.diamond.daq.application.persistence.service.PersistenceException - if id not found, unable to cast to class, or storage system failure
    • getVersions

      public List<Long> getVersions(long persistenceId) throws uk.ac.diamond.daq.application.persistence.service.PersistenceException
      List the versions available of an item.
      Specified by:
      getVersions in interface uk.ac.diamond.daq.application.persistence.service.PersistenceService
      Parameters:
      persistenceId - id of the item
      Returns:
      version available from the archive system
      Throws:
      uk.ac.diamond.daq.application.persistence.service.PersistenceException - if id not found, or storage system failure
    • getArchive

      public <T> T getArchive(long persistenceId, long version, Class<T> clazz) throws uk.ac.diamond.daq.application.persistence.service.PersistenceException
      Get a specific version of an item from the archive
      Specified by:
      getArchive in interface uk.ac.diamond.daq.application.persistence.service.PersistenceService
      Type Parameters:
      T - base class of the item
      Parameters:
      persistenceId - id of the item
      version - version of the item
      clazz - base class of the item
      Returns:
      instance of that item
      Throws:
      uk.ac.diamond.daq.application.persistence.service.PersistenceException - if id/version not found, unable to cast to class, or storage system failure