Class PersistenceServiceWrapper
- All Implemented Interfaces:
uk.ac.diamond.daq.application.persistence.service.PersistenceService
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
ConstructorsConstructorDescriptionPersistenceServiceWrapper(uk.ac.diamond.daq.application.persistence.factory.PersistenceServiceFactory persistenceServiceFactory) Create the persistence wrapper from a factory -
Method Summary
Modifier and TypeMethodDescriptionbooleandelete(long persistenceId) Deletes an item with the specified ID note that archived items are not deleted<T> TGet the current version of item<T> uk.ac.diamond.daq.application.persistence.data.SearchResultFinds all items stored of a type.<T> uk.ac.diamond.daq.application.persistence.data.SearchResultFinds all items stored of a type using search parameters The search parameters are made from key value pairs ofListablevalue against the string value of theListablefield.<T> TgetArchive(long persistenceId, long version, Class<T> clazz) Get a specific version of an item from the archivegetVersions(long persistenceId) List the versions available of an item.<T> voidsave(T item) Saves the an item that is persistable, and archived copy of the item is also stored
-
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:
savein interfaceuk.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:
deletein interfaceuk.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 theListableannotations applied to the method and fields of each items class i.e. different classes may return differing summaries that are contained in the sameSearchResult- Specified by:
getin interfaceuk.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.PersistenceExceptionFinds all items stored of a type using search parameters The search parameters are made from key value pairs ofListablevalue against the string value of theListablefield.- Specified by:
getin interfaceuk.ac.diamond.daq.application.persistence.service.PersistenceService- Type Parameters:
T- class- Parameters:
searchParameters- map of @Listable field name toStringvalue of the fieldclazz- 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:
getin interfaceuk.ac.diamond.daq.application.persistence.service.PersistenceService- Type Parameters:
T- base class of the item- Parameters:
persistenceId- id of the itemclazz- 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:
getVersionsin interfaceuk.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:
getArchivein interfaceuk.ac.diamond.daq.application.persistence.service.PersistenceService- Type Parameters:
T- base class of the item- Parameters:
persistenceId- id of the itemversion- version of the itemclazz- 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
-