Class ValidityAuditStrategy

  • All Implemented Interfaces:
    AuditStrategy

    public class ValidityAuditStrategy
    extends java.lang.Object
    implements AuditStrategy
    Audit strategy which persists and retrieves audit information using a validity algorithm, based on the start-revision and end-revision of a row in the audit tables.

    This algorithm works as follows:

    • For a new row that is persisted in an audit table, only the start-revision column of that row is set
    • At the same time the end-revision field of the previous audit row is set to this revision
    • Queries are retrieved using 'between start and end revision', instead of a subquery.

    This has a few important consequences that need to be judged against against each other:

    • Persisting audit information is a bit slower, because an extra row is updated
    • Retrieving audit information is a lot faster

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addAssociationAtRevisionRestriction​(org.hibernate.envers.internal.tools.query.QueryBuilder rootQueryBuilder, org.hibernate.envers.internal.tools.query.Parameters parameters, java.lang.String revisionProperty, java.lang.String revisionEndProperty, boolean addAlias, org.hibernate.envers.internal.entities.mapper.relation.MiddleIdData referencingIdData, java.lang.String versionsMiddleEntityName, java.lang.String eeOriginalIdPropertyPath, java.lang.String revisionPropertyPath, java.lang.String originalIdPropertyName, java.lang.String alias1, boolean inclusive, org.hibernate.envers.internal.entities.mapper.relation.MiddleComponentData... componentDatas)
      Update the rootQueryBuilder with an extra WHERE clause to restrict the revision for a middle-entity association.
      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, java.lang.String revisionProperty, java.lang.String revisionEndProperty, boolean addAlias, org.hibernate.envers.internal.entities.mapper.relation.MiddleIdData idData, java.lang.String revisionPropertyPath, java.lang.String originalIdPropertyName, java.lang.String alias1, java.lang.String alias2, boolean inclusive)
      Update the rootQueryBuilder with an extra WHERE clause to restrict the revision for a two-entity relation.
      void perform​(org.hibernate.Session session, java.lang.String entityName, org.hibernate.envers.configuration.internal.AuditEntitiesConfiguration audEntitiesCfg, java.io.Serializable id, java.lang.Object data, java.lang.Object revision)
      Perform the persistence of audited data for regular entities.
      void performCollectionChange​(org.hibernate.Session session, java.lang.String entityName, java.lang.String propertyName, org.hibernate.envers.configuration.internal.AuditEntitiesConfiguration auditEntitiesConfiguration, org.hibernate.envers.internal.entities.mapper.PersistentCollectionChangeData persistentCollectionChangeData, java.lang.Object revision)
      Perform the persistence of audited data for collection ("middle") entities.
      void setRevisionTimestampGetter​(org.hibernate.property.access.spi.Getter revisionTimestampGetter)  
      • Methods inherited from class java.lang.Object

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

      • ValidityAuditStrategy

        public ValidityAuditStrategy()
    • Method Detail

      • perform

        public void perform​(org.hibernate.Session session,
                            java.lang.String entityName,
                            org.hibernate.envers.configuration.internal.AuditEntitiesConfiguration audEntitiesCfg,
                            java.io.Serializable id,
                            java.lang.Object data,
                            java.lang.Object revision)
        Description copied from interface: AuditStrategy
        Perform the persistence of audited data for regular entities.
        Specified by:
        perform in interface AuditStrategy
        Parameters:
        session - Session, which can be used to persist the data.
        entityName - Name of the entity, in which the audited change happens
        audEntitiesCfg - The audit entity configuration.
        id - Id of the entity.
        data - Audit data to persist.
        revision - Current revision data.
      • performCollectionChange

        public void performCollectionChange​(org.hibernate.Session session,
                                            java.lang.String entityName,
                                            java.lang.String propertyName,
                                            org.hibernate.envers.configuration.internal.AuditEntitiesConfiguration auditEntitiesConfiguration,
                                            org.hibernate.envers.internal.entities.mapper.PersistentCollectionChangeData persistentCollectionChangeData,
                                            java.lang.Object revision)
        Description copied from interface: AuditStrategy
        Perform the persistence of audited data for collection ("middle") entities.
        Specified by:
        performCollectionChange in interface AuditStrategy
        Parameters:
        session - Session, which can be used to persist the data.
        entityName - Name of the entity, in which the audited change happens.
        propertyName - The name of the property holding the persistent collection
        auditEntitiesConfiguration - audit entity configuration
        persistentCollectionChangeData - Collection change data to be persisted.
        revision - Current revision data
      • 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,
                                                   java.lang.String revisionProperty,
                                                   java.lang.String revisionEndProperty,
                                                   boolean addAlias,
                                                   org.hibernate.envers.internal.entities.mapper.relation.MiddleIdData idData,
                                                   java.lang.String revisionPropertyPath,
                                                   java.lang.String originalIdPropertyName,
                                                   java.lang.String alias1,
                                                   java.lang.String alias2,
                                                   boolean inclusive)
        Description copied from interface: AuditStrategy
        Update the rootQueryBuilder with an extra WHERE clause to restrict the revision for a two-entity relation. This WHERE clause depends on the AuditStrategy, as follows:
        • For DefaultAuditStrategy a subquery is created:

          e.revision = (SELECT max(...) ...)

        • for ValidityAuditStrategy the revision-end column is used:

          e.revision <= :revision and (e.endRevision > :revision or e.endRevision is null)

        Specified by:
        addEntityAtRevisionRestriction in interface AuditStrategy
        Parameters:
        globalCfg - the GlobalConfiguration
        rootQueryBuilder - the QueryBuilder that will be updated
        parameters - root parameters to which restrictions shall be added
        revisionProperty - property of the revision column
        revisionEndProperty - property of the revisionEnd column (only used for ValidityAuditStrategy)
        addAlias - boolean indicator if a left alias is needed
        idData - id-information for the two-entity relation (only used for DefaultAuditStrategy)
        revisionPropertyPath - path of the revision property (only used for ValidityAuditStrategy)
        originalIdPropertyName - name of the id property (only used for ValidityAuditStrategy)
        alias1 - an alias used for subquery (only used for ValidityAuditStrategy)
        alias2 - an alias used for subquery (only used for ValidityAuditStrategy)
        inclusive - indicates whether revision number shall be treated as inclusive or exclusive
      • addAssociationAtRevisionRestriction

        public void addAssociationAtRevisionRestriction​(org.hibernate.envers.internal.tools.query.QueryBuilder rootQueryBuilder,
                                                        org.hibernate.envers.internal.tools.query.Parameters parameters,
                                                        java.lang.String revisionProperty,
                                                        java.lang.String revisionEndProperty,
                                                        boolean addAlias,
                                                        org.hibernate.envers.internal.entities.mapper.relation.MiddleIdData referencingIdData,
                                                        java.lang.String versionsMiddleEntityName,
                                                        java.lang.String eeOriginalIdPropertyPath,
                                                        java.lang.String revisionPropertyPath,
                                                        java.lang.String originalIdPropertyName,
                                                        java.lang.String alias1,
                                                        boolean inclusive,
                                                        org.hibernate.envers.internal.entities.mapper.relation.MiddleComponentData... componentDatas)
        Description copied from interface: AuditStrategy
        Update the rootQueryBuilder with an extra WHERE clause to restrict the revision for a middle-entity association. This WHERE clause depends on the AuditStrategy, as follows:
        • For DefaultAuditStrategy a subquery is created:

          e.revision = (SELECT max(...) ...)

        • for ValidityAuditStrategy the revision-end column is used:

          e.revision <= :revision and (e.endRevision > :revision or e.endRevision is null)

        Specified by:
        addAssociationAtRevisionRestriction in interface AuditStrategy
        Parameters:
        rootQueryBuilder - the QueryBuilder that will be updated
        parameters - root parameters to which restrictions shall be added
        revisionProperty - property of the revision column
        revisionEndProperty - property of the revisionEnd column (only used for ValidityAuditStrategy)
        addAlias - boolean indicator if a left alias is needed
        referencingIdData - id-information for the middle-entity association (only used for DefaultAuditStrategy)
        versionsMiddleEntityName - name of the middle-entity
        eeOriginalIdPropertyPath - name of the id property (only used for ValidityAuditStrategy)
        revisionPropertyPath - path of the revision property (only used for ValidityAuditStrategy)
        originalIdPropertyName - name of the id property (only used for ValidityAuditStrategy)
        alias1 - an alias used for subqueries (only used for DefaultAuditStrategy)
        inclusive - indicates whether revision number shall be treated as inclusive or exclusive
        componentDatas - information about the middle-entity relation
      • setRevisionTimestampGetter

        public void setRevisionTimestampGetter​(org.hibernate.property.access.spi.Getter revisionTimestampGetter)