Class AppValidityAuditStrategy

java.lang.Object
org.hibernate.envers.strategy.ValidityAuditStrategy
com.softslate.commerce.daos.core.AppValidityAuditStrategy
All Implemented Interfaces:
org.hibernate.envers.strategy.AuditStrategy

public class AppValidityAuditStrategy extends org.hibernate.envers.strategy.ValidityAuditStrategy
Override the default Envers ValidityAuditStrategy class that is responsible for updating the REVEND and REVEND_TSTMP fields in the previous audit log entry. In the default implementation distributed with Envers, if the prior record does not exist, a RuntimeException is thrown and the transaction can't complete. This class overrides that behavior to simply log the lack of a prior record. In effect, we are relaxing the behavior of the ValidityAuditStrategy class somewhat to avoid RuntimeExceptions, at the cost of not being quite as airtight with REVEND and REVEND_TSTMP. This will allow us to, for example, INSERT new records into the database without creating an audit log of the record at the same time. Envers will fail to update REVEND for that record because the prior audit log entry does not exist, but it won't stop transactions from taking place on the record. To revert to the regular Envers behavior, simply update hibernate.properties to use the super class: org.hibernate.envers.audit_strategy=org.hibernate.envers.strategy.ValidityAuditStrategy Note, due to private methods and inner classes, this class is copy of the super class, with the exception of the two RuntimeExceptions on lines 202 and 334, which are commented out and logged instead.
Author:
dtobey
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final org.jboss.logging.Logger
     
    private org.hibernate.property.Getter
    getter for the revision entity field annotated with @RevisionTimestamp
    private final org.hibernate.envers.internal.synchronization.SessionCacheCleaner
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addAssociationAtRevisionRestriction(org.hibernate.envers.internal.tools.query.QueryBuilder rootQueryBuilder, org.hibernate.envers.internal.tools.query.Parameters parameters, String revisionProperty, String revisionEndProperty, boolean addAlias, org.hibernate.envers.internal.entities.mapper.relation.MiddleIdData referencingIdData, String versionsMiddleEntityName, String eeOriginalIdPropertyPath, String revisionPropertyPath, String originalIdPropertyName, String alias1, boolean inclusive, org.hibernate.envers.internal.entities.mapper.relation.MiddleComponentData... componentDatas)
     
    private void
    addEndRevisionNullRestriction(org.hibernate.envers.configuration.spi.AuditConfiguration auditCfg, org.hibernate.envers.internal.tools.query.Parameters rootParameters)
     
    void
    addEntityAtRevisionRestriction(org.hibernate.envers.configuration.internal.GlobalConfiguration globalCfg, org.hibernate.envers.internal.tools.query.QueryBuilder rootQueryBuilder, org.hibernate.envers.internal.tools.query.Parameters parameters, String revisionProperty, String revisionEndProperty, boolean addAlias, org.hibernate.envers.internal.entities.mapper.relation.MiddleIdData idData, String revisionPropertyPath, String originalIdPropertyName, String alias1, String alias2, boolean inclusive)
     
    private void
    addRevisionRestriction(org.hibernate.envers.internal.tools.query.Parameters rootParameters, String revisionProperty, String revisionEndProperty, boolean addAlias, boolean inclusive)
     
    private Date
     
    private org.hibernate.persister.entity.Queryable
    getQueryable(String entityName, org.hibernate.engine.spi.SessionImplementor sessionImplementor)
     
    private org.hibernate.envers.RevisionType
    getRevisionType(org.hibernate.envers.configuration.spi.AuditConfiguration auditCfg, Object data)
     
    void
    perform(org.hibernate.Session session, String entityName, org.hibernate.envers.configuration.spi.AuditConfiguration auditCfg, Serializable id, Object data, Object revision)
     
    void
    performCollectionChange(org.hibernate.Session session, String entityName, String propertyName, org.hibernate.envers.configuration.spi.AuditConfiguration auditCfg, org.hibernate.envers.internal.entities.mapper.PersistentCollectionChangeData persistentCollectionChangeData, Object revision)
     
    void
    setRevisionTimestampGetter(org.hibernate.property.Getter revisionTimestampGetter)
     
    private void
    updateLastRevision(org.hibernate.Session session, org.hibernate.envers.configuration.spi.AuditConfiguration auditCfg, List<Object> l, Object id, String auditedEntityName, Object revision)
     

    Methods inherited from class java.lang.Object

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

    • log

      private static final org.jboss.logging.Logger log
    • revisionTimestampGetter

      private org.hibernate.property.Getter revisionTimestampGetter
      getter for the revision entity field annotated with @RevisionTimestamp
    • sessionCacheCleaner

      private final org.hibernate.envers.internal.synchronization.SessionCacheCleaner sessionCacheCleaner
  • Constructor Details

    • AppValidityAuditStrategy

      public AppValidityAuditStrategy()
  • Method Details

    • perform

      public void perform(org.hibernate.Session session, String entityName, org.hibernate.envers.configuration.spi.AuditConfiguration auditCfg, Serializable id, Object data, Object revision)
      Specified by:
      perform in interface org.hibernate.envers.strategy.AuditStrategy
      Overrides:
      perform in class org.hibernate.envers.strategy.ValidityAuditStrategy
    • getQueryable

      private org.hibernate.persister.entity.Queryable getQueryable(String entityName, org.hibernate.engine.spi.SessionImplementor sessionImplementor)
    • performCollectionChange

      public void performCollectionChange(org.hibernate.Session session, String entityName, String propertyName, org.hibernate.envers.configuration.spi.AuditConfiguration auditCfg, org.hibernate.envers.internal.entities.mapper.PersistentCollectionChangeData persistentCollectionChangeData, Object revision)
      Specified by:
      performCollectionChange in interface org.hibernate.envers.strategy.AuditStrategy
      Overrides:
      performCollectionChange in class org.hibernate.envers.strategy.ValidityAuditStrategy
    • addEndRevisionNullRestriction

      private void addEndRevisionNullRestriction(org.hibernate.envers.configuration.spi.AuditConfiguration auditCfg, org.hibernate.envers.internal.tools.query.Parameters rootParameters)
    • addEntityAtRevisionRestriction

      public void addEntityAtRevisionRestriction(org.hibernate.envers.configuration.internal.GlobalConfiguration globalCfg, org.hibernate.envers.internal.tools.query.QueryBuilder rootQueryBuilder, org.hibernate.envers.internal.tools.query.Parameters parameters, String revisionProperty, String revisionEndProperty, boolean addAlias, org.hibernate.envers.internal.entities.mapper.relation.MiddleIdData idData, String revisionPropertyPath, String originalIdPropertyName, String alias1, String alias2, boolean inclusive)
      Specified by:
      addEntityAtRevisionRestriction in interface org.hibernate.envers.strategy.AuditStrategy
      Overrides:
      addEntityAtRevisionRestriction in class org.hibernate.envers.strategy.ValidityAuditStrategy
    • addAssociationAtRevisionRestriction

      public void addAssociationAtRevisionRestriction(org.hibernate.envers.internal.tools.query.QueryBuilder rootQueryBuilder, org.hibernate.envers.internal.tools.query.Parameters parameters, String revisionProperty, String revisionEndProperty, boolean addAlias, org.hibernate.envers.internal.entities.mapper.relation.MiddleIdData referencingIdData, String versionsMiddleEntityName, String eeOriginalIdPropertyPath, String revisionPropertyPath, String originalIdPropertyName, String alias1, boolean inclusive, org.hibernate.envers.internal.entities.mapper.relation.MiddleComponentData... componentDatas)
      Specified by:
      addAssociationAtRevisionRestriction in interface org.hibernate.envers.strategy.AuditStrategy
      Overrides:
      addAssociationAtRevisionRestriction in class org.hibernate.envers.strategy.ValidityAuditStrategy
    • setRevisionTimestampGetter

      public void setRevisionTimestampGetter(org.hibernate.property.Getter revisionTimestampGetter)
      Overrides:
      setRevisionTimestampGetter in class org.hibernate.envers.strategy.ValidityAuditStrategy
    • addRevisionRestriction

      private void addRevisionRestriction(org.hibernate.envers.internal.tools.query.Parameters rootParameters, String revisionProperty, String revisionEndProperty, boolean addAlias, boolean inclusive)
    • getRevisionType

      private org.hibernate.envers.RevisionType getRevisionType(org.hibernate.envers.configuration.spi.AuditConfiguration auditCfg, Object data)
    • updateLastRevision

      private void updateLastRevision(org.hibernate.Session session, org.hibernate.envers.configuration.spi.AuditConfiguration auditCfg, List<Object> l, Object id, String auditedEntityName, Object revision)
    • convertRevEndTimestampToDate

      private Date convertRevEndTimestampToDate(Object revEndTimestampObj)