HHH-5580 - Refactoring

This commit is contained in:
Lukasz Antoniak 2011-05-14 23:47:34 +02:00
parent 2ba3cc6dab
commit b36b095c3c
11 changed files with 220 additions and 81 deletions

View File

@ -16,7 +16,8 @@
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.
way round, you can get the date at which a revision was committed. Since version 4, Envers enables user
to retrieve all changes performed in a certain revision.
</para>
</preface>
@ -792,7 +793,7 @@ query.add(AuditEntity.relatedId("address").eq(relatedEntityId));]]></programlist
<para>
The basic query allows retrieving entity classes modified in a specified revision:
</para>
<programlisting><![CDATA[List<Class> modifiedEntities = getAuditReader()
<programlisting><![CDATA[Set<Class> modifiedEntities = getAuditReader()
.findEntityTypesChangedInRevision(revisionNumber);]]></programlisting>
<para>
Other queries (accessible from <interfacename>org.hibernate.envers.AuditReader</interfacename>):

View File

@ -275,9 +275,9 @@ public interface AuditReader {
throws IllegalStateException, IllegalArgumentException, AuditException;
/**
* Returns list of entity classes modified in a given revision.
* Returns set of entity classes modified in a given revision.
* @param revision Revision number.
* @return List of classes modified in a given revision.
* @return Set of classes modified in a given revision.
* @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 AuditException If none of the following conditions is satisfied:
@ -290,6 +290,6 @@ public interface AuditReader {
* marked with {@link ModifiedEntityNames} interface.</li>
* </ul>
*/
List<Class> findEntityTypesChangedInRevision(Number revision)
Set<Class> findEntityTypesChangedInRevision(Number revision)
throws IllegalStateException, IllegalArgumentException, AuditException;
}

View File

@ -1,5 +1,8 @@
package org.hibernate.envers;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;
@ -16,9 +19,10 @@ import java.util.Set;
*/
@MappedSuperclass
public class DefaultTrackingModifiedTypesRevisionEntity extends DefaultRevisionEntity {
@ElementCollection
@ElementCollection(fetch = FetchType.EAGER)
@JoinTable(name = "REVENTITY", joinColumns = @JoinColumn(name = "REV"))
@Column(name = "ENTITYNAME")
@Fetch(FetchMode.JOIN)
@ModifiedEntityNames
private Set<String> modifiedEntityNames = new HashSet<String>();

View File

@ -96,7 +96,7 @@ public class RevisionInfoConfiguration {
/**
* Generates mapping that represents a set of strings.<br />
* <code>
* &lt;set name="propertyName" table="joinTableName" cascade="persist, delete"&gt;<br />
* &lt;set name="propertyName" table="joinTableName" cascade="persist, delete" lazy="false" fetch="join"&gt;<br />
* &nbsp;&nbsp;&nbsp;&lt;key column="joinTablePrimaryKeyColumnName" /&gt;<br />
* &nbsp;&nbsp;&nbsp;&lt;element type="joinTableValueColumnType"&gt;<br />
* &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;column name="joinTableValueColumnName" /&gt;<br />
@ -111,6 +111,8 @@ public class RevisionInfoConfiguration {
set.addAttribute("name", propertyName);
set.addAttribute("table", joinTableName);
set.addAttribute("cascade", "persist, delete");
set.addAttribute("fetch", "join");
set.addAttribute("lazy", "false");
Element key = set.addElement("key");
key.addAttribute("column", joinTablePrimaryKeyColumnName);
Element element = set.addElement("element");
@ -305,7 +307,9 @@ public class RevisionInfoConfiguration {
return new RevisionInfoConfigurationResult(
revisionInfoGenerator, revisionInfoXmlMapping,
new RevisionInfoQueryCreator(revisionInfoEntityName, revisionInfoIdData.getName(),
revisionInfoTimestampData.getName(), isTimestampAsDate(), modifiedEntityNamesData.getName()),
revisionInfoTimestampData.getName(), isTimestampAsDate(),
globalCfg.isTrackEntitiesChangedInRevisionEnabled() ? modifiedEntityNamesData.getName()
: null),
generateRevisionInfoRelationMapping(),
new RevisionInfoNumberReader(revisionInfoClass, revisionInfoIdData), revisionInfoEntityName,
revisionInfoClass, revisionInfoTimestampData);

View File

@ -32,6 +32,7 @@ import org.hibernate.NonUniqueResultException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.envers.ModifiedEntityNames;
import org.hibernate.envers.RevisionType;
import org.hibernate.envers.configuration.AuditConfiguration;
import org.hibernate.envers.exception.AuditException;
@ -41,6 +42,7 @@ import org.hibernate.envers.query.AuditEntity;
import org.hibernate.envers.query.AuditQueryCreator;
import org.hibernate.envers.query.criteria.RevisionTypeAuditExpression;
import org.hibernate.envers.synchronization.AuditProcess;
import org.hibernate.envers.tools.reflection.ReflectionTools;
import org.hibernate.event.EventSource;
import org.hibernate.proxy.HibernateProxy;
@ -237,7 +239,7 @@ public class AuditReaderImpl implements AuditReaderImplementor {
@SuppressWarnings({"unchecked"})
public List<Object> findEntitiesChangedInRevision(Number revision) throws IllegalStateException,
IllegalArgumentException, AuditException {
List<Class> clazz = findEntityTypesChangedInRevision(revision);
Set<Class> clazz = findEntityTypesChangedInRevision(revision);
List<Object> result = new ArrayList<Object>();
for (Class c : clazz) {
result.addAll(createQuery().forEntitiesModifiedAtRevision(c, revision).getResultList());
@ -248,7 +250,7 @@ public class AuditReaderImpl implements AuditReaderImplementor {
@SuppressWarnings({"unchecked"})
public List<Object> findEntitiesChangedInRevision(Number revision, RevisionType revisionType)
throws IllegalStateException, IllegalArgumentException, AuditException {
List<Class> clazz = findEntityTypesChangedInRevision(revision);
Set<Class> clazz = findEntityTypesChangedInRevision(revision);
List<Object> result = new ArrayList<Object>();
for (Class c : clazz) {
result.addAll(createQuery().forEntitiesModifiedAtRevision(c, revision)
@ -260,7 +262,7 @@ public class AuditReaderImpl implements AuditReaderImplementor {
@SuppressWarnings({"unchecked"})
public Map<RevisionType, List<Object>> findEntitiesChangedInRevisionGroupByRevisionType(Number revision)
throws IllegalStateException, IllegalArgumentException, AuditException {
List<Class> clazz = findEntityTypesChangedInRevision(revision);
Set<Class> clazz = findEntityTypesChangedInRevision(revision);
Map<RevisionType, List<Object>> result = new HashMap<RevisionType, List<Object>>();
for (RevisionType revisionType : RevisionType.values()) {
result.put(revisionType, new ArrayList());
@ -274,8 +276,8 @@ public class AuditReaderImpl implements AuditReaderImplementor {
}
@SuppressWarnings({"unchecked"})
public List<Class> findEntityTypesChangedInRevision(Number revision) throws IllegalStateException,
IllegalArgumentException, AuditException {
public Set<Class> findEntityTypesChangedInRevision(Number revision) throws IllegalStateException,
IllegalArgumentException, AuditException {
checkNotNull(revision, "Entity revision");
checkPositive(revision, "Entity revision");
checkSession();
@ -284,17 +286,26 @@ public class AuditReaderImpl implements AuditReaderImplementor {
+ " Extend DefaultTrackingModifiedTypesRevisionEntity, utilize @ModifiedEntityNames annotation or set "
+ "'org.hibernate.envers.track_entities_changed_in_revision' parameter to true.");
}
Query query = verCfg.getRevisionInfoQueryCreator().getEntitiesChangedInRevisionQuery(session, revision);
Set<String> modifiedEntityNames = new HashSet<String>(query.list());
List<Class> result = new ArrayList<Class>(modifiedEntityNames.size());
for (String entityName : modifiedEntityNames) {
try {
result.add(Class.forName(entityName));
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
Set<Number> revisions = new HashSet<Number>(1);
revisions.add(revision);
Query query = verCfg.getRevisionInfoQueryCreator().getRevisionsQuery(session, revisions);
Object revisionInfo = query.uniqueResult();
if (revisionInfo != null) {
// If revision exists
// Only one field can be marked with @ModifiedEntityNames annotation
Set<String> modifiedEntityNames = (Set<String>) ReflectionTools.getAnnotatedMembersValues(revisionInfo, ModifiedEntityNames.class).values().toArray()[0];
Set<Class> result = new HashSet<Class>(modifiedEntityNames.size());
for (String entityName : modifiedEntityNames) {
try {
result.add(Class.forName(entityName));
} catch (ClassNotFoundException e) {
// This shall never happen
throw new RuntimeException(e);
}
}
return result;
}
return result;
return Collections.EMPTY_SET;
}
@SuppressWarnings({"unchecked"})

View File

@ -22,11 +22,12 @@
* Boston, MA 02110-1301 USA
*/
package org.hibernate.envers.revisioninfo;
import java.util.Date;
import java.util.Set;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.transform.Transformers;
import java.util.Date;
import java.util.Set;
/**
* @author Adam Warski (adam at warski dot org)
@ -36,7 +37,6 @@ public class RevisionInfoQueryCreator {
private final String revisionDateQuery;
private final String revisionNumberForDateQuery;
private final String revisionsQuery;
private final String entitiesChangedInRevisionQuery;
private final boolean timestampAsDate;
public RevisionInfoQueryCreator(String revisionInfoEntityName, String revisionInfoIdName,
@ -56,17 +56,23 @@ public class RevisionInfoQueryCreator {
.append(" rev where ").append(revisionInfoTimestampName).append(" <= :_revision_date")
.toString();
revisionsQuery = new StringBuilder()
.append("select rev from ").append(revisionInfoEntityName)
.append(" rev where ").append(revisionInfoIdName)
.append(" in (:_revision_numbers)")
.toString();
entitiesChangedInRevisionQuery = new StringBuilder()
.append("select elements(rev.").append(modifiedEntityNamesName)
.append(") from ").append(revisionInfoEntityName)
.append(" rev where rev.").append(revisionInfoIdName).append(" = :_revision_number")
.toString();
if (modifiedEntityNamesName == null) {
// Tracking modified entity classes is not enabled.
revisionsQuery = new StringBuilder()
.append("select rev from ").append(revisionInfoEntityName)
.append(" rev where ").append(revisionInfoIdName)
.append(" in (:_revision_numbers)")
.toString();
} else {
// Modified entity names enabled. Eagerly loading entity names collection.
// HQL queries do not respect any fetch="join" defined in the mapping document.
revisionsQuery = new StringBuilder()
.append("select rev from ").append(revisionInfoEntityName)
.append(" rev join fetch rev.").append(modifiedEntityNamesName)
.append(" ent where rev.").append(revisionInfoIdName)
.append(" in (:_revision_numbers)")
.toString();
}
}
public Query getRevisionDateQuery(Session session, Number revision) {
@ -80,8 +86,4 @@ public class RevisionInfoQueryCreator {
public Query getRevisionsQuery(Session session, Set<Number> revisions) {
return session.createQuery(revisionsQuery).setParameterList("_revision_numbers", revisions);
}
public Query getEntitiesChangedInRevisionQuery(Session session, Number revision) {
return session.createQuery(entitiesChangedInRevisionQuery).setParameter("_revision_number", revision);
}
}

View File

@ -29,11 +29,8 @@ import org.hibernate.action.spi.BeforeTransactionCompletionProcess;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.envers.revisioninfo.RevisionInfoGenerator;
import org.hibernate.envers.synchronization.work.AuditWorkUnit;
import org.hibernate.envers.synchronization.work.PersistentCollectionChangeWorkUnit;
import org.hibernate.envers.tools.Pair;
import org.hibernate.persister.entity.EntityPersister;
import java.io.Serializable;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
@ -49,6 +46,7 @@ public class AuditProcess implements BeforeTransactionCompletionProcess {
private final LinkedList<AuditWorkUnit> workUnits;
private final Queue<AuditWorkUnit> undoQueue;
private final Map<Pair<String, Object>, AuditWorkUnit> usedIds;
private final EntityChangeNotifier entityChangeNotifier;
private Object revisionData;
@ -59,6 +57,7 @@ public class AuditProcess implements BeforeTransactionCompletionProcess {
workUnits = new LinkedList<AuditWorkUnit>();
undoQueue = new LinkedList<AuditWorkUnit>();
usedIds = new HashMap<Pair<String, Object>, AuditWorkUnit>();
entityChangeNotifier = new EntityChangeNotifier(revisionInfoGenerator, session);
}
private void removeWorkUnit(AuditWorkUnit vwu) {
@ -114,23 +113,10 @@ public class AuditProcess implements BeforeTransactionCompletionProcess {
while ((vwu = workUnits.poll()) != null) {
vwu.perform(session, revisionData);
Serializable entityId = vwu.getEntityId();
if (entityId instanceof PersistentCollectionChangeWorkUnit.PersistentCollectionChangeWorkUnitId) {
entityId = ((PersistentCollectionChangeWorkUnit.PersistentCollectionChangeWorkUnitId) entityId).getOwnerId();
}
Class entityClass = getEntityClass(this.session, session, vwu.getEntityName());
revisionInfoGenerator.entityChanged(entityClass, vwu.getEntityName(), entityId, vwu.getRevisionType(), currentRevisionData);
entityChangeNotifier.entityChanged(session, currentRevisionData, vwu);
}
}
/**
* @return Java class mapped to specified entity name.
*/
private Class getEntityClass(SessionImplementor sessionImplementor, Session session, String entityName) {
EntityPersister entityPersister = sessionImplementor.getFactory().getEntityPersister(entityName);
return entityPersister.getClassMetadata().getMappedClass(session.getEntityMode());
}
public Object getCurrentRevisionData(Session session, boolean persist) {
// Generating the revision data if not yet generated
if (revisionData == null) {

View File

@ -0,0 +1,51 @@
package org.hibernate.envers.synchronization;
import org.hibernate.Session;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.envers.RevisionType;
import org.hibernate.envers.revisioninfo.RevisionInfoGenerator;
import org.hibernate.envers.synchronization.work.AuditWorkUnit;
import org.hibernate.envers.synchronization.work.PersistentCollectionChangeWorkUnit;
import org.hibernate.persister.entity.EntityPersister;
import java.io.Serializable;
/**
* Notifies {@link RevisionInfoGenerator} about changes made in the current revision.
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
*/
public class EntityChangeNotifier {
private final RevisionInfoGenerator revisionInfoGenerator;
private final SessionImplementor sessionImplementor;
public EntityChangeNotifier(RevisionInfoGenerator revisionInfoGenerator, SessionImplementor sessionImplementor) {
this.revisionInfoGenerator = revisionInfoGenerator;
this.sessionImplementor = sessionImplementor;
}
/**
* Notifies {@link RevisionInfoGenerator} about changes made in the current revision. Provides information
* about modified entity class, entity name and its id, as well as {@link RevisionType} and revision log entity.
* @param session Active session.
* @param currentRevisionData Revision log entity.
* @param vwu Performed work unit.
*/
public void entityChanged(Session session, Object currentRevisionData, AuditWorkUnit vwu) {
Serializable entityId = vwu.getEntityId();
if (entityId instanceof PersistentCollectionChangeWorkUnit.PersistentCollectionChangeWorkUnitId) {
// Notify about a change in collection owner entity.
entityId = ((PersistentCollectionChangeWorkUnit.PersistentCollectionChangeWorkUnitId) entityId).getOwnerId();
}
Class entityClass = getEntityClass(session, vwu.getEntityName());
revisionInfoGenerator.entityChanged(entityClass, vwu.getEntityName(), entityId, vwu.getRevisionType(),
currentRevisionData);
}
/**
* @return Java class mapped to specified entity name.
*/
private Class getEntityClass(Session session, String entityName) {
EntityPersister entityPersister = sessionImplementor.getFactory().getEntityPersister(entityName);
return entityPersister.getClassMetadata().getMappedClass(session.getEntityMode());
}
}

View File

@ -22,8 +22,7 @@
* 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;
@ -33,8 +32,20 @@ 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)
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
*/
public class ReflectionTools {
private static final Map<Pair<Class, String>, Getter> getterCache =
@ -89,4 +100,72 @@ public class ReflectionTools {
return value;
}
/**
* @param object Not {@code null} instance.
* @param annotation Searched annotation.
* @return Map with the following structure:
* <ul>
* <li>key - members ({@link Field} and/or {@link Method}) that have been marked with a given annotation.</li>
* <li>value - object returned by the method invocation or field's value.</li>
* </ul>
*/
public static Map<Member, Object> getAnnotatedMembersValues(Object object, Class<? extends Annotation> annotation) {
try {
Set<Field> annotatedFields = new HashSet<Field>();
Set<Method> annotatedMethods = new HashSet<Method>();
doGetAnnotatedFields(object.getClass(), annotation, annotatedFields);
doGetAnnotatedMethods(object.getClass(), annotation, annotatedMethods);
Map<Member, Object> result = new HashMap<Member, Object>(annotatedFields.size() + annotatedMethods.size());
for (Field field : annotatedFields) {
field.setAccessible(true);
result.put(field, field.get(object));
}
for (Method method : annotatedMethods) {
method.setAccessible(true);
result.put(method, method.invoke(object));
}
return result;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* Populates {@code fields} set with all properties marked with a given annotation.
* @param clazz Object's class type.
* @param annotation Annotation.
* @param fields Set of annotated fields. Shall be initialized externally.
*/
private static void doGetAnnotatedFields(Class clazz, Class<? extends Annotation> annotation, Set<Field> fields) {
for (Field field : clazz.getDeclaredFields()) {
field.setAccessible(true);
if (field.isAnnotationPresent(annotation)) {
fields.add(field);
}
}
Class superClass = clazz.getSuperclass();
if (!Object.class.equals(superClass)) {
doGetAnnotatedFields(superClass, annotation, fields);
}
}
/**
* Populates {@code methods} set with all functions marked with a given annotation.
* @param clazz Object's class type.
* @param annotation Annotation.
* @param methods Set of annotated methods. Shall be initialized externally.
*/
private static void doGetAnnotatedMethods(Class clazz, Class<? extends Annotation> annotation, Set<Method> methods) {
for (Method method : clazz.getDeclaredMethods()) {
method.setAccessible(true);
if (method.isAnnotationPresent(annotation)) {
methods.add(method);
}
}
Class superClass = clazz.getSuperclass();
if (!Object.class.equals(superClass)) {
doGetAnnotatedMethods(superClass, annotation, methods);
}
}
}

View File

@ -6,12 +6,12 @@ import org.hibernate.envers.test.AbstractEntityTest;
import org.hibernate.envers.test.Priority;
import org.hibernate.envers.test.entities.StrIntTestEntity;
import org.hibernate.envers.test.entities.StrTestEntity;
import org.hibernate.envers.test.tools.TestTools;
import org.hibernate.mapping.Column;
import org.hibernate.mapping.Table;
import org.junit.Test;
import javax.persistence.EntityManager;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@ -83,14 +83,14 @@ public class DefaultTrackingEntitiesTest extends AbstractEntityTest {
StrTestEntity ste = new StrTestEntity("x", steId);
StrIntTestEntity site = new StrIntTestEntity("y", 1, siteId);
assert Arrays.asList(ste, site).equals(getAuditReader().findEntitiesChangedInRevision(1));
assert TestTools.checkList(getAuditReader().findEntitiesChangedInRevision(1), ste, site);
}
@Test
public void testTrackModifiedEntities() {
StrIntTestEntity site = new StrIntTestEntity("y", 2, siteId);
assert Arrays.asList(site).equals(getAuditReader().findEntitiesChangedInRevision(2));
assert TestTools.checkList(getAuditReader().findEntitiesChangedInRevision(2), site);
}
@Test
@ -98,7 +98,7 @@ public class DefaultTrackingEntitiesTest extends AbstractEntityTest {
StrTestEntity ste = new StrTestEntity(null, steId);
StrIntTestEntity site = new StrIntTestEntity(null, null, siteId);
assert Arrays.asList(ste, site).equals(getAuditReader().findEntitiesChangedInRevision(3));
assert TestTools.checkList(getAuditReader().findEntitiesChangedInRevision(3), site, ste);
}
@Test
@ -112,9 +112,9 @@ public class DefaultTrackingEntitiesTest extends AbstractEntityTest {
StrIntTestEntity site = new StrIntTestEntity("y", 1, siteId);
Map<RevisionType, List<Object>> result = getAuditReader().findEntitiesChangedInRevisionGroupByRevisionType(1);
assert Arrays.asList(ste, site).equals(result.get(RevisionType.ADD));
assert Arrays.asList().equals(result.get(RevisionType.MOD));
assert Arrays.asList().equals(result.get(RevisionType.DEL));
assert TestTools.checkList(result.get(RevisionType.ADD), site, ste);
assert TestTools.checkList(result.get(RevisionType.MOD));
assert TestTools.checkList(result.get(RevisionType.DEL));
}
@Test
@ -122,9 +122,9 @@ public class DefaultTrackingEntitiesTest extends AbstractEntityTest {
StrIntTestEntity site = new StrIntTestEntity("y", 2, siteId);
Map<RevisionType, List<Object>> result = getAuditReader().findEntitiesChangedInRevisionGroupByRevisionType(2);
assert Arrays.asList().equals(result.get(RevisionType.ADD));
assert Arrays.asList(site).equals(result.get(RevisionType.MOD));
assert Arrays.asList().equals(result.get(RevisionType.DEL));
assert TestTools.checkList(result.get(RevisionType.ADD));
assert TestTools.checkList(result.get(RevisionType.MOD), site);
assert TestTools.checkList(result.get(RevisionType.DEL));
}
@Test
@ -133,9 +133,9 @@ public class DefaultTrackingEntitiesTest extends AbstractEntityTest {
StrIntTestEntity site = new StrIntTestEntity(null, null, siteId);
Map<RevisionType, List<Object>> result = getAuditReader().findEntitiesChangedInRevisionGroupByRevisionType(3);
assert Arrays.asList().equals(result.get(RevisionType.ADD));
assert Arrays.asList().equals(result.get(RevisionType.MOD));
assert Arrays.asList(ste, site).equals(result.get(RevisionType.DEL));
assert TestTools.checkList(result.get(RevisionType.ADD));
assert TestTools.checkList(result.get(RevisionType.MOD));
assert TestTools.checkList(result.get(RevisionType.DEL), site, ste);
}
@Test
@ -143,14 +143,14 @@ public class DefaultTrackingEntitiesTest extends AbstractEntityTest {
StrTestEntity ste = new StrTestEntity("x", steId);
StrIntTestEntity site = new StrIntTestEntity("y", 1, siteId);
assert Arrays.asList(ste, site).equals(getAuditReader().findEntitiesChangedInRevision(1, RevisionType.ADD));
assert TestTools.checkList(getAuditReader().findEntitiesChangedInRevision(1, RevisionType.ADD), ste, site);
}
@Test
public void testFindChangedEntitiesByRevisionTypeMOD() {
StrIntTestEntity site = new StrIntTestEntity("y", 2, siteId);
assert Arrays.asList(site).equals(getAuditReader().findEntitiesChangedInRevision(2, RevisionType.MOD));
assert TestTools.checkList(getAuditReader().findEntitiesChangedInRevision(2, RevisionType.MOD), site);
}
@Test
@ -158,13 +158,13 @@ public class DefaultTrackingEntitiesTest extends AbstractEntityTest {
StrTestEntity ste = new StrTestEntity(null, steId);
StrIntTestEntity site = new StrIntTestEntity(null, null, siteId);
assert Arrays.asList(ste, site).equals(getAuditReader().findEntitiesChangedInRevision(3, RevisionType.DEL));
assert TestTools.checkList(getAuditReader().findEntitiesChangedInRevision(3, RevisionType.DEL), ste, site);
}
@Test
public void testFindEntityTypesChangedInRevision() {
assert Arrays.asList(StrTestEntity.class, StrIntTestEntity.class).equals(getAuditReader().findEntityTypesChangedInRevision(1));
assert Arrays.asList(StrIntTestEntity.class).equals(getAuditReader().findEntityTypesChangedInRevision(2));
assert Arrays.asList(StrTestEntity.class, StrIntTestEntity.class).equals(getAuditReader().findEntityTypesChangedInRevision(3));
assert TestTools.makeSet(StrTestEntity.class, StrIntTestEntity.class).equals(getAuditReader().findEntityTypesChangedInRevision(1));
assert TestTools.makeSet(StrIntTestEntity.class).equals(getAuditReader().findEntityTypesChangedInRevision(2));
assert TestTools.makeSet(StrTestEntity.class, StrIntTestEntity.class).equals(getAuditReader().findEntityTypesChangedInRevision(3));
}
}

View File

@ -5,6 +5,7 @@ import org.hibernate.envers.test.AbstractSessionTest;
import org.hibernate.envers.test.Priority;
import org.hibernate.envers.test.integration.entityNames.manyToManyAudited.Car;
import org.hibernate.envers.test.integration.entityNames.manyToManyAudited.Person;
import org.hibernate.envers.test.tools.TestTools;
import org.junit.Test;
import java.io.File;
@ -61,7 +62,7 @@ public class EntityNamesTest extends AbstractSessionTest {
@Test
@SuppressWarnings("unchecked")
public void testModifiedEntityTypes() {
assert Arrays.asList(Car.class, Person.class).equals(getAuditReader().findEntityTypesChangedInRevision(1));
assert Arrays.asList(Car.class, Person.class).equals(getAuditReader().findEntityTypesChangedInRevision(2));
assert TestTools.makeSet(Car.class, Person.class).equals(getAuditReader().findEntityTypesChangedInRevision(1));
assert TestTools.makeSet(Car.class, Person.class).equals(getAuditReader().findEntityTypesChangedInRevision(2));
}
}