alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Hibernate example source code file (AuditStrategy.java)

This example Hibernate source code file (AuditStrategy.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Hibernate tags/keywords

auditconfiguration, auditconfiguration, auditstrategy, io, middlecomponentdata, middleiddata, middleiddata, object, object, persistentcollectionchangedata, querybuilder, serializable, string, string

The Hibernate AuditStrategy.java source code

package org.hibernate.envers.strategy;
import java.io.Serializable;
import org.hibernate.Session;
import org.hibernate.envers.configuration.AuditConfiguration;
import org.hibernate.envers.configuration.GlobalConfiguration;
import org.hibernate.envers.entities.mapper.PersistentCollectionChangeData;
import org.hibernate.envers.entities.mapper.relation.MiddleComponentData;
import org.hibernate.envers.entities.mapper.relation.MiddleIdData;
import org.hibernate.envers.tools.query.QueryBuilder;

/**
 * Behaviours of different audit strategy for populating audit data.
 * 
 * @author Stephanie Pau
 * @author Adam Warski (adam at warski dot org)
 */
public interface AuditStrategy {
    /**
     * Perform the persistence of audited data for regular entities.
     * 
     * @param session Session, which can be used to persist the data.
     * @param entityName Name of the entity, in which the audited change happens
     * @param auditCfg Audit configuration
     * @param id Id of the entity.
     * @param data Audit data to persist
     * @param revision Current revision data
     */
    void perform(Session session, String entityName, AuditConfiguration auditCfg, Serializable id, Object data,
                 Object revision);

    /**
     * Perform the persistence of audited data for collection ("middle") entities.
     *
     * @param session Session, which can be used to persist the data.
     * @param auditCfg Audit configuration
     * @param persistentCollectionChangeData Collection change data to be persisted.
     * @param revision Current revision data
     */
    void performCollectionChange(Session session, AuditConfiguration auditCfg,
                                 PersistentCollectionChangeData persistentCollectionChangeData, Object revision);
    

    /**
	 * 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:
	 * <ul>
	 * <li>For {@link DefaultAuditStrategy} a subquery is created: 
	 * <p>e.revision = (SELECT max(...) ...)

* </li> * <li>for {@link ValidityAuditStrategy} the revision-end column is used: * <p>e.revision <= :revision and (e.endRevision > :revision or e.endRevision is null)

* </li> * </ul> * * @param globalCfg the {@link GlobalConfiguration} * @param rootQueryBuilder the {@link QueryBuilder} that will be updated * @param revisionProperty property of the revision column * @param revisionEndProperty property of the revisionEnd column (only used for {@link ValidityAuditStrategy}) * @param addAlias {@code boolean} indicator if a left alias is needed * @param idData id-information for the two-entity relation (only used for {@link DefaultAuditStrategy}) * @param revisionPropertyPath path of the revision property (only used for {@link ValidityAuditStrategy}) * @param originalIdPropertyName name of the id property (only used for {@link ValidityAuditStrategy}) * @param alias1 an alias used for subquery (only used for {@link ValidityAuditStrategy}) * @param alias2 an alias used for subquery (only used for {@link ValidityAuditStrategy}) */ void addEntityAtRevisionRestriction(GlobalConfiguration globalCfg, QueryBuilder rootQueryBuilder, String revisionProperty, String revisionEndProperty, boolean addAlias, MiddleIdData idData, String revisionPropertyPath, String originalIdPropertyName, String alias1, String alias2); /** * 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: * <ul> * <li>For {@link DefaultAuditStrategy} a subquery is created: * <p>e.revision = (SELECT max(...) ...)

* </li> * <li>for {@link ValidityAuditStrategy} the revision-end column is used: * <p>e.revision <= :revision and (e.endRevision > :revision or e.endRevision is null)

* </li> * </ul> * * @param rootQueryBuilder the {@link QueryBuilder} that will be updated * @param revisionProperty property of the revision column * @param revisionEndProperty property of the revisionEnd column (only used for {@link ValidityAuditStrategy}) * @param addAlias {@code boolean} indicator if a left alias is needed * @param referencingIdData id-information for the middle-entity association (only used for {@link DefaultAuditStrategy}) * @param versionsMiddleEntityName name of the middle-entity * @param eeOriginalIdPropertyPath name of the id property (only used for {@link ValidityAuditStrategy}) * @param revisionPropertyPath path of the revision property (only used for {@link ValidityAuditStrategy}) * @param originalIdPropertyName name of the id property (only used for {@link ValidityAuditStrategy}) * @param componentDatas information about the middle-entity relation */ void addAssociationAtRevisionRestriction(QueryBuilder rootQueryBuilder, String revisionProperty, String revisionEndProperty, boolean addAlias, MiddleIdData referencingIdData, String versionsMiddleEntityName, String eeOriginalIdPropertyPath, String revisionPropertyPath, String originalIdPropertyName, MiddleComponentData... componentDatas); }

Other Hibernate examples (source code examples)

Here is a short list of links related to this Hibernate AuditStrategy.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.