diff --git a/documentation/src/main/docbook/devguide/en-US/Envers.xml b/documentation/src/main/docbook/devguide/en-US/Envers.xml index 0488ee2892..00b71e6022 100644 --- a/documentation/src/main/docbook/devguide/en-US/Envers.xml +++ b/documentation/src/main/docbook/devguide/en-US/Envers.xml @@ -800,25 +800,25 @@ query.add(AuditEntity.relatedId("address").eq(relatedEntityId));]]> > modifiedEntityTypes = getAuditReader() - .findEntityTypesChangedInRevision(revisionNumber);]]> + .getEntitiesChangedInRevisionManager().findEntityTypes(revisionNumber);]]> - Other queries (accessible from org.hibernate.envers.AuditReader): + Other queries (also accessible from org.hibernate.envers.EntitiesChangedInRevisionManager): - List]]> findEntitiesChangedInRevision(Number) + List]]> findEntities(Number) - Returns snapshots of all audited entities changed (added, updated and removed) in a given revision. Executes n+1 SQL queries, where n is a number of different entity classes modified within specified revision. - List]]> findEntitiesChangedInRevision(Number, RevisionType) + List]]> findEntities(Number, RevisionType) - Returns snapshots of all audited entities changed (added, updated or removed) in a given revision filtered by modification type. Executes n+1 SQL queries, where n is a number of different entity classes modified within specified revision. - >]]> findEntitiesChangedInRevisionGroupByRevisionType(Number) + >]]> findEntitiesGroupByRevisionType(Number) - Returns a map containing lists of entity snapshots grouped by modification operation (e.g. addition, update and removal). Executes 3n+1 SQL queries, where n is a number of different entity classes modified within specified revision. 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 204feb1060..b1499beaac 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/AuditReader.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/AuditReader.java @@ -28,7 +28,6 @@ import org.hibernate.envers.exception.AuditException; import org.hibernate.envers.exception.NotAuditedException; import org.hibernate.envers.exception.RevisionDoesNotExistException; import org.hibernate.envers.query.AuditQueryCreator; -import org.hibernate.envers.tools.Pair; import java.util.Date; import java.util.List; @@ -212,12 +211,8 @@ public interface AuditReader { throws HibernateException; /** - * Find all entities changed (added, updated and removed) in a given revision. Executes n+1 SQL queries, - * where n is a number of different entity classes modified within specified revision. - * @param revision Revision number. - * @return Snapshots of all audited entities changed in a given revision. - * @throws IllegalStateException If the associated entity manager is closed. - * @throws IllegalArgumentException If a revision number is null, less or equal to 0. + * @return Basic implementation of {@link EntitiesChangedInRevisionManager} interface. Raises an exception if the default + * mechanism of tracking entity names modified during revisions has not been enabled. * @throws AuditException If none of the following conditions is satisfied: * */ - List findEntitiesChangedInRevision(Number revision) - throws IllegalStateException, IllegalArgumentException, AuditException; - - /** - * Find all entities changed (added, updated or removed) in a given revision. Executes n+1 SQL queries, - * 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 and filtered by modification type. - * @throws IllegalStateException If the associated entity manager is closed. - * @throws IllegalArgumentException If a revision number is {@code null}, less or equal to 0. - * @throws AuditException If none of the following conditions is satisfied: - *
    - *
  • {@code org.hibernate.envers.track_entities_changed_in_revision} - * parameter is set to {@code true}.
  • - *
  • Custom revision entity (annotated with {@link RevisionEntity}) - * extends {@link DefaultTrackingModifiedEntitiesRevisionEntity} base class.
  • - *
  • Custom revision entity (annotated with {@link RevisionEntity}) encapsulates a field - * marked with {@link ModifiedEntityNames} interface.
  • - *
- */ - List findEntitiesChangedInRevision(Number revision, RevisionType revisionType) - throws IllegalStateException, IllegalArgumentException, AuditException; - - /** - * Find all entities changed (added, updated and removed) in a given revision grouped by modification type. - * Executes mn+1 SQL queries, where: - *
    - *
  • n - number of different entity classes modified within specified revision. - *
  • m - number of different revision types. See {@link RevisionType} enum. - *
- * @param revision Revision number. - * @return Map containing lists of entity snapshots grouped by modification operation (e.g. addition, update, removal). - * @throws IllegalStateException If the associated entity manager is closed. - * @throws IllegalArgumentException If a revision number is {@code null}, less or equal to 0. - * @throws AuditException If none of the following conditions is satisfied: - *
    - *
  • {@code org.hibernate.envers.track_entities_changed_in_revision} - * parameter is set to {@code true}.
  • - *
  • Custom revision entity (annotated with {@link RevisionEntity}) - * extends {@link DefaultTrackingModifiedEntitiesRevisionEntity} base class.
  • - *
  • Custom revision entity (annotated with {@link RevisionEntity}) encapsulates a field - * marked with {@link ModifiedEntityNames} interface.
  • - *
- */ - Map> findEntitiesChangedInRevisionGroupByRevisionType(Number revision) - throws IllegalStateException, IllegalArgumentException, AuditException; - - /** - * Returns set of entity names and corresponding Java classes modified in a given revision. - * @param revision Revision number. - * @return Set of entity names and corresponding Java classes modified in a given revision. - * @throws IllegalStateException If the associated entity manager is closed. - * @throws IllegalArgumentException If a revision number is {@code null}, less or equal to 0. - * @throws AuditException If none of the following conditions is satisfied: - *
    - *
  • {@code org.hibernate.envers.track_entities_changed_in_revision} - * parameter is set to {@code true}.
  • - *
  • Custom revision entity (annotated with {@link RevisionEntity}) - * extends {@link DefaultTrackingModifiedEntitiesRevisionEntity} base class.
  • - *
  • Custom revision entity (annotated with {@link RevisionEntity}) encapsulates a field - * marked with {@link ModifiedEntityNames} interface.
  • - *
- */ - Set> findEntityTypesChangedInRevision(Number revision) - throws IllegalStateException, IllegalArgumentException, AuditException; + public EntitiesChangedInRevisionManager getEntitiesChangedInRevisionManager() throws AuditException; } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/EntitiesChangedInRevisionManager.java b/hibernate-envers/src/main/java/org/hibernate/envers/EntitiesChangedInRevisionManager.java new file mode 100644 index 0000000000..047a9aed14 --- /dev/null +++ b/hibernate-envers/src/main/java/org/hibernate/envers/EntitiesChangedInRevisionManager.java @@ -0,0 +1,61 @@ +package org.hibernate.envers; + +import org.hibernate.envers.tools.Pair; + +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * Queries that allow retrieving snapshots of all entities (regardless of their particular type) changed in the given + * revision. Note that this API can be legally used only when default mechanism of tracking modified entity names + * is enabled. + * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) + */ +public interface EntitiesChangedInRevisionManager { + /** + * Find all entities changed (added, updated and removed) in a given revision. Executes n+1 SQL queries, + * where n is a number of different entity classes modified within specified revision. + * @param revision Revision number. + * @return Snapshots of all audited entities changed in a given revision. + * @throws IllegalStateException If the associated entity manager is closed. + * @throws IllegalArgumentException If a revision number is null, less or equal to 0. + */ + public List findEntities(Number revision) throws IllegalStateException, IllegalArgumentException; + + /** + * Find all entities changed (added, updated or removed) in a given revision. Executes n+1 SQL queries, + * 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 and filtered by modification type. + * @throws IllegalStateException If the associated entity manager is closed. + * @throws IllegalArgumentException If a revision number is {@code null}, less or equal to 0. + */ + public List findEntities(Number revision, RevisionType revisionType) throws IllegalStateException, + IllegalArgumentException; + + /** + * Find all entities changed (added, updated and removed) in a given revision grouped by modification type. + * Executes mn+1 SQL queries, where: + *
    + *
  • n - number of different entity classes modified within specified revision. + *
  • m - number of different revision types. See {@link RevisionType} enum. + *
+ * @param revision Revision number. + * @return Map containing lists of entity snapshots grouped by modification operation (e.g. addition, update, removal). + * @throws IllegalStateException If the associated entity manager is closed. + * @throws IllegalArgumentException If a revision number is {@code null}, less or equal to 0. + */ + public Map> findEntitiesGroupByRevisionType(Number revision) throws IllegalStateException, + IllegalArgumentException; + + /** + * Returns set of entity names and corresponding Java classes modified in a given revision. + * @param revision Revision number. + * @return Set of entity names and corresponding Java classes modified in a given revision. + * @throws IllegalStateException If the associated entity manager is closed. + * @throws IllegalArgumentException If a revision number is {@code null}, less or equal to 0. + */ + public Set> findEntityTypes(Number revision) throws IllegalStateException, IllegalArgumentException; +} 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 05aafba24a..5c8fbbb03b 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 @@ -25,8 +25,6 @@ package org.hibernate.envers.reader; import static org.hibernate.envers.tools.ArgumentsTools.checkNotNull; import static org.hibernate.envers.tools.ArgumentsTools.checkPositive; import static org.hibernate.envers.tools.Tools.getTargetClassIfProxied; -import java.util.ArrayList; -import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.HashSet; @@ -39,17 +37,14 @@ import org.hibernate.HibernateException; import org.hibernate.NonUniqueResultException; import org.hibernate.Session; import org.hibernate.engine.spi.SessionImplementor; -import org.hibernate.envers.RevisionType; +import org.hibernate.envers.EntitiesChangedInRevisionManager; import org.hibernate.envers.configuration.AuditConfiguration; import org.hibernate.envers.exception.AuditException; import org.hibernate.envers.exception.NotAuditedException; import org.hibernate.envers.exception.RevisionDoesNotExistException; 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.Pair; -import org.hibernate.envers.tools.Tools; import org.hibernate.event.spi.EventSource; import org.hibernate.proxy.HibernateProxy; @@ -63,6 +58,7 @@ public class AuditReaderImpl implements AuditReaderImplementor { private final SessionImplementor sessionImplementor; private final Session session; private final FirstLevelCache firstLevelCache; + private final EntitiesChangedInRevisionManager entitiesChangedInRevisionManager; public AuditReaderImpl(AuditConfiguration verCfg, Session session, SessionImplementor sessionImplementor) { @@ -71,6 +67,7 @@ public class AuditReaderImpl implements AuditReaderImplementor { this.session = session; firstLevelCache = new FirstLevelCache(); + entitiesChangedInRevisionManager = new EntitiesChangedInRevisionManagerImpl(this, verCfg); } private void checkSession() { @@ -247,73 +244,13 @@ public class AuditReaderImpl implements AuditReaderImplementor { } } - @SuppressWarnings({"unchecked"}) - public List findEntitiesChangedInRevision(Number revision) throws IllegalStateException, - IllegalArgumentException, AuditException { - Set> entityTypes = findEntityTypesChangedInRevision(revision); - List result = new ArrayList(); - for (Pair type : entityTypes) { - result.addAll(createQuery().forEntitiesModifiedAtRevision(type.getSecond(), type.getFirst(), revision).getResultList()); - } - return result; - } - - @SuppressWarnings({"unchecked"}) - public List findEntitiesChangedInRevision(Number revision, RevisionType revisionType) - throws IllegalStateException, IllegalArgumentException, AuditException { - Set> entityTypes = findEntityTypesChangedInRevision(revision); - List result = new ArrayList(); - for (Pair type : entityTypes) { - result.addAll(createQuery().forEntitiesModifiedAtRevision(type.getSecond(), type.getFirst(), revision) - .add(new RevisionTypeAuditExpression(revisionType, "=")).getResultList()); - } - return result; - } - - @SuppressWarnings({"unchecked"}) - public Map> findEntitiesChangedInRevisionGroupByRevisionType(Number revision) - throws IllegalStateException, IllegalArgumentException, AuditException { - Set> entityTypes = findEntityTypesChangedInRevision(revision); - Map> result = new HashMap>(); - for (RevisionType revisionType : RevisionType.values()) { - result.put(revisionType, new ArrayList()); - for (Pair type : entityTypes) { - List list = createQuery().forEntitiesModifiedAtRevision(type.getSecond(), type.getFirst(), revision) - .add(new RevisionTypeAuditExpression(revisionType, "=")).getResultList(); - result.get(revisionType).addAll(list); - } - } - return result; - } - - @SuppressWarnings({"unchecked"}) - public Set> findEntityTypesChangedInRevision(Number revision) throws IllegalStateException, - IllegalArgumentException, AuditException { - checkNotNull(revision, "Entity revision"); - checkPositive(revision, "Entity revision"); - checkSession(); + public EntitiesChangedInRevisionManager getEntitiesChangedInRevisionManager() throws AuditException { if (!verCfg.getGlobalCfg().isTrackEntitiesChangedInRevisionEnabled()) { - throw new AuditException("This query is designed for Envers default mechanism of tracking entities modified in a given revision." + throw new AuditException("This API is designed for Envers default mechanism of tracking entities modified in a given revision." + " Extend DefaultTrackingModifiedEntitiesRevisionEntity, utilize @ModifiedEntityNames annotation or set " + "'org.hibernate.envers.track_entities_changed_in_revision' parameter to true."); } - Set revisions = new HashSet(1); - revisions.add(revision); - Criteria query = verCfg.getRevisionInfoQueryCreator().getRevisionsQuery(session, revisions); - Object revisionInfo = query.uniqueResult(); - if (revisionInfo != null) { - // If revision exists. - Set entityNames = verCfg.getModifiedEntityNamesReader().getModifiedEntityNames(revisionInfo); - if (entityNames != null) { - // Generate result that contains entity names and corresponding Java classes. - Set> result = new HashSet>(); - for (String entityName : entityNames) { - result.add(Pair.make(entityName, Tools.getEntityClass(sessionImplementor, session, entityName))); - } - return result; - } - } - return Collections.EMPTY_SET; + return entitiesChangedInRevisionManager; } @SuppressWarnings({"unchecked"}) diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/reader/EntitiesChangedInRevisionManagerImpl.java b/hibernate-envers/src/main/java/org/hibernate/envers/reader/EntitiesChangedInRevisionManagerImpl.java new file mode 100644 index 0000000000..b05bfc998e --- /dev/null +++ b/hibernate-envers/src/main/java/org/hibernate/envers/reader/EntitiesChangedInRevisionManagerImpl.java @@ -0,0 +1,104 @@ +package org.hibernate.envers.reader; + +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.engine.spi.SessionImplementor; +import org.hibernate.envers.EntitiesChangedInRevisionManager; +import org.hibernate.envers.RevisionType; +import org.hibernate.envers.configuration.AuditConfiguration; +import org.hibernate.envers.query.criteria.RevisionTypeAuditExpression; +import org.hibernate.envers.tools.Pair; +import org.hibernate.envers.tools.Tools; + +import java.util.*; + +import static org.hibernate.envers.tools.ArgumentsTools.checkNotNull; +import static org.hibernate.envers.tools.ArgumentsTools.checkPositive; + +/** + * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) + */ +public class EntitiesChangedInRevisionManagerImpl implements EntitiesChangedInRevisionManager { + private final AuditReaderImplementor auditReaderImplementor; + private final AuditConfiguration verCfg; + + public EntitiesChangedInRevisionManagerImpl(AuditReaderImplementor auditReaderImplementor, AuditConfiguration verCfg) { + this.auditReaderImplementor = auditReaderImplementor; + this.verCfg = verCfg; + } + + @SuppressWarnings({"unchecked"}) + public List findEntities(Number revision) throws IllegalStateException, IllegalArgumentException { + Set> entityTypes = findEntityTypes(revision); + List result = new ArrayList(); + for (Pair type : entityTypes) { + result.addAll(auditReaderImplementor.createQuery().forEntitiesModifiedAtRevision(type.getSecond(), type.getFirst(), revision) + .getResultList()); + } + return result; + } + + @SuppressWarnings({"unchecked"}) + public List findEntities(Number revision, RevisionType revisionType) throws IllegalStateException, + IllegalArgumentException { + Set> entityTypes = findEntityTypes(revision); + List result = new ArrayList(); + for (Pair type : entityTypes) { + result.addAll(auditReaderImplementor.createQuery().forEntitiesModifiedAtRevision(type.getSecond(), type.getFirst(), revision) + .add(new RevisionTypeAuditExpression(revisionType, "=")).getResultList()); + } + return result; + } + + @SuppressWarnings({"unchecked"}) + public Map> findEntitiesGroupByRevisionType(Number revision) throws IllegalStateException, + IllegalArgumentException { + Set> entityTypes = findEntityTypes(revision); + Map> result = new HashMap>(); + for (RevisionType revisionType : RevisionType.values()) { + result.put(revisionType, new ArrayList()); + for (Pair type : entityTypes) { + List list = auditReaderImplementor.createQuery().forEntitiesModifiedAtRevision(type.getSecond(), type.getFirst(), revision) + .add(new RevisionTypeAuditExpression(revisionType, "=")).getResultList(); + result.get(revisionType).addAll(list); + } + } + return result; + } + + @SuppressWarnings({"unchecked"}) + public Set> findEntityTypes(Number revision) throws IllegalStateException, IllegalArgumentException { + checkNotNull(revision, "Entity revision"); + checkPositive(revision, "Entity revision"); + checkSession(); + + Session session = auditReaderImplementor.getSession(); + SessionImplementor sessionImplementor = auditReaderImplementor.getSessionImplementor(); + + Set revisions = new HashSet(1); + revisions.add(revision); + Criteria query = verCfg.getRevisionInfoQueryCreator().getRevisionsQuery(session, revisions); + Object revisionInfo = query.uniqueResult(); + + if (revisionInfo != null) { + // If revision exists. + Set entityNames = verCfg.getModifiedEntityNamesReader().getModifiedEntityNames(revisionInfo); + if (entityNames != null) { + // Generate result that contains entity names and corresponding Java classes. + Set> result = new HashSet>(); + for (String entityName : entityNames) { + result.add(Pair.make(entityName, Tools.getEntityClass(sessionImplementor, session, entityName))); + } + return result; + } + } + + return Collections.EMPTY_SET; + } + + private void checkSession() { + if (!auditReaderImplementor.getSession().isOpen()) { + throw new IllegalStateException("The associated entity manager is closed!"); + } + } +} diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/trackmodifiedentities/CustomTrackingEntitiesTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/trackmodifiedentities/CustomTrackingEntitiesTest.java index ecfd829ad7..8712112336 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/trackmodifiedentities/CustomTrackingEntitiesTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/trackmodifiedentities/CustomTrackingEntitiesTest.java @@ -100,6 +100,6 @@ public class CustomTrackingEntitiesTest extends AbstractEntityTest { @Test(expected = AuditException.class) public void testFindEntitiesChangedInRevisionException() { - getAuditReader().findEntitiesChangedInRevision(1); + getAuditReader().getEntitiesChangedInRevisionManager(); } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/trackmodifiedentities/DefaultTrackingEntitiesTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/trackmodifiedentities/DefaultTrackingEntitiesTest.java index 27ba587e0e..38153bb95f 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/trackmodifiedentities/DefaultTrackingEntitiesTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/trackmodifiedentities/DefaultTrackingEntitiesTest.java @@ -1,6 +1,7 @@ package org.hibernate.envers.test.integration.reventity.trackmodifiedentities; import org.hibernate.ejb.Ejb3Configuration; +import org.hibernate.envers.EntitiesChangedInRevisionManager; import org.hibernate.envers.RevisionType; import org.hibernate.envers.test.AbstractEntityTest; import org.hibernate.envers.test.Priority; @@ -84,14 +85,14 @@ public class DefaultTrackingEntitiesTest extends AbstractEntityTest { StrTestEntity ste = new StrTestEntity("x", steId); StrIntTestEntity site = new StrIntTestEntity("y", 1, siteId); - assert TestTools.checkList(getAuditReader().findEntitiesChangedInRevision(1), ste, site); + assert TestTools.checkList(getEntitiesChangedInRevisionManager().findEntities(1), ste, site); } @Test public void testTrackModifiedEntities() { StrIntTestEntity site = new StrIntTestEntity("y", 2, siteId); - assert TestTools.checkList(getAuditReader().findEntitiesChangedInRevision(2), site); + assert TestTools.checkList(getEntitiesChangedInRevisionManager().findEntities(2), site); } @Test @@ -99,12 +100,12 @@ public class DefaultTrackingEntitiesTest extends AbstractEntityTest { StrTestEntity ste = new StrTestEntity(null, steId); StrIntTestEntity site = new StrIntTestEntity(null, null, siteId); - assert TestTools.checkList(getAuditReader().findEntitiesChangedInRevision(3), site, ste); + assert TestTools.checkList(getEntitiesChangedInRevisionManager().findEntities(3), site, ste); } @Test public void testFindChangesInInvalidRevision() { - assert getAuditReader().findEntitiesChangedInRevision(4).isEmpty(); + assert getEntitiesChangedInRevisionManager().findEntities(4).isEmpty(); } @Test @@ -112,7 +113,7 @@ public class DefaultTrackingEntitiesTest extends AbstractEntityTest { StrTestEntity ste = new StrTestEntity("x", steId); StrIntTestEntity site = new StrIntTestEntity("y", 1, siteId); - Map> result = getAuditReader().findEntitiesChangedInRevisionGroupByRevisionType(1); + Map> result = getEntitiesChangedInRevisionManager().findEntitiesGroupByRevisionType(1); assert TestTools.checkList(result.get(RevisionType.ADD), site, ste); assert TestTools.checkList(result.get(RevisionType.MOD)); assert TestTools.checkList(result.get(RevisionType.DEL)); @@ -122,7 +123,7 @@ public class DefaultTrackingEntitiesTest extends AbstractEntityTest { public void testTrackModifiedEntitiesGroupByRevisionType() { StrIntTestEntity site = new StrIntTestEntity("y", 2, siteId); - Map> result = getAuditReader().findEntitiesChangedInRevisionGroupByRevisionType(2); + Map> result = getEntitiesChangedInRevisionManager().findEntitiesGroupByRevisionType(2); assert TestTools.checkList(result.get(RevisionType.ADD)); assert TestTools.checkList(result.get(RevisionType.MOD), site); assert TestTools.checkList(result.get(RevisionType.DEL)); @@ -133,7 +134,7 @@ public class DefaultTrackingEntitiesTest extends AbstractEntityTest { StrTestEntity ste = new StrTestEntity(null, steId); StrIntTestEntity site = new StrIntTestEntity(null, null, siteId); - Map> result = getAuditReader().findEntitiesChangedInRevisionGroupByRevisionType(3); + Map> result = getEntitiesChangedInRevisionManager().findEntitiesGroupByRevisionType(3); assert TestTools.checkList(result.get(RevisionType.ADD)); assert TestTools.checkList(result.get(RevisionType.MOD)); assert TestTools.checkList(result.get(RevisionType.DEL), site, ste); @@ -144,14 +145,14 @@ public class DefaultTrackingEntitiesTest extends AbstractEntityTest { StrTestEntity ste = new StrTestEntity("x", steId); StrIntTestEntity site = new StrIntTestEntity("y", 1, siteId); - assert TestTools.checkList(getAuditReader().findEntitiesChangedInRevision(1, RevisionType.ADD), ste, site); + assert TestTools.checkList(getEntitiesChangedInRevisionManager().findEntities(1, RevisionType.ADD), ste, site); } @Test public void testFindChangedEntitiesByRevisionTypeMOD() { StrIntTestEntity site = new StrIntTestEntity("y", 2, siteId); - assert TestTools.checkList(getAuditReader().findEntitiesChangedInRevision(2, RevisionType.MOD), site); + assert TestTools.checkList(getEntitiesChangedInRevisionManager().findEntities(2, RevisionType.MOD), site); } @Test @@ -159,20 +160,24 @@ public class DefaultTrackingEntitiesTest extends AbstractEntityTest { StrTestEntity ste = new StrTestEntity(null, steId); StrIntTestEntity site = new StrIntTestEntity(null, null, siteId); - assert TestTools.checkList(getAuditReader().findEntitiesChangedInRevision(3, RevisionType.DEL), ste, site); + assert TestTools.checkList(getEntitiesChangedInRevisionManager().findEntities(3, RevisionType.DEL), ste, site); } @Test public void testFindEntityTypesChangedInRevision() { assert TestTools.makeSet(Pair.make(StrTestEntity.class.getName(), StrTestEntity.class), Pair.make(StrIntTestEntity.class.getName(), StrIntTestEntity.class)) - .equals(getAuditReader().findEntityTypesChangedInRevision(1)); + .equals(getEntitiesChangedInRevisionManager().findEntityTypes(1)); assert TestTools.makeSet(Pair.make(StrIntTestEntity.class.getName(), StrIntTestEntity.class)) - .equals(getAuditReader().findEntityTypesChangedInRevision(2)); + .equals(getEntitiesChangedInRevisionManager().findEntityTypes(2)); assert TestTools.makeSet(Pair.make(StrTestEntity.class.getName(), StrTestEntity.class), Pair.make(StrIntTestEntity.class.getName(), StrIntTestEntity.class)) - .equals(getAuditReader().findEntityTypesChangedInRevision(3)); + .equals(getEntitiesChangedInRevisionManager().findEntityTypes(3)); + } + + private EntitiesChangedInRevisionManager getEntitiesChangedInRevisionManager() { + return getAuditReader().getEntitiesChangedInRevisionManager(); } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/trackmodifiedentities/EntityNamesTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/trackmodifiedentities/EntityNamesTest.java index c3260ef5b0..af631865a4 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/trackmodifiedentities/EntityNamesTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/trackmodifiedentities/EntityNamesTest.java @@ -64,9 +64,9 @@ public class EntityNamesTest extends AbstractSessionTest { public void testModifiedEntityTypes() { assert TestTools.makeSet(Pair.make(Car.class.getName(), Car.class), Pair.make("Personaje", Person.class)) - .equals(getAuditReader().findEntityTypesChangedInRevision(1)); + .equals(getAuditReader().getEntitiesChangedInRevisionManager().findEntityTypes(1)); assert TestTools.makeSet(Pair.make(Car.class.getName(), Car.class), Pair.make("Personaje", Person.class)) - .equals(getAuditReader().findEntityTypesChangedInRevision(2)); + .equals(getAuditReader().getEntitiesChangedInRevisionManager().findEntityTypes(2)); } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/trackmodifiedentities/TrackingEntitiesMultipleChangesTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/trackmodifiedentities/TrackingEntitiesMultipleChangesTest.java index 0e683e5ed6..bf02228a45 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/trackmodifiedentities/TrackingEntitiesMultipleChangesTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/trackmodifiedentities/TrackingEntitiesMultipleChangesTest.java @@ -1,6 +1,7 @@ package org.hibernate.envers.test.integration.reventity.trackmodifiedentities; import org.hibernate.ejb.Ejb3Configuration; +import org.hibernate.envers.EntitiesChangedInRevisionManager; import org.hibernate.envers.test.AbstractEntityTest; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.StrTestEntity; @@ -59,7 +60,7 @@ public class TrackingEntitiesMultipleChangesTest extends AbstractEntityTest { StrTestEntity ste1 = new StrTestEntity("x", steId1); StrTestEntity ste2 = new StrTestEntity("y", steId2); - assert Arrays.asList(ste1, ste2).equals(getAuditReader().findEntitiesChangedInRevision(1)); + assert Arrays.asList(ste1, ste2).equals(getEntitiesChangedInRevisionManager().findEntities(1)); } @Test @@ -67,13 +68,17 @@ public class TrackingEntitiesMultipleChangesTest extends AbstractEntityTest { StrTestEntity ste1 = new StrTestEntity("z", steId1); StrTestEntity ste2 = new StrTestEntity(null, steId2); - assert Arrays.asList(ste1, ste2).equals(getAuditReader().findEntitiesChangedInRevision(2)); + assert Arrays.asList(ste1, ste2).equals(getEntitiesChangedInRevisionManager().findEntities(2)); } @Test public void testTrackUpdateAndRemoveTheSameEntity() { StrTestEntity ste1 = new StrTestEntity(null, steId1); - assert Arrays.asList(ste1).equals(getAuditReader().findEntitiesChangedInRevision(3)); + assert Arrays.asList(ste1).equals(getEntitiesChangedInRevisionManager().findEntities(3)); + } + + private EntitiesChangedInRevisionManager getEntitiesChangedInRevisionManager() { + return getAuditReader().getEntitiesChangedInRevisionManager(); } } \ No newline at end of file