Class HistoryCustomizer
java.lang.Object
org.eclipse.persistence.descriptors.DescriptorEventAdapter
com.jbstrap.core.dao.base.history.HistoryCustomizer
- All Implemented Interfaces:
EventListener
,org.eclipse.persistence.config.DescriptorCustomizer
,org.eclipse.persistence.config.SessionCustomizer
,org.eclipse.persistence.descriptors.DescriptorEventListener
public class HistoryCustomizer
extends org.eclipse.persistence.descriptors.DescriptorEventAdapter
implements org.eclipse.persistence.config.DescriptorCustomizer, org.eclipse.persistence.config.SessionCustomizer
JBStrap enables you to write the entire persistence history. With the help of it, the record's complete history can be followed on the database side.
To write the history, the use of the @Customizer(HistoryCustomizer.class)
annotation must be used on the entity.
To write the history, some parameters need to be set. The values can be set through message sources. Where the
field name must be specified, the database field name must be used, not the entity field name.
Parameters:
- Schema: The history schema used by the database. It can be changed, but then it won't be able to write to another Database (not required).
Message source key: hist.schema - Table name prefix: History table name prefix. Same with every history table.
(not required).
Message source key: hist.table.name.prefix - Valid from: In the history record, there is a validity from field. This marks when the record was created.
Message source key: hist.valid.from - Valid to: In the history record, there is a validity to field. This marks when the record was deleted or modified.
Message source key: hist.valid.to - Deleter user: If the entity was deleted, the name of the user who deleted it will be recorded
Message source key: hist.delete.user - Modifier user: If the entity was modified, or if a new entity is saved, the name of the logged in user will be recorded
Message source key: hist.modifier.user - Domain uuid field name: This parameter specifies the field which passes the user's uuid to the history. A transient (@Transient) field with the name specified
here must be included in the entity. The entity has a @Customizer(HistoryCustomizer.class) annotation. If this parameter is not specified in the property
file or there are no transient fields in the entity, then the fields specified in the hist.deleter.user and hist.modifier.user parameters are left
empty in the table's associated history entity.
Message source key: hist.domain.uuid.fieldName
NullPointerException - If both the schema and prefix are null
.
- Since:
- 4.0
- Author:
- JBStrap
- See Also:
-
HistoryPolicy
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
customize
(org.eclipse.persistence.descriptors.ClassDescriptor descriptor) void
customize
(org.eclipse.persistence.sessions.Session session) static String
Gets the name of the field, where the deleter user is writtenstatic String
Gets the name of the field, where the modifier user is writtenstatic String
Gets the history schema namestatic String
Gets the table name prefixstatic String
Gets the name of the valid from fieldstatic String
Gets the name of the valid to fieldvoid
postMerge
(org.eclipse.persistence.descriptors.DescriptorEvent event) void
preDelete
(org.eclipse.persistence.descriptors.DescriptorEvent event) Methods inherited from class org.eclipse.persistence.descriptors.DescriptorEventAdapter
aboutToDelete, aboutToInsert, aboutToUpdate, isOverriddenEvent, postBuild, postClone, postDelete, postInsert, postRefresh, postUpdate, postWrite, preInsert, prePersist, preRemove, preUpdate, preUpdateWithChanges, preWrite
-
Constructor Details
-
HistoryCustomizer
public HistoryCustomizer()
-
-
Method Details
-
customize
public void customize(org.eclipse.persistence.descriptors.ClassDescriptor descriptor) - Specified by:
customize
in interfaceorg.eclipse.persistence.config.DescriptorCustomizer
-
customize
- Specified by:
customize
in interfaceorg.eclipse.persistence.config.SessionCustomizer
- Throws:
Exception
-
postMerge
public void postMerge(org.eclipse.persistence.descriptors.DescriptorEvent event) - Specified by:
postMerge
in interfaceorg.eclipse.persistence.descriptors.DescriptorEventListener
- Overrides:
postMerge
in classorg.eclipse.persistence.descriptors.DescriptorEventAdapter
-
preDelete
public void preDelete(org.eclipse.persistence.descriptors.DescriptorEvent event) - Specified by:
preDelete
in interfaceorg.eclipse.persistence.descriptors.DescriptorEventListener
- Overrides:
preDelete
in classorg.eclipse.persistence.descriptors.DescriptorEventAdapter
-
getSchema
Gets the history schema name- Returns:
- The database schema name
-
getTableNamePrefix
Gets the table name prefix- Returns:
- The table name prefix
-
getValidFrom
Gets the name of the valid from field- Returns:
- The name of the valid from field
-
getValidTo
Gets the name of the valid to field- Returns:
- The name of the valid to field
-
getDeleterUser
Gets the name of the field, where the deleter user is written- Returns:
- The name of the field, where the deleter user is written
-
getModifierUser
Gets the name of the field, where the modifier user is written- Returns:
- The name of the field, where the modifier user is written
-