Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package org.hibernate.envers.strategy;
import static org.hibernate.envers.entities.mapper.relation.query.QueryConstants.*;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.hibernate.LockOptions;
import org.hibernate.Session;
import org.hibernate.envers.RevisionType;
import org.hibernate.envers.configuration.AuditConfiguration;
import org.hibernate.envers.configuration.AuditEntitiesConfiguration;
import org.hibernate.envers.configuration.GlobalConfiguration;
import org.hibernate.envers.entities.mapper.PersistentCollectionChangeData;
import org.hibernate.envers.entities.mapper.id.IdMapper;
import org.hibernate.envers.entities.mapper.relation.MiddleComponentData;
import org.hibernate.envers.entities.mapper.relation.MiddleIdData;
import org.hibernate.envers.synchronization.SessionCacheCleaner;
import org.hibernate.envers.tools.query.Parameters;
import org.hibernate.envers.tools.query.QueryBuilder;
import org.hibernate.property.Getter;
/**
* 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
*
*
*
* @author Stephanie Pau
* @author Adam Warski (adam at warski dot org)
*/
public class ValidityAuditStrategy implements AuditStrategy {
/** getter for the revision entity field annotated with @RevisionTimestamp */
private Getter revisionTimestampGetter = null;
private final SessionCacheCleaner sessionCacheCleaner;
public ValidityAuditStrategy() {
sessionCacheCleaner = new SessionCacheCleaner();
}
public void perform(Session session, String entityName, AuditConfiguration auditCfg, Serializable id, Object data,
Object revision) {
AuditEntitiesConfiguration audEntCfg = auditCfg.getAuditEntCfg();
String auditedEntityName = audEntCfg.getAuditEntityName(entityName);
// Update the end date of the previous row if this operation is expected to have a previous row
if (getRevisionType(auditCfg, data) != RevisionType.ADD) {
/*
Constructing a query:
select e from audited_ent e where e.end_rev is null and e.id = :id
*/
QueryBuilder qb = new QueryBuilder(auditedEntityName, MIDDLE_ENTITY_ALIAS);
// e.id = :id
IdMapper idMapper = auditCfg.getEntCfg().get(entityName).getIdMapper();
idMapper.addIdEqualsToQuery(qb.getRootParameters(), id, auditCfg.getAuditEntCfg().getOriginalIdPropName(), true);
addEndRevisionNullRestriction(auditCfg, qb);
@SuppressWarnings({"unchecked"})
List