From 2fef8a4acc2c2e068dca4ed990ef1debd86a4aa2 Mon Sep 17 00:00:00 2001 From: Adam Warski Date: Fri, 11 Dec 2009 12:40:05 +0000 Subject: [PATCH] HHH-4670: - changing the way work unit collision is resolved: now work units are merged, the result is a work unit (possibly new) - work units should behave as immutable objects - test git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@18208 1b8cb986-b30d-0410-93ca-fae66ebed9b2 --- .../envers/synchronization/AuditSync.java | 22 ++++------- .../work/AbstractAuditWorkUnit.java | 3 +- .../synchronization/work/AddWorkUnit.java | 39 ++++++++++--------- .../synchronization/work/AuditWorkUnit.java | 2 +- .../work/CollectionChangeWorkUnit.java | 20 +++++----- .../synchronization/work/DelWorkUnit.java | 20 +++++----- .../synchronization/work/KeepCheckResult.java | 35 ----------------- .../synchronization/work/ModWorkUnit.java | 24 +++++++----- .../PersistentCollectionChangeWorkUnit.java | 37 +++++++++++------- ...cher.java => WorkUnitMergeDispatcher.java} | 6 +-- ...Visitor.java => WorkUnitMergeVisitor.java} | 10 ++--- .../integration/flush/DoubleFlushAddMod.java | 16 ++++++++ .../integration/flush/DoubleFlushModDel.java | 16 ++++++++ .../integration/flush/DoubleFlushModMod.java | 16 ++++++++ .../test/integration/flush/ManualFlush.java | 16 ++++++++ 15 files changed, 160 insertions(+), 122 deletions(-) delete mode 100644 envers/src/main/java/org/hibernate/envers/synchronization/work/KeepCheckResult.java rename envers/src/main/java/org/hibernate/envers/synchronization/work/{KeepCheckDispatcher.java => WorkUnitMergeDispatcher.java} (89%) rename envers/src/main/java/org/hibernate/envers/synchronization/work/{KeepCheckVisitor.java => WorkUnitMergeVisitor.java} (84%) diff --git a/envers/src/main/java/org/hibernate/envers/synchronization/AuditSync.java b/envers/src/main/java/org/hibernate/envers/synchronization/AuditSync.java index bc0c4bdb41..0865587e62 100644 --- a/envers/src/main/java/org/hibernate/envers/synchronization/AuditSync.java +++ b/envers/src/main/java/org/hibernate/envers/synchronization/AuditSync.java @@ -86,22 +86,16 @@ public class AuditSync implements Synchronization { if (usedIds.containsKey(usedIdsKey)) { AuditWorkUnit other = usedIds.get(usedIdsKey); - // The entity with entityId has two work units; checking which one should be kept. - switch (vwu.dispatch(other)) { - case FIRST: - // Simply not adding the second - break; + AuditWorkUnit result = vwu.dispatch(other); - case SECOND: - removeWorkUnit(other); - usedIds.put(usedIdsKey, vwu); - workUnits.offer(vwu); - break; + if (result != other) { + removeWorkUnit(other); - case NONE: - removeWorkUnit(other); - break; - } + if (result != null) { + usedIds.put(usedIdsKey, result); + workUnits.offer(result); + } // else: a null result means that no work unit should be kept + } // else: the result is the same as the work unit already added. No need to do anything. } else { usedIds.put(usedIdsKey, vwu); workUnits.offer(vwu); diff --git a/envers/src/main/java/org/hibernate/envers/synchronization/work/AbstractAuditWorkUnit.java b/envers/src/main/java/org/hibernate/envers/synchronization/work/AbstractAuditWorkUnit.java index e2c7261ea3..cee758d3d6 100644 --- a/envers/src/main/java/org/hibernate/envers/synchronization/work/AbstractAuditWorkUnit.java +++ b/envers/src/main/java/org/hibernate/envers/synchronization/work/AbstractAuditWorkUnit.java @@ -41,8 +41,7 @@ public abstract class AbstractAuditWorkUnit implements AuditWorkUnit { protected final SessionImplementor sessionImplementor; protected final AuditConfiguration verCfg; protected final Serializable id; - - private final String entityName; + protected final String entityName; private Object performedData; diff --git a/envers/src/main/java/org/hibernate/envers/synchronization/work/AddWorkUnit.java b/envers/src/main/java/org/hibernate/envers/synchronization/work/AddWorkUnit.java index 0108c6eab1..450d2383de 100644 --- a/envers/src/main/java/org/hibernate/envers/synchronization/work/AddWorkUnit.java +++ b/envers/src/main/java/org/hibernate/envers/synchronization/work/AddWorkUnit.java @@ -38,15 +38,22 @@ import org.hibernate.persister.entity.EntityPersister; * @author Adam Warski (adam at warski dot org) */ public class AddWorkUnit extends AbstractAuditWorkUnit implements AuditWorkUnit { - private final Object[] state; - private final String[] propertyNames; + private final Map data; public AddWorkUnit(SessionImplementor sessionImplementor, String entityName, AuditConfiguration verCfg, Serializable id, EntityPersister entityPersister, Object[] state) { super(sessionImplementor, entityName, verCfg, id); - this.state = state; - this.propertyNames = entityPersister.getPropertyNames(); + data = new HashMap(); + verCfg.getEntCfg().get(getEntityName()).getPropertyMapper().map(sessionImplementor, data, + entityPersister.getPropertyNames(), state, null); + } + + public AddWorkUnit(SessionImplementor sessionImplementor, String entityName, AuditConfiguration verCfg, + Serializable id, Map data) { + super(sessionImplementor, entityName, verCfg, id); + + this.data = data; } public boolean containsWork() { @@ -54,34 +61,30 @@ public class AddWorkUnit extends AbstractAuditWorkUnit implements AuditWorkUnit } public void perform(Session session, Object revisionData) { - Map data = new HashMap(); fillDataWithId(data, revisionData, RevisionType.ADD); - verCfg.getEntCfg().get(getEntityName()).getPropertyMapper().map(sessionImplementor, data, - propertyNames, state, null); - session.save(verCfg.getAuditEntCfg().getAuditEntityName(getEntityName()), data); setPerformed(data); } - public KeepCheckResult check(AddWorkUnit second) { - return KeepCheckResult.FIRST; + public AuditWorkUnit merge(AddWorkUnit second) { + return second; } - public KeepCheckResult check(ModWorkUnit second) { - return KeepCheckResult.SECOND; + public AuditWorkUnit merge(ModWorkUnit second) { + return new AddWorkUnit(sessionImplementor, entityName, verCfg, id, second.getData()); } - public KeepCheckResult check(DelWorkUnit second) { - return KeepCheckResult.NONE; + public AuditWorkUnit merge(DelWorkUnit second) { + return null; } - public KeepCheckResult check(CollectionChangeWorkUnit second) { - return KeepCheckResult.FIRST; + public AuditWorkUnit merge(CollectionChangeWorkUnit second) { + return this; } - public KeepCheckResult dispatch(KeepCheckVisitor first) { - return first.check(this); + public AuditWorkUnit dispatch(WorkUnitMergeVisitor first) { + return first.merge(this); } } diff --git a/envers/src/main/java/org/hibernate/envers/synchronization/work/AuditWorkUnit.java b/envers/src/main/java/org/hibernate/envers/synchronization/work/AuditWorkUnit.java index f6c2ee1df0..52090c5acb 100644 --- a/envers/src/main/java/org/hibernate/envers/synchronization/work/AuditWorkUnit.java +++ b/envers/src/main/java/org/hibernate/envers/synchronization/work/AuditWorkUnit.java @@ -28,7 +28,7 @@ import org.hibernate.Session; /** * @author Adam Warski (adam at warski dot org) */ -public interface AuditWorkUnit extends KeepCheckVisitor, KeepCheckDispatcher { +public interface AuditWorkUnit extends WorkUnitMergeVisitor, WorkUnitMergeDispatcher { Object getEntityId(); String getEntityName(); diff --git a/envers/src/main/java/org/hibernate/envers/synchronization/work/CollectionChangeWorkUnit.java b/envers/src/main/java/org/hibernate/envers/synchronization/work/CollectionChangeWorkUnit.java index 9b5d3a824b..04870d3a62 100644 --- a/envers/src/main/java/org/hibernate/envers/synchronization/work/CollectionChangeWorkUnit.java +++ b/envers/src/main/java/org/hibernate/envers/synchronization/work/CollectionChangeWorkUnit.java @@ -62,23 +62,23 @@ public class CollectionChangeWorkUnit extends AbstractAuditWorkUnit implements A setPerformed(data); } - public KeepCheckResult check(AddWorkUnit second) { - return KeepCheckResult.SECOND; + public AuditWorkUnit merge(AddWorkUnit second) { + return second; } - public KeepCheckResult check(ModWorkUnit second) { - return KeepCheckResult.SECOND; + public AuditWorkUnit merge(ModWorkUnit second) { + return second; } - public KeepCheckResult check(DelWorkUnit second) { - return KeepCheckResult.SECOND; + public AuditWorkUnit merge(DelWorkUnit second) { + return second; } - public KeepCheckResult check(CollectionChangeWorkUnit second) { - return KeepCheckResult.FIRST; + public AuditWorkUnit merge(CollectionChangeWorkUnit second) { + return this; } - public KeepCheckResult dispatch(KeepCheckVisitor first) { - return first.check(this); + public AuditWorkUnit dispatch(WorkUnitMergeVisitor first) { + return first.merge(this); } } diff --git a/envers/src/main/java/org/hibernate/envers/synchronization/work/DelWorkUnit.java b/envers/src/main/java/org/hibernate/envers/synchronization/work/DelWorkUnit.java index 0c1f2d54de..e5a1fcda7e 100644 --- a/envers/src/main/java/org/hibernate/envers/synchronization/work/DelWorkUnit.java +++ b/envers/src/main/java/org/hibernate/envers/synchronization/work/DelWorkUnit.java @@ -67,23 +67,23 @@ public class DelWorkUnit extends AbstractAuditWorkUnit implements AuditWorkUnit setPerformed(data); } - public KeepCheckResult check(AddWorkUnit second) { - return KeepCheckResult.NONE; + public AuditWorkUnit merge(AddWorkUnit second) { + return null; } - public KeepCheckResult check(ModWorkUnit second) { - return KeepCheckResult.NONE; + public AuditWorkUnit merge(ModWorkUnit second) { + return null; } - public KeepCheckResult check(DelWorkUnit second) { - return KeepCheckResult.FIRST; + public AuditWorkUnit merge(DelWorkUnit second) { + return this; } - public KeepCheckResult check(CollectionChangeWorkUnit second) { - return KeepCheckResult.FIRST; + public AuditWorkUnit merge(CollectionChangeWorkUnit second) { + return this; } - public KeepCheckResult dispatch(KeepCheckVisitor first) { - return first.check(this); + public AuditWorkUnit dispatch(WorkUnitMergeVisitor first) { + return first.merge(this); } } \ No newline at end of file diff --git a/envers/src/main/java/org/hibernate/envers/synchronization/work/KeepCheckResult.java b/envers/src/main/java/org/hibernate/envers/synchronization/work/KeepCheckResult.java deleted file mode 100644 index 3ecdfa9e5a..0000000000 --- a/envers/src/main/java/org/hibernate/envers/synchronization/work/KeepCheckResult.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Middleware LLC. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License, as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package org.hibernate.envers.synchronization.work; - -/** - * Possible outcomes of selecting which work unit to keep, in case there are two work units for the same entity - * with the same id. - * @author Adam Warski (adam at warski dot org) - */ -public enum KeepCheckResult { - FIRST, - SECOND, - NONE -} diff --git a/envers/src/main/java/org/hibernate/envers/synchronization/work/ModWorkUnit.java b/envers/src/main/java/org/hibernate/envers/synchronization/work/ModWorkUnit.java index 788686f983..cdfde7dac2 100644 --- a/envers/src/main/java/org/hibernate/envers/synchronization/work/ModWorkUnit.java +++ b/envers/src/main/java/org/hibernate/envers/synchronization/work/ModWorkUnit.java @@ -62,23 +62,27 @@ public class ModWorkUnit extends AbstractAuditWorkUnit implements AuditWorkUnit setPerformed(data); } - public KeepCheckResult check(AddWorkUnit second) { - return KeepCheckResult.FIRST; + public Map getData() { + return data; } - public KeepCheckResult check(ModWorkUnit second) { - return KeepCheckResult.SECOND; + public AuditWorkUnit merge(AddWorkUnit second) { + return this; } - public KeepCheckResult check(DelWorkUnit second) { - return KeepCheckResult.SECOND; + public AuditWorkUnit merge(ModWorkUnit second) { + return second; } - public KeepCheckResult check(CollectionChangeWorkUnit second) { - return KeepCheckResult.FIRST; + public AuditWorkUnit merge(DelWorkUnit second) { + return second; } - public KeepCheckResult dispatch(KeepCheckVisitor first) { - return first.check(this); + public AuditWorkUnit merge(CollectionChangeWorkUnit second) { + return this; + } + + public AuditWorkUnit dispatch(WorkUnitMergeVisitor first) { + return first.merge(this); } } \ No newline at end of file diff --git a/envers/src/main/java/org/hibernate/envers/synchronization/work/PersistentCollectionChangeWorkUnit.java b/envers/src/main/java/org/hibernate/envers/synchronization/work/PersistentCollectionChangeWorkUnit.java index a795d7939b..53245ba785 100644 --- a/envers/src/main/java/org/hibernate/envers/synchronization/work/PersistentCollectionChangeWorkUnit.java +++ b/envers/src/main/java/org/hibernate/envers/synchronization/work/PersistentCollectionChangeWorkUnit.java @@ -58,6 +58,16 @@ public class PersistentCollectionChangeWorkUnit extends AbstractAuditWorkUnit im .mapCollectionChanges(referencingPropertyName, collection, snapshot, id); } + public PersistentCollectionChangeWorkUnit(SessionImplementor sessionImplementor, String entityName, + AuditConfiguration verCfg, Serializable id, + List collectionChanges, + String referencingPropertyName) { + super(sessionImplementor, entityName, verCfg, id); + + this.collectionChanges = collectionChanges; + this.referencingPropertyName = referencingPropertyName; + } + public boolean containsWork() { return collectionChanges != null && collectionChanges.size() != 0; } @@ -83,23 +93,23 @@ public class PersistentCollectionChangeWorkUnit extends AbstractAuditWorkUnit im return collectionChanges; } - public KeepCheckResult check(AddWorkUnit second) { + public AuditWorkUnit merge(AddWorkUnit second) { return null; } - public KeepCheckResult check(ModWorkUnit second) { + public AuditWorkUnit merge(ModWorkUnit second) { return null; } - public KeepCheckResult check(DelWorkUnit second) { + public AuditWorkUnit merge(DelWorkUnit second) { return null; } - public KeepCheckResult check(CollectionChangeWorkUnit second) { + public AuditWorkUnit merge(CollectionChangeWorkUnit second) { return null; } - public KeepCheckResult dispatch(KeepCheckVisitor first) { + public AuditWorkUnit dispatch(WorkUnitMergeVisitor first) { if (first instanceof PersistentCollectionChangeWorkUnit) { PersistentCollectionChangeWorkUnit original = (PersistentCollectionChangeWorkUnit) first; @@ -115,26 +125,25 @@ public class PersistentCollectionChangeWorkUnit extends AbstractAuditWorkUnit im persistentCollectionChangeData); } - // Storing the current changes - List newChanges = new ArrayList(); - newChanges.addAll(collectionChanges); + // This will be the list with the resulting (merged) changes. + List mergedChanges = new ArrayList(); - // And building the change list again - collectionChanges.clear(); + // Including only those original changes, which are not overshadowed by new ones. for (PersistentCollectionChangeData originalCollectionChangeData : original.getCollectionChanges()) { if (!newChangesIdMap.containsKey(getOriginalId(originalCollectionChangeData))) { - collectionChanges.add(originalCollectionChangeData); + mergedChanges.add(originalCollectionChangeData); } } // Finally adding all of the new changes to the end of the list - collectionChanges.addAll(newChanges); + mergedChanges.addAll(getCollectionChanges()); + + return new PersistentCollectionChangeWorkUnit(sessionImplementor, entityName, verCfg, id, mergedChanges, + referencingPropertyName); } else { throw new RuntimeException("Trying to merge a " + first + " with a PersitentCollectionChangeWorkUnit. " + "This is not really possible."); } - - return KeepCheckResult.SECOND; } private Object getOriginalId(PersistentCollectionChangeData persistentCollectionChangeData) { diff --git a/envers/src/main/java/org/hibernate/envers/synchronization/work/KeepCheckDispatcher.java b/envers/src/main/java/org/hibernate/envers/synchronization/work/WorkUnitMergeDispatcher.java similarity index 89% rename from envers/src/main/java/org/hibernate/envers/synchronization/work/KeepCheckDispatcher.java rename to envers/src/main/java/org/hibernate/envers/synchronization/work/WorkUnitMergeDispatcher.java index 700633508d..c8ad2a2f3c 100644 --- a/envers/src/main/java/org/hibernate/envers/synchronization/work/KeepCheckDispatcher.java +++ b/envers/src/main/java/org/hibernate/envers/synchronization/work/WorkUnitMergeDispatcher.java @@ -27,11 +27,11 @@ package org.hibernate.envers.synchronization.work; * Visitor patter dispatcher. * @author Adam Warski (adam at warski dot org) */ -public interface KeepCheckDispatcher { +public interface WorkUnitMergeDispatcher { /** * Shuold be invoked on the second work unit. * @param first First work unit (that is, the one added earlier). - * @return Which work unit should be kept. + * @return The work unit that is the result of the merge. */ - KeepCheckResult dispatch(KeepCheckVisitor first); + AuditWorkUnit dispatch(WorkUnitMergeVisitor first); } diff --git a/envers/src/main/java/org/hibernate/envers/synchronization/work/KeepCheckVisitor.java b/envers/src/main/java/org/hibernate/envers/synchronization/work/WorkUnitMergeVisitor.java similarity index 84% rename from envers/src/main/java/org/hibernate/envers/synchronization/work/KeepCheckVisitor.java rename to envers/src/main/java/org/hibernate/envers/synchronization/work/WorkUnitMergeVisitor.java index 3f8385ef29..4f5d958dd7 100644 --- a/envers/src/main/java/org/hibernate/envers/synchronization/work/KeepCheckVisitor.java +++ b/envers/src/main/java/org/hibernate/envers/synchronization/work/WorkUnitMergeVisitor.java @@ -27,9 +27,9 @@ package org.hibernate.envers.synchronization.work; * Visitor pattern visitor. All methods should be invoked on the first work unit. * @author Adam Warski (adam at warski dot org) */ -public interface KeepCheckVisitor { - KeepCheckResult check(AddWorkUnit second); - KeepCheckResult check(ModWorkUnit second); - KeepCheckResult check(DelWorkUnit second); - KeepCheckResult check(CollectionChangeWorkUnit second); +public interface WorkUnitMergeVisitor { + AuditWorkUnit merge(AddWorkUnit second); + AuditWorkUnit merge(ModWorkUnit second); + AuditWorkUnit merge(DelWorkUnit second); + AuditWorkUnit merge(CollectionChangeWorkUnit second); } diff --git a/envers/src/test/java/org/hibernate/envers/test/integration/flush/DoubleFlushAddMod.java b/envers/src/test/java/org/hibernate/envers/test/integration/flush/DoubleFlushAddMod.java index 0c8c910cc5..318fd010c6 100644 --- a/envers/src/test/java/org/hibernate/envers/test/integration/flush/DoubleFlushAddMod.java +++ b/envers/src/test/java/org/hibernate/envers/test/integration/flush/DoubleFlushAddMod.java @@ -24,11 +24,15 @@ package org.hibernate.envers.test.integration.flush; import java.util.Arrays; +import java.util.List; import javax.persistence.EntityManager; import org.hibernate.envers.test.entities.StrTestEntity; +import org.hibernate.envers.query.AuditEntity; +import org.hibernate.envers.RevisionType; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; +import static org.testng.Assert.*; import org.hibernate.FlushMode; @@ -87,4 +91,16 @@ public class DoubleFlushAddMod extends AbstractFlushTest { assert getAuditReader().find(StrTestEntity.class, id, 1).equals(ver1); assert getAuditReader().find(StrTestEntity.class, id, 2).equals(ver2); } + + @Test + public void testRevisionTypes() { + @SuppressWarnings({"unchecked"}) List results = + getAuditReader().createQuery() + .forRevisionsOfEntity(StrTestEntity.class, false, true) + .add(AuditEntity.id().eq(id)) + .getResultList(); + + assertEquals(results.get(0)[2], RevisionType.ADD); + assertEquals(results.get(1)[2], RevisionType.MOD); + } } \ No newline at end of file diff --git a/envers/src/test/java/org/hibernate/envers/test/integration/flush/DoubleFlushModDel.java b/envers/src/test/java/org/hibernate/envers/test/integration/flush/DoubleFlushModDel.java index 2886f91152..fe4bb87a82 100644 --- a/envers/src/test/java/org/hibernate/envers/test/integration/flush/DoubleFlushModDel.java +++ b/envers/src/test/java/org/hibernate/envers/test/integration/flush/DoubleFlushModDel.java @@ -24,11 +24,15 @@ package org.hibernate.envers.test.integration.flush; import java.util.Arrays; +import java.util.List; import javax.persistence.EntityManager; import org.hibernate.envers.test.entities.StrTestEntity; +import org.hibernate.envers.query.AuditEntity; +import org.hibernate.envers.RevisionType; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; +import static org.testng.Assert.assertEquals; import org.hibernate.FlushMode; @@ -83,4 +87,16 @@ public class DoubleFlushModDel extends AbstractFlushTest { assert getAuditReader().find(StrTestEntity.class, id, 1).equals(ver1); assert getAuditReader().find(StrTestEntity.class, id, 2) == null; } + + @Test + public void testRevisionTypes() { + @SuppressWarnings({"unchecked"}) List results = + getAuditReader().createQuery() + .forRevisionsOfEntity(StrTestEntity.class, false, true) + .add(AuditEntity.id().eq(id)) + .getResultList(); + + assertEquals(results.get(0)[2], RevisionType.ADD); + assertEquals(results.get(1)[2], RevisionType.DEL); + } } \ No newline at end of file diff --git a/envers/src/test/java/org/hibernate/envers/test/integration/flush/DoubleFlushModMod.java b/envers/src/test/java/org/hibernate/envers/test/integration/flush/DoubleFlushModMod.java index cdbce54d26..a41a529b06 100644 --- a/envers/src/test/java/org/hibernate/envers/test/integration/flush/DoubleFlushModMod.java +++ b/envers/src/test/java/org/hibernate/envers/test/integration/flush/DoubleFlushModMod.java @@ -24,11 +24,15 @@ package org.hibernate.envers.test.integration.flush; import java.util.Arrays; +import java.util.List; import javax.persistence.EntityManager; import org.hibernate.envers.test.entities.StrTestEntity; +import org.hibernate.envers.query.AuditEntity; +import org.hibernate.envers.RevisionType; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; +import static org.testng.Assert.assertEquals; import org.hibernate.FlushMode; @@ -84,4 +88,16 @@ public class DoubleFlushModMod extends AbstractFlushTest { assert getAuditReader().find(StrTestEntity.class, id, 1).equals(ver1); assert getAuditReader().find(StrTestEntity.class, id, 2).equals(ver2); } + + @Test + public void testRevisionTypes() { + @SuppressWarnings({"unchecked"}) List results = + getAuditReader().createQuery() + .forRevisionsOfEntity(StrTestEntity.class, false, true) + .add(AuditEntity.id().eq(id)) + .getResultList(); + + assertEquals(results.get(0)[2], RevisionType.ADD); + assertEquals(results.get(1)[2], RevisionType.MOD); + } } \ No newline at end of file diff --git a/envers/src/test/java/org/hibernate/envers/test/integration/flush/ManualFlush.java b/envers/src/test/java/org/hibernate/envers/test/integration/flush/ManualFlush.java index f2f2b86bfd..4d9e090d6a 100644 --- a/envers/src/test/java/org/hibernate/envers/test/integration/flush/ManualFlush.java +++ b/envers/src/test/java/org/hibernate/envers/test/integration/flush/ManualFlush.java @@ -24,11 +24,15 @@ package org.hibernate.envers.test.integration.flush; import java.util.Arrays; +import java.util.List; import javax.persistence.EntityManager; import org.hibernate.envers.test.entities.StrTestEntity; +import org.hibernate.envers.query.AuditEntity; +import org.hibernate.envers.RevisionType; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; +import static org.testng.Assert.assertEquals; import org.hibernate.FlushMode; @@ -96,4 +100,16 @@ public class ManualFlush extends AbstractFlushTest { public void testCurrent() { assert getEntityManager().find(StrTestEntity.class, id).equals(new StrTestEntity("z", id)); } + + @Test + public void testRevisionTypes() { + @SuppressWarnings({"unchecked"}) List results = + getAuditReader().createQuery() + .forRevisionsOfEntity(StrTestEntity.class, false, true) + .add(AuditEntity.id().eq(id)) + .getResultList(); + + assertEquals(results.get(0)[2], RevisionType.ADD); + assertEquals(results.get(1)[2], RevisionType.MOD); + } }