|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface SerializedObjectDAO
The SerializedObjectDAO is meant to be used as a means for persisting objects for which a typical relational table model is impractical. A typical example is for persisting multiple different user-configurable implementations of a particular interface. Because it is impossible to know what properties a given implementation will have and which will need to be persisted, it might be more practical to use serialization for this. Each available method for managing Serialized Objects on this class is available in two forms. The first form operates on OpenmrsObject instances directly, and isolates the consumer completely from the mechanics of Serialization. You pass in OpenmrsObjects and you get out OpenmrsObjects. For example:
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. }
Method Summary | ||
---|---|---|
|
convertSerializedObject(java.lang.Class<T> clazz,
SerializedObject serializedObject)
Converts a raw SerializedObject to an OpenmrsObject, using the appropriate Serializer |
|
|
getAllObjects(java.lang.Class<T> type)
Retrieves all non-retired objects of the passed type from the database that have been saved through serialization |
|
|
getAllObjects(java.lang.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 |
|
|
getAllObjectsByName(java.lang.Class<T> type,
java.lang.String name,
boolean exactMatchOnly)
Retrieves all objects from the database that match the passed type and name that have been saved through serialization |
|
java.util.List<SerializedObject> |
getAllSerializedObjects(java.lang.Class<?> type,
boolean includeRetired)
Retrieves all raw Serialized Object from the database that match the passed type and includeRetired flag |
|
java.util.List<SerializedObject> |
getAllSerializedObjectsByName(java.lang.Class<?> type,
java.lang.String name,
boolean exactMatchOnly)
Retrieves all raw Serialized Objects from the database that match the passed type and name |
|
|
getObject(java.lang.Class<T> type,
java.lang.Integer id)
Retrieves the saved object of the passed type from the database by it's id |
|
|
getObjectByUuid(java.lang.Class<T> type,
java.lang.String uuid)
Retrieves the saved object of the passed type from the database by it's uuid |
|
java.lang.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(java.lang.Integer id)
Retrieves the raw SerializedObject from the database by id |
|
SerializedObject |
getSerializedObjectByUuid(java.lang.String uuid)
Retrieves the raw Serialized Object from the database by uuid |
|
java.util.List<java.lang.Class<? extends OpenmrsObject>> |
getSupportedTypes()
|
|
void |
purgeObject(java.lang.Integer id)
Deletes the item from the database with the given primary key id |
|
void |
registerSupportedType(java.lang.Class<? extends OpenmrsObject> clazz)
Registers a class as one that should be supported |
|
|
saveObject(T object)
Saves an object to the database in serialized form |
|
|
saveObject(T object,
OpenmrsSerializer serializer)
Saves an object to the database, in serialized form, using the specified OpenmrsSerializer |
|
void |
unregisterSupportedType(java.lang.Class<? extends OpenmrsObject> clazz)
Removes this class as one that should be supported |
Method Detail |
---|
SerializedObject getSerializedObject(java.lang.Integer id) throws DAOException
id
- the id to lookup
DAOException
<T extends OpenmrsObject> T getObject(java.lang.Class<T> type, java.lang.Integer id) throws DAOException
type
- The class of the object to retrieveid
- The primary key id of the object to retrieve
DAOException
SerializedObject getSerializedObjectByUuid(java.lang.String uuid) throws DAOException
uuid
- The UUID of the object to retrieve
DAOException
<T extends OpenmrsObject> T getObjectByUuid(java.lang.Class<T> type, java.lang.String uuid) throws DAOException
type
- The class of the object to retrieveuuid
- The UUID of the object to retrieve
DAOException
<T extends OpenmrsObject> T saveObject(T object) throws DAOException
object
- The object to save
DAOException
<T extends OpenmrsObject> T saveObject(T object, OpenmrsSerializer serializer) throws DAOException
OpenmrsSerializer
object
- The object to saveserializer
- The OpenmrsSerializer
to use
DAOException
java.util.List<SerializedObject> getAllSerializedObjects(java.lang.Class<?> type, boolean includeRetired) throws DAOException
type
- The class of the object to retrieveincludeRetired
- if true includes retired/voided objects, otherwise does not
DAOException
<T extends OpenmrsObject> java.util.List<T> getAllObjects(java.lang.Class<T> type) throws DAOException
type
- The class of the object to retrieve
DAOException
<T extends OpenmrsObject> java.util.List<T> getAllObjects(java.lang.Class<T> type, boolean includeRetired) throws DAOException
type
- The class of the object to retrieveincludeRetired
- includeRetired If true, returns voided/retired objects as well
DAOException
java.util.List<SerializedObject> getAllSerializedObjectsByName(java.lang.Class<?> type, java.lang.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 matches
DAOException
<T extends OpenmrsMetadata> java.util.List<T> getAllObjectsByName(java.lang.Class<T> type, java.lang.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 matches
DAOException
<T extends OpenmrsObject> T convertSerializedObject(java.lang.Class<T> clazz, SerializedObject serializedObject) throws DAOException
clazz
- the OpenmrsObject class to retrieveserializedObject
- the raw SerializedObject to deserialize into an OpenmrsObject
DAOException
void purgeObject(java.lang.Integer id) throws DAOException
id
- The id of the item to delete from the database
DAOException
java.lang.Class<? extends OpenmrsObject> getRegisteredTypeForObject(OpenmrsObject object)
object
- The object to check for the registered type
java.util.List<java.lang.Class<? extends OpenmrsObject>> getSupportedTypes()
void registerSupportedType(java.lang.Class<? extends OpenmrsObject> clazz) throws DAOException
clazz
- The class to register
DAOException
void unregisterSupportedType(java.lang.Class<? extends OpenmrsObject> clazz) throws DAOException
clazz
- The class to un-register
DAOException
|
OpenMRS-1.7.x | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |