Search in sources :

Example 6 with RevisionType

use of org.hibernate.envers.RevisionType in project hibernate-orm by hibernate.

the class SimpleQuery method testEntitiesChangedAtRevision.

@Test
public void testEntitiesChangedAtRevision() {
    StrIntTestEntity site1 = new StrIntTestEntity("aBc", 10, id1);
    StrIntTestEntity site2 = new StrIntTestEntity("a", 20, id2);
    List result = getAuditReader().createQuery().forEntitiesModifiedAtRevision(StrIntTestEntity.class, 2).getResultList();
    RevisionType revisionType = (RevisionType) getAuditReader().createQuery().forEntitiesModifiedAtRevision(StrIntTestEntity.class, 2).addProjection(AuditEntity.revisionType()).add(AuditEntity.id().eq(id1)).getSingleResult();
    Assert.assertTrue(TestTools.checkCollection(result, site1, site2));
    Assert.assertEquals(revisionType, RevisionType.MOD);
}
Also used : StrIntTestEntity(org.hibernate.envers.test.entities.StrIntTestEntity) RevisionType(org.hibernate.envers.RevisionType) List(java.util.List) Test(org.junit.Test)

Example 7 with RevisionType

use of org.hibernate.envers.RevisionType in project hibernate-orm by hibernate.

the class SimpleQuery method testEntitiesRemovedAtRevision.

@Test
public void testEntitiesRemovedAtRevision() {
    StrIntTestEntity site1 = new StrIntTestEntity(null, null, id1);
    List result = getAuditReader().createQuery().forEntitiesModifiedAtRevision(StrIntTestEntity.class, 4).getResultList();
    RevisionType revisionType = (RevisionType) getAuditReader().createQuery().forEntitiesModifiedAtRevision(StrIntTestEntity.class, 4).addProjection(AuditEntity.revisionType()).add(AuditEntity.id().eq(id1)).getSingleResult();
    Assert.assertTrue(TestTools.checkCollection(result, site1));
    Assert.assertEquals(revisionType, RevisionType.DEL);
}
Also used : StrIntTestEntity(org.hibernate.envers.test.entities.StrIntTestEntity) RevisionType(org.hibernate.envers.RevisionType) List(java.util.List) Test(org.junit.Test)

Example 8 with RevisionType

use of org.hibernate.envers.RevisionType in project hibernate-orm by hibernate.

the class CrossTypeRevisionChangesReaderImpl method findEntitiesGroupByRevisionType.

@Override
@SuppressWarnings({ "unchecked" })
public Map<RevisionType, List<Object>> findEntitiesGroupByRevisionType(Number revision) throws IllegalStateException, IllegalArgumentException {
    final Set<Pair<String, Class>> entityTypes = findEntityTypes(revision);
    final Map<RevisionType, List<Object>> result = new HashMap<>();
    for (RevisionType revisionType : RevisionType.values()) {
        result.put(revisionType, new ArrayList<>());
        for (Pair<String, Class> type : entityTypes) {
            final List<Object> list = auditReaderImplementor.createQuery().forEntitiesModifiedAtRevision(type.getSecond(), type.getFirst(), revision).add(new RevisionTypeAuditExpression(null, revisionType, "=")).getResultList();
            result.get(revisionType).addAll(list);
        }
    }
    return result;
}
Also used : HashMap(java.util.HashMap) RevisionType(org.hibernate.envers.RevisionType) ArrayList(java.util.ArrayList) List(java.util.List) RevisionTypeAuditExpression(org.hibernate.envers.query.criteria.internal.RevisionTypeAuditExpression) Pair(org.hibernate.envers.tools.Pair)

Example 9 with RevisionType

use of org.hibernate.envers.RevisionType in project hibernate-orm by hibernate.

the class QueryBuilder method toQuery.

public Query toQuery(Session session) {
    final StringBuilder querySb = new StringBuilder();
    final Map<String, Object> queryParamValues = new HashMap<>();
    build(querySb, queryParamValues);
    final Query query = session.createQuery(querySb.toString());
    for (Map.Entry<String, Object> paramValue : queryParamValues.entrySet()) {
        if (paramValue.getValue() instanceof RevisionType) {
            // this is needed when the ClassicQueryTranslatorFactory is used
            query.setParameter(paramValue.getKey(), paramValue.getValue(), new CustomType(new RevisionTypeType()));
        } else {
            query.setParameter(paramValue.getKey(), paramValue.getValue());
        }
    }
    return query;
}
Also used : CustomType(org.hibernate.type.CustomType) Query(org.hibernate.query.Query) HashMap(java.util.HashMap) RevisionType(org.hibernate.envers.RevisionType) RevisionTypeType(org.hibernate.envers.internal.entities.RevisionTypeType) HashMap(java.util.HashMap) Map(java.util.Map)

Example 10 with RevisionType

use of org.hibernate.envers.RevisionType in project hibernate-orm by hibernate.

the class DefaultTrackingEntitiesTest method testTrackAddedEntitiesGroupByRevisionType.

@Test
public void testTrackAddedEntitiesGroupByRevisionType() {
    StrTestEntity ste = new StrTestEntity("x", steId);
    StrIntTestEntity site = new StrIntTestEntity("y", 1, siteId);
    Map<RevisionType, List<Object>> result = getCrossTypeRevisionChangesReader().findEntitiesGroupByRevisionType(1);
    assert TestTools.checkCollection(result.get(RevisionType.ADD), site, ste);
    assert TestTools.checkCollection(result.get(RevisionType.MOD));
    assert TestTools.checkCollection(result.get(RevisionType.DEL));
}
Also used : StrIntTestEntity(org.hibernate.envers.test.entities.StrIntTestEntity) StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) RevisionType(org.hibernate.envers.RevisionType) List(java.util.List) Test(org.junit.Test)

Aggregations

RevisionType (org.hibernate.envers.RevisionType)10 List (java.util.List)7 StrIntTestEntity (org.hibernate.envers.test.entities.StrIntTestEntity)6 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 StrTestEntity (org.hibernate.envers.test.entities.StrTestEntity)2 Serializable (java.io.Serializable)1 Map (java.util.Map)1 EntityManager (javax.persistence.EntityManager)1 Query (javax.persistence.Query)1 SequenceIdRevisionEntity (org.hibernate.envers.enhanced.SequenceIdRevisionEntity)1 RevisionTypeType (org.hibernate.envers.internal.entities.RevisionTypeType)1 PersistentCollectionChangeData (org.hibernate.envers.internal.entities.mapper.PersistentCollectionChangeData)1 IdMapper (org.hibernate.envers.internal.entities.mapper.id.IdMapper)1 AuditWorkUnit (org.hibernate.envers.internal.synchronization.work.AuditWorkUnit)1 CollectionChangeWorkUnit (org.hibernate.envers.internal.synchronization.work.CollectionChangeWorkUnit)1 FakeBidirectionalRelationWorkUnit (org.hibernate.envers.internal.synchronization.work.FakeBidirectionalRelationWorkUnit)1 PersistentCollectionChangeWorkUnit (org.hibernate.envers.internal.synchronization.work.PersistentCollectionChangeWorkUnit)1 RevisionTypeAuditExpression (org.hibernate.envers.query.criteria.internal.RevisionTypeAuditExpression)1