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
When creating a new entity, the validity from and modifier user fields will be written. When an entity is modified, the last record that was modified, will have its validity to field written, then a new record will be created, that will have the validity from and modifier user fields filled out. When deleting, the last modified record's deleter user and validity to fields will be written.

NullPointerException - If both the schema and prefix are null.

Since:
4.0
Author:
JBStrap
See Also:
  • HistoryPolicy
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    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 written
    static String
    Gets the name of the field, where the modifier user is written
    static String
    Gets the history schema name
    static String
    Gets the table name prefix
    static String
    Gets the name of the valid from field
    static String
    Gets the name of the valid to field
    void
    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

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • HistoryCustomizer

      public HistoryCustomizer()
  • Method Details

    • customize

      public void customize(org.eclipse.persistence.descriptors.ClassDescriptor descriptor)
      Specified by:
      customize in interface org.eclipse.persistence.config.DescriptorCustomizer
    • customize

      public void customize(org.eclipse.persistence.sessions.Session session) throws Exception
      Specified by:
      customize in interface org.eclipse.persistence.config.SessionCustomizer
      Throws:
      Exception
    • postMerge

      public void postMerge(org.eclipse.persistence.descriptors.DescriptorEvent event)
      Specified by:
      postMerge in interface org.eclipse.persistence.descriptors.DescriptorEventListener
      Overrides:
      postMerge in class org.eclipse.persistence.descriptors.DescriptorEventAdapter
    • preDelete

      public void preDelete(org.eclipse.persistence.descriptors.DescriptorEvent event)
      Specified by:
      preDelete in interface org.eclipse.persistence.descriptors.DescriptorEventListener
      Overrides:
      preDelete in class org.eclipse.persistence.descriptors.DescriptorEventAdapter
    • getSchema

      public static String getSchema()
      Gets the history schema name
      Returns:
      The database schema name
    • getTableNamePrefix

      public static String getTableNamePrefix()
      Gets the table name prefix
      Returns:
      The table name prefix
    • getValidFrom

      public static String getValidFrom()
      Gets the name of the valid from field
      Returns:
      The name of the valid from field
    • getValidTo

      public static String getValidTo()
      Gets the name of the valid to field
      Returns:
      The name of the valid to field
    • getDeleterUser

      public static String 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

      public static String 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