diff --git a/documentation/src/main/docbook/devguide/en-US/Envers.xml b/documentation/src/main/docbook/devguide/en-US/Envers.xml index c728304c53..14c666ec60 100644 --- a/documentation/src/main/docbook/devguide/en-US/Envers.xml +++ b/documentation/src/main/docbook/devguide/en-US/Envers.xml @@ -16,7 +16,7 @@ which can be used to identify groups of changes (much like a change set in source control). As the revisions are global, having a revision number, you can query for various entities at that revision, retrieving a (partial) view of the database at that revision. You can find a revision number having a date, and the other - way round, you can get the date at which a revision was committed. Since version 4, Envers enables user + way round, you can get the date at which a revision was committed. Since version 4.0, Envers enables you to retrieve all changes performed in a certain revision. @@ -531,7 +531,7 @@ public class AnnotatedTrackingRevisionEntity { - Custom implementation of tracking entity classes modified in revision + Custom implementation of tracking entity classes modified during revisions CustomEntityTrackingRevisionListener.java Querying for entities modified in a given revision - The basic query allows retrieving entity classes modified in a specified revision: + The basic query allows retrieving entity types changed in a specified revision: - modifiedEntities = getAuditReader() + modifiedEntityTypes = getAuditReader() .findEntityTypesChangedInRevision(revisionNumber);]]> Other queries (accessible from org.hibernate.envers.AuditReader): @@ -816,7 +816,7 @@ query.add(AuditEntity.relatedId("address").eq(relatedEntityId));]]> Note that methods described above can be legally used only when default mechanism of - tracking changed entity classes is enabled (see ). + tracking changed entity types is enabled (see ). diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/AuditReader.java b/hibernate-envers/src/main/java/org/hibernate/envers/AuditReader.java index 39bb8ea3c5..2adf928578 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/AuditReader.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/AuditReader.java @@ -191,7 +191,7 @@ public interface AuditReader { /** * Checks if the entityName was configured to be audited. * - * @param entityName + * @param entityClass * EntityName of the entity asking for audit support. * @return true if the entityName is audited. */ @@ -234,7 +234,7 @@ public interface AuditReader { * where n is a number of different entity classes modified within specified revision. * @param revision Revision number. * @param revisionType Type of modification. - * @return Snapshots of all audited entities changed in a given revision filtered by modification type. + * @return Snapshots of all audited entities changed in a given revision and filtered by modification type. * @throws IllegalStateException If the associated entity manager is closed. * @throws IllegalArgumentException If a revision number is null, less or equal to 0. * @throws AuditException If none of the following conditions is satisfied: diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/RevisionInfoConfiguration.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/RevisionInfoConfiguration.java index 1cf06be6b6..d8cbd3ffda 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/RevisionInfoConfiguration.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/RevisionInfoConfiguration.java @@ -34,7 +34,14 @@ import org.hibernate.annotations.common.reflection.ReflectionManager; import org.hibernate.annotations.common.reflection.XClass; import org.hibernate.annotations.common.reflection.XProperty; import org.hibernate.cfg.Configuration; -import org.hibernate.envers.*; +import org.hibernate.envers.Audited; +import org.hibernate.envers.DefaultRevisionEntity; +import org.hibernate.envers.DefaultTrackingModifiedTypesRevisionEntity; +import org.hibernate.envers.ModifiedEntityTypes; +import org.hibernate.envers.RevisionEntity; +import org.hibernate.envers.RevisionListener; +import org.hibernate.envers.RevisionNumber; +import org.hibernate.envers.RevisionTimestamp; import org.hibernate.envers.configuration.metadata.AuditTableData; import org.hibernate.envers.configuration.metadata.MetadataTools; import org.hibernate.envers.entities.PropertyData; @@ -87,7 +94,7 @@ public class RevisionInfoConfiguration { MetadataTools.addColumn(timestampProperty, "REVTSTMP", null, 0, 0, null, null, null, false); if (globalCfg.isTrackEntitiesChangedInRevisionEnabled()) { - generateEntityNamesTrackingTableMapping(class_mapping, "modifiedEntityTypes", "REVENTITY", "REV", "ENTITYTYPE", "string"); + generateEntityTypesTrackingTableMapping(class_mapping, "modifiedEntityTypes", "REVENTITY", "REV", "ENTITYTYPE", "string"); } return document; @@ -104,7 +111,7 @@ public class RevisionInfoConfiguration { * </set> * */ - private void generateEntityNamesTrackingTableMapping(Element class_mapping, String propertyName, + private void generateEntityTypesTrackingTableMapping(Element class_mapping, String propertyName, String joinTableName, String joinTablePrimaryKeyColumnName, String joinTableValueColumnName, String joinTableValueColumnType) { Element set = class_mapping.addElement("set"); diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/impl/EntitiesAtRevisionQuery.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/impl/EntitiesAtRevisionQuery.java index b846ad795c..a05da97045 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/impl/EntitiesAtRevisionQuery.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/impl/EntitiesAtRevisionQuery.java @@ -48,8 +48,7 @@ public class EntitiesAtRevisionQuery extends AbstractAuditQuery { } public EntitiesAtRevisionQuery(AuditConfiguration verCfg, - AuditReaderImplementor versionsReader, Class cls, String entityName, - Number revision) { + AuditReaderImplementor versionsReader, Class cls, String entityName, Number revision) { super(verCfg, versionsReader, cls, entityName); this.revision = revision; } @@ -85,9 +84,9 @@ public class EntitiesAtRevisionQuery extends AbstractAuditQuery { verCfg.getAuditStrategy().addEntityAtRevisionRestriction(verCfg.getGlobalCfg(), qb, revisionPropertyPath, verEntCfg.getRevisionEndFieldName(), true, referencedIdData, revisionPropertyPath, originalIdPropertyName, "e", "e2"); - - // e.revision_type != DEL - qb.getRootParameters().addWhereWithParam(verEntCfg.getRevisionTypePropName(), "<>", RevisionType.DEL); + + // e.revision_type != DEL + qb.getRootParameters().addWhereWithParam(verEntCfg.getRevisionTypePropName(), "<>", RevisionType.DEL); // all specified conditions for (AuditCriterion criterion : criterions) { diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/reader/AuditReaderImpl.java b/hibernate-envers/src/main/java/org/hibernate/envers/reader/AuditReaderImpl.java index 538f036d00..229edc1776 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/reader/AuditReaderImpl.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/reader/AuditReaderImpl.java @@ -24,9 +24,14 @@ package org.hibernate.envers.reader; import static org.hibernate.envers.tools.ArgumentsTools.checkNotNull; import static org.hibernate.envers.tools.ArgumentsTools.checkPositive; - -import java.lang.reflect.Member; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; import javax.persistence.NoResultException; import org.hibernate.Criteria; import org.hibernate.HibernateException; @@ -55,7 +60,6 @@ public class AuditReaderImpl implements AuditReaderImplementor { private final SessionImplementor sessionImplementor; private final Session session; private final FirstLevelCache firstLevelCache; - private Member modifiedEntityTypesProperty = null; public AuditReaderImpl(AuditConfiguration verCfg, Session session, SessionImplementor sessionImplementor) { @@ -297,7 +301,7 @@ public class AuditReaderImpl implements AuditReaderImplementor { return Collections.EMPTY_SET; } - @SuppressWarnings({"unchecked"}) + @SuppressWarnings({"unchecked"}) public T getCurrentRevision(Class revisionEntityClass, boolean persist) { if (!(session instanceof EventSource)) { throw new IllegalArgumentException("The provided session is not an EventSource!"); diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/revisioninfo/DefaultTrackingModifiedTypesRevisionInfoGenerator.java b/hibernate-envers/src/main/java/org/hibernate/envers/revisioninfo/DefaultTrackingModifiedTypesRevisionInfoGenerator.java index 9f33ebe9ad..bd8a62599e 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/revisioninfo/DefaultTrackingModifiedTypesRevisionInfoGenerator.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/revisioninfo/DefaultTrackingModifiedTypesRevisionInfoGenerator.java @@ -1,5 +1,7 @@ package org.hibernate.envers.revisioninfo; +import org.hibernate.envers.DefaultTrackingModifiedTypesRevisionEntity; +import org.hibernate.envers.ModifiedEntityTypes; import org.hibernate.envers.RevisionListener; import org.hibernate.envers.RevisionType; import org.hibernate.envers.entities.PropertyData; @@ -12,17 +14,16 @@ import java.util.HashSet; import java.util.Set; /** - * Automatically adds entity names changed during current revision. - * @see org.hibernate.envers.ModifiedEntityTypes - * @see org.hibernate.envers.DefaultTrackingModifiedTypesRevisionEntity + * Automatically adds entity class names that have been changed during current revision to revision entity. + * @see ModifiedEntityTypes + * @see DefaultTrackingModifiedTypesRevisionEntity * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ public class DefaultTrackingModifiedTypesRevisionInfoGenerator extends DefaultRevisionInfoGenerator { private final Setter modifiedEntityTypesSetter; private final Getter modifiedEntityTypesGetter; - public DefaultTrackingModifiedTypesRevisionInfoGenerator(String revisionInfoEntityName, - Class revisionInfoClass, + public DefaultTrackingModifiedTypesRevisionInfoGenerator(String revisionInfoEntityName, Class revisionInfoClass, Class listenerClass, PropertyData revisionInfoTimestampData, boolean timestampAsDate, PropertyData modifiedEntityTypesData) { diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/revisioninfo/ModifiedEntityTypesReader.java b/hibernate-envers/src/main/java/org/hibernate/envers/revisioninfo/ModifiedEntityTypesReader.java index 858d13b53d..137f9f2199 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/revisioninfo/ModifiedEntityTypesReader.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/revisioninfo/ModifiedEntityTypesReader.java @@ -21,7 +21,7 @@ public class ModifiedEntityTypesReader { @SuppressWarnings({"unchecked"}) public Set getModifiedEntityTypes(Object revisionEntity) { - // The default mechanism of tracking entity types that have been changed during each revision, stores + // The default mechanism of tracking entity types that have been changed during each revision stores // fully qualified Java class names. Set modifiedEntityClassNames = (Set) modifiedEntityTypesGetter.get(revisionEntity); if (modifiedEntityClassNames != null) { diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/synchronization/AuditProcess.java b/hibernate-envers/src/main/java/org/hibernate/envers/synchronization/AuditProcess.java index d0e6aa4cb0..440dc8ebee 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/synchronization/AuditProcess.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/synchronization/AuditProcess.java @@ -23,6 +23,10 @@ */ package org.hibernate.envers.synchronization; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.Map; +import java.util.Queue; import org.hibernate.FlushMode; import org.hibernate.Session; import org.hibernate.action.spi.BeforeTransactionCompletionProcess; @@ -31,11 +35,6 @@ import org.hibernate.envers.revisioninfo.RevisionInfoGenerator; import org.hibernate.envers.synchronization.work.AuditWorkUnit; import org.hibernate.envers.tools.Pair; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.Map; -import java.util.Queue; - /** * @author Adam Warski (adam at warski dot org) */ diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/synchronization/work/AbstractAuditWorkUnit.java b/hibernate-envers/src/main/java/org/hibernate/envers/synchronization/work/AbstractAuditWorkUnit.java index e8ec2a5a1f..b652ffff3b 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/synchronization/work/AbstractAuditWorkUnit.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/synchronization/work/AbstractAuditWorkUnit.java @@ -23,6 +23,9 @@ */ package org.hibernate.envers.synchronization.work; +import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; import org.hibernate.Session; import org.hibernate.engine.SessionImplementor; import org.hibernate.envers.RevisionType; @@ -30,10 +33,6 @@ import org.hibernate.envers.configuration.AuditConfiguration; import org.hibernate.envers.configuration.AuditEntitiesConfiguration; import org.hibernate.envers.strategy.AuditStrategy; -import java.io.Serializable; -import java.util.HashMap; -import java.util.Map; - /** * @author Adam Warski (adam at warski dot org) * @author Stephanie Pau at Markit Group Plc diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/synchronization/work/AuditWorkUnit.java b/hibernate-envers/src/main/java/org/hibernate/envers/synchronization/work/AuditWorkUnit.java index 0ec98df495..59c8f4c6df 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/synchronization/work/AuditWorkUnit.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/synchronization/work/AuditWorkUnit.java @@ -22,13 +22,11 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.synchronization.work; - +import java.util.Map; +import java.io.Serializable; import org.hibernate.Session; import org.hibernate.envers.RevisionType; -import java.io.Serializable; -import java.util.Map; - /** * TODO: refactor constructors into factory methods * @author Adam Warski (adam at warski dot org) diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/synchronization/work/PersistentCollectionChangeWorkUnit.java b/hibernate-envers/src/main/java/org/hibernate/envers/synchronization/work/PersistentCollectionChangeWorkUnit.java index 610b42a8c1..0cb1cdeace 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/synchronization/work/PersistentCollectionChangeWorkUnit.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/synchronization/work/PersistentCollectionChangeWorkUnit.java @@ -23,8 +23,10 @@ */ package org.hibernate.envers.synchronization.work; import java.io.Serializable; -import java.util.*; - +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import org.hibernate.Session; import org.hibernate.collection.PersistentCollection; import org.hibernate.engine.CollectionEntry; @@ -79,7 +81,7 @@ public class PersistentCollectionChangeWorkUnit extends AbstractAuditWorkUnit im // Setting the revision number ((Map) persistentCollectionChangeData.getData().get(entitiesCfg.getOriginalIdPropName())) .put(entitiesCfg.getRevisionFieldName(), revisionData); - + auditStrategy.performCollectionChange(session, verCfg, persistentCollectionChangeData, revisionData); } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/tools/reflection/ReflectionTools.java b/hibernate-envers/src/main/java/org/hibernate/envers/tools/reflection/ReflectionTools.java index 3d41e39455..0b8f2f3fd4 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/tools/reflection/ReflectionTools.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/tools/reflection/ReflectionTools.java @@ -22,7 +22,8 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.tools.reflection; - +import static org.hibernate.envers.tools.Pair.make; +import java.util.Map; import org.hibernate.envers.entities.PropertyData; import org.hibernate.envers.exception.AuditException; import org.hibernate.envers.tools.ConcurrentReferenceHashMap; @@ -32,17 +33,6 @@ import org.hibernate.property.PropertyAccessor; import org.hibernate.property.PropertyAccessorFactory; import org.hibernate.property.Setter; -import java.lang.annotation.Annotation; -import java.lang.reflect.Field; -import java.lang.reflect.Member; -import java.lang.reflect.Method; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import static org.hibernate.envers.tools.Pair.make; - /** * @author Adam Warski (adam at warski dot org) */