Package com.softslate.commerce.daos.core
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
Modifier and TypeFieldDescriptionprivate static final org.jboss.logging.Logger
private org.hibernate.property.Getter
getter for the revision entity field annotated with @RevisionTimestampprivate final org.hibernate.envers.internal.synchronization.SessionCacheCleaner
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
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
convertRevEndTimestampToDate
(Object revEndTimestampObj) 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)
-
Field Details
-
log
private static final org.jboss.logging.Logger log -
revisionTimestampGetter
private org.hibernate.property.Getter revisionTimestampGettergetter 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 interfaceorg.hibernate.envers.strategy.AuditStrategy
- Overrides:
perform
in classorg.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 interfaceorg.hibernate.envers.strategy.AuditStrategy
- Overrides:
performCollectionChange
in classorg.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 interfaceorg.hibernate.envers.strategy.AuditStrategy
- Overrides:
addEntityAtRevisionRestriction
in classorg.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 interfaceorg.hibernate.envers.strategy.AuditStrategy
- Overrides:
addAssociationAtRevisionRestriction
in classorg.hibernate.envers.strategy.ValidityAuditStrategy
-
setRevisionTimestampGetter
public void setRevisionTimestampGetter(org.hibernate.property.Getter revisionTimestampGetter) - Overrides:
setRevisionTimestampGetter
in classorg.hibernate.envers.strategy.ValidityAuditStrategy
-
addRevisionRestriction
-
getRevisionType
private org.hibernate.envers.RevisionType getRevisionType(org.hibernate.envers.configuration.spi.AuditConfiguration auditCfg, Object data) -
updateLastRevision
-
convertRevEndTimestampToDate
-