HHH-5580 - Cleanup

This commit is contained in:
Lukasz Antoniak 2011-05-21 12:49:37 +02:00
parent 403b15cae8
commit c2e53061f2
12 changed files with 53 additions and 54 deletions

View File

@ -16,7 +16,7 @@
which can be used to identify groups of changes (much like a change set in source control). As the revisions 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 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 (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. to retrieve all changes performed in a certain revision.
</para> </para>
</preface> </preface>
@ -531,7 +531,7 @@ public class AnnotatedTrackingRevisionEntity {
</para> </para>
<example> <example>
<title>Custom implementation of tracking entity classes modified in revision</title> <title>Custom implementation of tracking entity classes modified during revisions</title>
<programlisting> <programlisting>
<filename>CustomEntityTrackingRevisionListener.java</filename> <filename>CustomEntityTrackingRevisionListener.java</filename>
<![CDATA[ <![CDATA[
@ -787,9 +787,9 @@ query.add(AuditEntity.relatedId("address").eq(relatedEntityId));]]></programlist
<section id="envers-tracking-modified-entities-queries"> <section id="envers-tracking-modified-entities-queries">
<title>Querying for entities modified in a given revision</title> <title>Querying for entities modified in a given revision</title>
<para> <para>
The basic query allows retrieving entity classes modified in a specified revision: The basic query allows retrieving entity types changed in a specified revision:
</para> </para>
<programlisting><![CDATA[Set<Class> modifiedEntities = getAuditReader() <programlisting><![CDATA[Set<Class> modifiedEntityTypes = getAuditReader()
.findEntityTypesChangedInRevision(revisionNumber);]]></programlisting> .findEntityTypesChangedInRevision(revisionNumber);]]></programlisting>
<para> <para>
Other queries (accessible from <interfacename>org.hibernate.envers.AuditReader</interfacename>): Other queries (accessible from <interfacename>org.hibernate.envers.AuditReader</interfacename>):
@ -816,7 +816,7 @@ query.add(AuditEntity.relatedId("address").eq(relatedEntityId));]]></programlist
</orderedlist> </orderedlist>
<para> <para>
Note that methods described above can be legally used only when default mechanism of Note that methods described above can be legally used only when default mechanism of
tracking changed entity classes is enabled (see <xref linkend="envers-tracking-modified-entities-reventity"/>). tracking changed entity types is enabled (see <xref linkend="envers-tracking-modified-entities-reventity"/>).
</para> </para>
</section> </section>

View File

@ -191,7 +191,7 @@ public interface AuditReader {
/** /**
* Checks if the entityName was configured to be audited. * Checks if the entityName was configured to be audited.
* *
* @param entityName * @param entityClass
* EntityName of the entity asking for audit support. * EntityName of the entity asking for audit support.
* @return true if the entityName is audited. * @return true if the entityName is audited.
*/ */
@ -234,7 +234,7 @@ public interface AuditReader {
* where <i>n</i> is a number of different entity classes modified within specified revision. * where <i>n</i> is a number of different entity classes modified within specified revision.
* @param revision Revision number. * @param revision Revision number.
* @param revisionType Type of modification. * @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 IllegalStateException If the associated entity manager is closed.
* @throws IllegalArgumentException If a revision number is <code>null</code>, less or equal to 0. * @throws IllegalArgumentException If a revision number is <code>null</code>, less or equal to 0.
* @throws AuditException If none of the following conditions is satisfied: * @throws AuditException If none of the following conditions is satisfied:

View File

@ -34,7 +34,14 @@ import org.hibernate.annotations.common.reflection.ReflectionManager;
import org.hibernate.annotations.common.reflection.XClass; import org.hibernate.annotations.common.reflection.XClass;
import org.hibernate.annotations.common.reflection.XProperty; import org.hibernate.annotations.common.reflection.XProperty;
import org.hibernate.cfg.Configuration; 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.AuditTableData;
import org.hibernate.envers.configuration.metadata.MetadataTools; import org.hibernate.envers.configuration.metadata.MetadataTools;
import org.hibernate.envers.entities.PropertyData; import org.hibernate.envers.entities.PropertyData;
@ -87,7 +94,7 @@ public class RevisionInfoConfiguration {
MetadataTools.addColumn(timestampProperty, "REVTSTMP", null, 0, 0, null, null, null, false); MetadataTools.addColumn(timestampProperty, "REVTSTMP", null, 0, 0, null, null, null, false);
if (globalCfg.isTrackEntitiesChangedInRevisionEnabled()) { if (globalCfg.isTrackEntitiesChangedInRevisionEnabled()) {
generateEntityNamesTrackingTableMapping(class_mapping, "modifiedEntityTypes", "REVENTITY", "REV", "ENTITYTYPE", "string"); generateEntityTypesTrackingTableMapping(class_mapping, "modifiedEntityTypes", "REVENTITY", "REV", "ENTITYTYPE", "string");
} }
return document; return document;
@ -104,7 +111,7 @@ public class RevisionInfoConfiguration {
* &lt;/set&gt; * &lt;/set&gt;
* </code> * </code>
*/ */
private void generateEntityNamesTrackingTableMapping(Element class_mapping, String propertyName, private void generateEntityTypesTrackingTableMapping(Element class_mapping, String propertyName,
String joinTableName, String joinTablePrimaryKeyColumnName, String joinTableName, String joinTablePrimaryKeyColumnName,
String joinTableValueColumnName, String joinTableValueColumnType) { String joinTableValueColumnName, String joinTableValueColumnType) {
Element set = class_mapping.addElement("set"); Element set = class_mapping.addElement("set");

View File

@ -48,8 +48,7 @@ public class EntitiesAtRevisionQuery extends AbstractAuditQuery {
} }
public EntitiesAtRevisionQuery(AuditConfiguration verCfg, public EntitiesAtRevisionQuery(AuditConfiguration verCfg,
AuditReaderImplementor versionsReader, Class<?> cls, String entityName, AuditReaderImplementor versionsReader, Class<?> cls, String entityName, Number revision) {
Number revision) {
super(verCfg, versionsReader, cls, entityName); super(verCfg, versionsReader, cls, entityName);
this.revision = revision; this.revision = revision;
} }
@ -85,9 +84,9 @@ public class EntitiesAtRevisionQuery extends AbstractAuditQuery {
verCfg.getAuditStrategy().addEntityAtRevisionRestriction(verCfg.getGlobalCfg(), qb, revisionPropertyPath, verCfg.getAuditStrategy().addEntityAtRevisionRestriction(verCfg.getGlobalCfg(), qb, revisionPropertyPath,
verEntCfg.getRevisionEndFieldName(), true, referencedIdData, verEntCfg.getRevisionEndFieldName(), true, referencedIdData,
revisionPropertyPath, originalIdPropertyName, "e", "e2"); revisionPropertyPath, originalIdPropertyName, "e", "e2");
// e.revision_type != DEL // e.revision_type != DEL
qb.getRootParameters().addWhereWithParam(verEntCfg.getRevisionTypePropName(), "<>", RevisionType.DEL); qb.getRootParameters().addWhereWithParam(verEntCfg.getRevisionTypePropName(), "<>", RevisionType.DEL);
// all specified conditions // all specified conditions
for (AuditCriterion criterion : criterions) { for (AuditCriterion criterion : criterions) {

View File

@ -24,9 +24,14 @@
package org.hibernate.envers.reader; package org.hibernate.envers.reader;
import static org.hibernate.envers.tools.ArgumentsTools.checkNotNull; import static org.hibernate.envers.tools.ArgumentsTools.checkNotNull;
import static org.hibernate.envers.tools.ArgumentsTools.checkPositive; import static org.hibernate.envers.tools.ArgumentsTools.checkPositive;
import java.util.ArrayList;
import java.lang.reflect.Member; import java.util.Collections;
import java.util.*; 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 javax.persistence.NoResultException;
import org.hibernate.Criteria; import org.hibernate.Criteria;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
@ -55,7 +60,6 @@ public class AuditReaderImpl implements AuditReaderImplementor {
private final SessionImplementor sessionImplementor; private final SessionImplementor sessionImplementor;
private final Session session; private final Session session;
private final FirstLevelCache firstLevelCache; private final FirstLevelCache firstLevelCache;
private Member modifiedEntityTypesProperty = null;
public AuditReaderImpl(AuditConfiguration verCfg, Session session, public AuditReaderImpl(AuditConfiguration verCfg, Session session,
SessionImplementor sessionImplementor) { SessionImplementor sessionImplementor) {
@ -297,7 +301,7 @@ public class AuditReaderImpl implements AuditReaderImplementor {
return Collections.EMPTY_SET; return Collections.EMPTY_SET;
} }
@SuppressWarnings({"unchecked"}) @SuppressWarnings({"unchecked"})
public <T> T getCurrentRevision(Class<T> revisionEntityClass, boolean persist) { public <T> T getCurrentRevision(Class<T> revisionEntityClass, boolean persist) {
if (!(session instanceof EventSource)) { if (!(session instanceof EventSource)) {
throw new IllegalArgumentException("The provided session is not an EventSource!"); throw new IllegalArgumentException("The provided session is not an EventSource!");

View File

@ -1,5 +1,7 @@
package org.hibernate.envers.revisioninfo; package org.hibernate.envers.revisioninfo;
import org.hibernate.envers.DefaultTrackingModifiedTypesRevisionEntity;
import org.hibernate.envers.ModifiedEntityTypes;
import org.hibernate.envers.RevisionListener; import org.hibernate.envers.RevisionListener;
import org.hibernate.envers.RevisionType; import org.hibernate.envers.RevisionType;
import org.hibernate.envers.entities.PropertyData; import org.hibernate.envers.entities.PropertyData;
@ -12,17 +14,16 @@ import java.util.HashSet;
import java.util.Set; import java.util.Set;
/** /**
* Automatically adds entity names changed during current revision. * Automatically adds entity class names that have been changed during current revision to revision entity.
* @see org.hibernate.envers.ModifiedEntityTypes * @see ModifiedEntityTypes
* @see org.hibernate.envers.DefaultTrackingModifiedTypesRevisionEntity * @see DefaultTrackingModifiedTypesRevisionEntity
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
*/ */
public class DefaultTrackingModifiedTypesRevisionInfoGenerator extends DefaultRevisionInfoGenerator { public class DefaultTrackingModifiedTypesRevisionInfoGenerator extends DefaultRevisionInfoGenerator {
private final Setter modifiedEntityTypesSetter; private final Setter modifiedEntityTypesSetter;
private final Getter modifiedEntityTypesGetter; private final Getter modifiedEntityTypesGetter;
public DefaultTrackingModifiedTypesRevisionInfoGenerator(String revisionInfoEntityName, public DefaultTrackingModifiedTypesRevisionInfoGenerator(String revisionInfoEntityName, Class<?> revisionInfoClass,
Class<?> revisionInfoClass,
Class<? extends RevisionListener> listenerClass, Class<? extends RevisionListener> listenerClass,
PropertyData revisionInfoTimestampData, boolean timestampAsDate, PropertyData revisionInfoTimestampData, boolean timestampAsDate,
PropertyData modifiedEntityTypesData) { PropertyData modifiedEntityTypesData) {

View File

@ -21,7 +21,7 @@ public class ModifiedEntityTypesReader {
@SuppressWarnings({"unchecked"}) @SuppressWarnings({"unchecked"})
public Set<Class> getModifiedEntityTypes(Object revisionEntity) { public Set<Class> 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. // fully qualified Java class names.
Set<String> modifiedEntityClassNames = (Set<String>) modifiedEntityTypesGetter.get(revisionEntity); Set<String> modifiedEntityClassNames = (Set<String>) modifiedEntityTypesGetter.get(revisionEntity);
if (modifiedEntityClassNames != null) { if (modifiedEntityClassNames != null) {

View File

@ -23,6 +23,10 @@
*/ */
package org.hibernate.envers.synchronization; 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.FlushMode;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.action.spi.BeforeTransactionCompletionProcess; 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.synchronization.work.AuditWorkUnit;
import org.hibernate.envers.tools.Pair; 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) * @author Adam Warski (adam at warski dot org)
*/ */

View File

@ -23,6 +23,9 @@
*/ */
package org.hibernate.envers.synchronization.work; 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.Session;
import org.hibernate.engine.SessionImplementor; import org.hibernate.engine.SessionImplementor;
import org.hibernate.envers.RevisionType; 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.configuration.AuditEntitiesConfiguration;
import org.hibernate.envers.strategy.AuditStrategy; 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 Adam Warski (adam at warski dot org)
* @author Stephanie Pau at Markit Group Plc * @author Stephanie Pau at Markit Group Plc

View File

@ -22,13 +22,11 @@
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.envers.synchronization.work; package org.hibernate.envers.synchronization.work;
import java.util.Map;
import java.io.Serializable;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.envers.RevisionType; import org.hibernate.envers.RevisionType;
import java.io.Serializable;
import java.util.Map;
/** /**
* TODO: refactor constructors into factory methods * TODO: refactor constructors into factory methods
* @author Adam Warski (adam at warski dot org) * @author Adam Warski (adam at warski dot org)

View File

@ -23,8 +23,10 @@
*/ */
package org.hibernate.envers.synchronization.work; package org.hibernate.envers.synchronization.work;
import java.io.Serializable; 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.Session;
import org.hibernate.collection.PersistentCollection; import org.hibernate.collection.PersistentCollection;
import org.hibernate.engine.CollectionEntry; import org.hibernate.engine.CollectionEntry;
@ -79,7 +81,7 @@ public class PersistentCollectionChangeWorkUnit extends AbstractAuditWorkUnit im
// Setting the revision number // Setting the revision number
((Map<String, Object>) persistentCollectionChangeData.getData().get(entitiesCfg.getOriginalIdPropName())) ((Map<String, Object>) persistentCollectionChangeData.getData().get(entitiesCfg.getOriginalIdPropName()))
.put(entitiesCfg.getRevisionFieldName(), revisionData); .put(entitiesCfg.getRevisionFieldName(), revisionData);
auditStrategy.performCollectionChange(session, verCfg, persistentCollectionChangeData, revisionData); auditStrategy.performCollectionChange(session, verCfg, persistentCollectionChangeData, revisionData);
} }
} }

View File

@ -22,7 +22,8 @@
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.envers.tools.reflection; 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.entities.PropertyData;
import org.hibernate.envers.exception.AuditException; import org.hibernate.envers.exception.AuditException;
import org.hibernate.envers.tools.ConcurrentReferenceHashMap; import org.hibernate.envers.tools.ConcurrentReferenceHashMap;
@ -32,17 +33,6 @@ import org.hibernate.property.PropertyAccessor;
import org.hibernate.property.PropertyAccessorFactory; import org.hibernate.property.PropertyAccessorFactory;
import org.hibernate.property.Setter; 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) * @author Adam Warski (adam at warski dot org)
*/ */