Package de.esoco.history
Klasse HistoryManager
java.lang.Object
de.esoco.history.HistoryManager
This class contains static methods to query, create, and manipulate history
records. The manipulation methods like
begin(Entity, Entity, String)
are thread-based, i.e. they record history entries based on the invoking
thread.-
Feldübersicht
Modifizierer und TypFeldBeschreibungstatic final String
The key for the default templates inHISTORY_NOTE_TEMPLATES
.static final org.obrel.core.RelationType
<Boolean> A flag relation type that marks objects which create history records.A configuration extra attribute that contains mapping from process names to templates for history notes. -
Methodenübersicht
Modifizierer und TypMethodeBeschreibungstatic void
Begins a new group of history records for the current thread.static void
commit
(boolean keepIfEmpty) Commits a group of history records.static List
<HistoryRecord> getHistoryFor
(Entity target, HistoryRecord.HistoryType type) Returns the history entries for a target object that have a certain type.static List
<HistoryRecord> getHistoryFor
(Entity target, HistoryRecord.HistoryType type, Date fromDate, Date toDate, Entity origin) Returns the history entries for a target object.static de.esoco.storage.Storage
Returns the storage instance that will be used by history operations from the current (= invoking) thread to access history records.static void
init()
This method should be invoked at application startup to initialize the history functionality.static boolean
Allows to check whether a history is recorded for the current thread.static void
record
(HistoryRecord.HistoryType type, Entity origin, Entity target, Entity rootTarget, String value, HistoryRecord.ReferenceType referenceType, String referenceValue) Records a history entry with a reference value.static void
record
(HistoryRecord.HistoryType type, Entity origin, Entity target, String value) Records a history entry.static void
rollback()
Cancels any currently active hierarchy of history records and discards it.static void
shutdown()
Performs a shutdown of the history manager and frees all allocated resources.
-
Felddetails
-
DEFAULT_HISTORY_NOTE_TEMPLATES
The key for the default templates inHISTORY_NOTE_TEMPLATES
.- Siehe auch:
-
HISTORIZED
A flag relation type that marks objects which create history records. This can be used as a hint to wrap it in a history group if necessary. -
HISTORY_NOTE_TEMPLATES
A configuration extra attribute that contains mapping from process names to templates for history notes. The map values must be in the form "[Template]\n[Template]\n..." where each template must have the format "[Title]|[Text]". [Title] must not contain linefeeds or other control characters and preferably only text to prevent parsing errors of the extra attribute. If the [Text] part needs to contain linefeeds they must be escaped as '$n'.The map key is either the name of the process in which the templates should be applied or the string
DEFAULT_HISTORY_NOTE_TEMPLATES
for which the value contains the default templates that are always available.
-
-
Methodendetails
-
begin
Begins a new group of history records for the current thread. The topmost group and all it's children will be made persistent when a matching call tocommit(boolean)
is made. A call to therollback()
method will cancel the complete history group hierarchy.- Parameter:
origin
- The entity from which the record originates (may be NULL)target
- The target entity referenced by the record (may be NULL)value
- The value of this record
-
commit
public static void commit(boolean keepIfEmpty) throws de.esoco.lib.manage.TransactionException Commits a group of history records. The group must previously have been started with a call tobegin(Entity, Entity, String)
.- Parameter:
keepIfEmpty
- TRUE to keep empty groups, FALSE to discard them- Löst aus:
de.esoco.lib.manage.TransactionException
- If storing the group fails
-
getHistoryFor
public static List<HistoryRecord> getHistoryFor(Entity target, HistoryRecord.HistoryType type) throws de.esoco.storage.StorageException Returns the history entries for a target object that have a certain type.- Parameter:
target
- The target entity to search records fortype
- The type of the history records to query or NULL- Gibt zurück:
- A list of history records that match the given criteria (may be empty but will never be NULL)
- Löst aus:
de.esoco.storage.StorageException
- If querying the history storage failsIllegalArgumentException
- If the target entity is NULL- Siehe auch:
-
getHistoryFor
public static List<HistoryRecord> getHistoryFor(Entity target, HistoryRecord.HistoryType type, Date fromDate, Date toDate, Entity origin) throws de.esoco.storage.StorageException Returns the history entries for a target object. The returned records can optionally be constrained to certain criteria. Criteria that are NULL will be ignored.- Parameter:
target
- The target entity to search records fortype
- The type of the history records to query or NULLfromDate
- The start date for the queried records or NULLtoDate
- The end date for the queried records or NULLorigin
- The origin entity to search records for or NULL- Gibt zurück:
- A list of history records that match the given criteria (may be empty but will never be NULL)
- Löst aus:
de.esoco.storage.StorageException
- If querying the history storage failsIllegalArgumentException
- If the target entity is NULL
-
getHistoryStorage
public static de.esoco.storage.Storage getHistoryStorage() throws de.esoco.storage.StorageExceptionReturns the storage instance that will be used by history operations from the current (= invoking) thread to access history records. When the returned storage instance is no longer needed, the calling code must invoke the methodStorage.release()
to free the storage resources. See the methodStorageManager.getStorage(Object)
for details.This method is intended mainly for internal use by the history implementation but it may also be used by special application code which needs to access the history storage and is therefore public. Applications should be careful when manipulating the history storage, especially when invoking
Storage.commit()
orStorage.rollback()
. Furthermore, if no history operations have been performed by the current thread before, the invocation may create a new storage instance and thus acquire system resources.- Gibt zurück:
- The history storage instance for the current thread
- Löst aus:
de.esoco.storage.StorageException
- If acquiring a new storage instance fails
-
init
public static void init()This method should be invoked at application startup to initialize the history functionality. -
isRecording
public static boolean isRecording()Allows to check whether a history is recorded for the current thread.- Gibt zurück:
- The recording
-
record
public static void record(HistoryRecord.HistoryType type, Entity origin, Entity target, String value) throws de.esoco.lib.manage.TransactionException Records a history entry. If a history group has been started before by means ofbegin(Entity, Entity, String)
the new entry will be added as a detail record to that group. If no group is active a single history record will be created and stored immediately.- Parameter:
type
- The type of the new history recordorigin
- The entity from which the record originates (may be NULL)target
- The target entity referenced by the record (may be NULL)value
- The value of this record- Löst aus:
de.esoco.lib.manage.TransactionException
- If storing the new record fails
-
record
public static void record(HistoryRecord.HistoryType type, Entity origin, Entity target, Entity rootTarget, String value, HistoryRecord.ReferenceType referenceType, String referenceValue) throws de.esoco.lib.manage.TransactionException Records a history entry with a reference value. If a history group has been started before by means ofbegin(Entity, Entity, String)
the new entry will be added as a detail record to that group. If no group is active a single history record will be created and stored immediately.- Parameter:
type
- The type of the new history recordorigin
- The entity from which the record originates (may be NULL)target
- The target entity referenced by the record (may be NULL)rootTarget
- The root target entity of the record (may be NULL, will be ignored if a group is active)value
- The value of this recordreferenceType
- The type of the reference valuereferenceValue
- The reference value- Löst aus:
de.esoco.lib.manage.TransactionException
- If storing the new record fails
-
rollback
public static void rollback()Cancels any currently active hierarchy of history records and discards it. This method must be invoked when an exception occurs after a history group has been started withbegin(Entity, Entity, String)
to remove any remaining history group for the current thread. Additional invocations of this method will be ignored. -
shutdown
public static void shutdown()Performs a shutdown of the history manager and frees all allocated resources.
-