public interface SerializedObjectDAO
MyOpenmrsObject m = getObject(MyOpenmrsObject.class, 10);The second form operates on SerializedObject instances directly, and provides the consumer with more control over how to handle these SerializedObjects. A typical reason why this might be useful is to provide graceful failure in the event that a persisted Object has had an API change, and thus would fail to deserialize properly. In this case, the consumer can use something like the following:
MyOpenmrsObject m = null; SerializedObject s = getSerializedObject(10); try { m = convertSerializedObject(MyOpenmrsObject.class, s); } catch (Exception e) { // Handle this exception however you need to for your use case. }
Modifier and Type | Method and Description |
---|---|
<T extends OpenmrsObject> |
convertSerializedObject(Class<T> clazz,
SerializedObject serializedObject)
Converts a raw SerializedObject to an OpenmrsObject, using the appropriate Serializer
|
<T extends OpenmrsObject> |
getAllObjects(Class<T> type)
Retrieves all non-retired objects of the passed type from the database that have been saved through serialization
|
<T extends OpenmrsObject> |
getAllObjects(Class<T> type,
boolean includeRetired)
Retrieves all objects from the database that match the passed type that have been saved through serialization
Returns voided / retired Objects only if includeRetired parameter is true
|
<T extends OpenmrsMetadata> |
getAllObjectsByName(Class<T> type,
String name,
boolean exactMatchOnly)
Retrieves all objects from the database that match the passed type and name that have been saved through serialization
|
List<SerializedObject> |
getAllSerializedObjects(Class<?> type,
boolean includeRetired)
Retrieves all raw Serialized Object from the database that match the passed type and includeRetired flag
|
List<SerializedObject> |
getAllSerializedObjectsByName(Class<?> type,
String name,
boolean exactMatchOnly)
Retrieves all raw Serialized Objects from the database that match the passed type and name
|
<T extends OpenmrsObject> |
getObject(Class<T> type,
Integer id)
Retrieves the saved object of the passed type from the database by it's id
|
<T extends OpenmrsObject> |
getObjectByUuid(Class<T> type,
String uuid)
Retrieves the saved object of the passed type from the database by it's uuid
|
Class<? extends OpenmrsObject> |
getRegisteredTypeForObject(OpenmrsObject object)
Returns the registered class for the passed object, or null if none found For example, if the
supportedTypes property contains the CohortDefinition.class interface, and a particular
implementation of that interface is passed in, then this method would return
CohortDefinition.class.
|
SerializedObject |
getSerializedObject(Integer id)
Retrieves the raw SerializedObject from the database by id
|
SerializedObject |
getSerializedObjectByUuid(String uuid)
Retrieves the raw Serialized Object from the database by uuid
|
List<Class<? extends OpenmrsObject>> |
getSupportedTypes() |
void |
purgeObject(Integer id)
Deletes the item from the database with the given primary key id
|
void |
registerSupportedType(Class<? extends OpenmrsObject> clazz)
Registers a class as one that should be supported
|
<T extends OpenmrsObject> |
saveObject(T object)
Saves an object to the database in serialized form
|
<T extends OpenmrsObject> |
saveObject(T object,
OpenmrsSerializer serializer)
Saves an object to the database, in serialized form, using the specified
OpenmrsSerializer |
void |
unregisterSupportedType(Class<? extends OpenmrsObject> clazz)
Removes this class as one that should be supported
|
SerializedObject getSerializedObject(Integer id) throws DAOException
id
- the id to lookupDAOException
<T extends OpenmrsObject> T getObject(Class<T> type, Integer id) throws DAOException
type
- The class of the object to retrieveid
- The primary key id of the object to retrieveDAOException
SerializedObject getSerializedObjectByUuid(String uuid) throws DAOException
uuid
- The UUID of the object to retrieveDAOException
<T extends OpenmrsObject> T getObjectByUuid(Class<T> type, String uuid) throws DAOException
type
- The class of the object to retrieveuuid
- The UUID of the object to retrieveDAOException
<T extends OpenmrsObject> T saveObject(T object) throws DAOException
object
- The object to saveDAOException
<T extends OpenmrsObject> T saveObject(T object, OpenmrsSerializer serializer) throws DAOException
OpenmrsSerializer
object
- The object to saveserializer
- The OpenmrsSerializer
to useDAOException
List<SerializedObject> getAllSerializedObjects(Class<?> type, boolean includeRetired) throws DAOException
type
- The class of the object to retrieveincludeRetired
- if true includes retired/voided objects, otherwise does notDAOException
<T extends OpenmrsObject> List<T> getAllObjects(Class<T> type) throws DAOException
type
- The class of the object to retrieveDAOException
<T extends OpenmrsObject> List<T> getAllObjects(Class<T> type, boolean includeRetired) throws DAOException
type
- The class of the object to retrieveincludeRetired
- includeRetired If true, returns voided/retired objects as wellDAOException
List<SerializedObject> getAllSerializedObjectsByName(Class<?> type, String name, boolean exactMatchOnly) throws DAOException
type
- The class of the object to retrievename
- the name of the item to retrieveexactMatchOnly
- if true will only return exact matchesDAOException
<T extends OpenmrsMetadata> List<T> getAllObjectsByName(Class<T> type, String name, boolean exactMatchOnly) throws DAOException
type
- The class of the object to retrievename
- the name of the item to retrieveexactMatchOnly
- if true will only return exact matchesDAOException
<T extends OpenmrsObject> T convertSerializedObject(Class<T> clazz, SerializedObject serializedObject) throws DAOException
clazz
- the OpenmrsObject class to retrieveserializedObject
- the raw SerializedObject to deserialize into an OpenmrsObjectDAOException
void purgeObject(Integer id) throws DAOException
id
- The id of the item to delete from the databaseDAOException
Class<? extends OpenmrsObject> getRegisteredTypeForObject(OpenmrsObject object)
object
- The object to check for the registered typeList<Class<? extends OpenmrsObject>> getSupportedTypes()
void registerSupportedType(Class<? extends OpenmrsObject> clazz) throws DAOException
clazz
- The class to registerDAOException
void unregisterSupportedType(Class<? extends OpenmrsObject> clazz) throws DAOException
clazz
- The class to un-registerDAOException
Copyright © 2018 OpenMRS LLC.. All Rights Reserved.