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);
}
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);
}
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;
}
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;
}
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));
}
Aggregations