use of org.hibernate.envers.test.entities.StrIntTestEntity in project hibernate-orm by hibernate.
the class MaximalizePropertyQuery method testAllLatestRevisionsOfEntityType.
@Test
@TestForIssue(jiraKey = "HHH-7827")
public void testAllLatestRevisionsOfEntityType() {
List result = getAuditReader().createQuery().forRevisionsOfEntity(StrIntTestEntity.class, false, true).add(AuditEntity.revisionNumber().maximize().computeAggregationInInstanceContext()).addOrder(AuditEntity.property("id").asc()).getResultList();
Assert.assertEquals(4, result.size());
Object[] result1 = (Object[]) result.get(0);
Object[] result2 = (Object[]) result.get(1);
Object[] result3 = (Object[]) result.get(2);
Object[] result4 = (Object[]) result.get(3);
checkRevisionData(result1, 4, RevisionType.MOD, new StrIntTestEntity("d", 5, id1));
checkRevisionData(result2, 4, RevisionType.MOD, new StrIntTestEntity("a", 20, id2));
checkRevisionData(result3, 1, RevisionType.ADD, new StrIntTestEntity("c", 42, id3));
checkRevisionData(result4, 5, RevisionType.DEL, new StrIntTestEntity(null, null, id4));
}
use of org.hibernate.envers.test.entities.StrIntTestEntity in project hibernate-orm by hibernate.
the class MaximalizePropertyQuery method testMaximizeInDisjunction.
@Test
@TestForIssue(jiraKey = "HHH-7800")
public void testMaximizeInDisjunction() {
List<Integer> idsToQuery = Arrays.asList(id1, id3);
AuditDisjunction disjunction = AuditEntity.disjunction();
for (Integer id : idsToQuery) {
disjunction.add(AuditEntity.revisionNumber().maximize().add(AuditEntity.id().eq(id)));
}
List result = getAuditReader().createQuery().forRevisionsOfEntity(StrIntTestEntity.class, true, true).add(disjunction).getResultList();
Set<Integer> idsSeen = new HashSet<Integer>();
for (Object o : result) {
StrIntTestEntity entity = (StrIntTestEntity) o;
Integer id = entity.getId();
Assert.assertTrue("Entity with ID " + id + " returned but not queried for.", idsToQuery.contains(id));
if (!idsSeen.add(id)) {
Assert.fail("Multiple revisions returned with ID " + id + "; expected only one.");
}
}
}
use of org.hibernate.envers.test.entities.StrIntTestEntity in project hibernate-orm by hibernate.
the class RevisionConstraintQuery method testRevisionTypeEqQuery.
@Test
public void testRevisionTypeEqQuery() {
// The query shouldn't be ordered as always, otherwise - we get an exception.
List results = getAuditReader().createQuery().forRevisionsOfEntity(StrIntTestEntity.class, true, true).add(AuditEntity.id().eq(id1)).add(AuditEntity.revisionType().eq(RevisionType.MOD)).getResultList();
Assert.assertEquals(3, results.size());
Assert.assertEquals(new StrIntTestEntity("d", 10, id1), results.get(0));
Assert.assertEquals(new StrIntTestEntity("d", 1, id1), results.get(1));
Assert.assertEquals(new StrIntTestEntity("d", 5, id1), results.get(2));
}
use of org.hibernate.envers.test.entities.StrIntTestEntity in project hibernate-orm by hibernate.
the class RevisionConstraintQuery method initData.
@Test
@Priority(10)
public void initData() {
// Revision 1
EntityManager em = getEntityManager();
em.getTransaction().begin();
StrIntTestEntity site1 = new StrIntTestEntity("a", 10);
StrIntTestEntity site2 = new StrIntTestEntity("b", 15);
em.persist(site1);
em.persist(site2);
id1 = site1.getId();
Integer id2 = site2.getId();
em.getTransaction().commit();
// Revision 2
em.getTransaction().begin();
site1 = em.find(StrIntTestEntity.class, id1);
site2 = em.find(StrIntTestEntity.class, id2);
site1.setStr1("d");
site2.setNumber(20);
em.getTransaction().commit();
// Revision 3
em.getTransaction().begin();
site1 = em.find(StrIntTestEntity.class, id1);
site2 = em.find(StrIntTestEntity.class, id2);
site1.setNumber(1);
site2.setStr1("z");
em.getTransaction().commit();
// Revision 4
em.getTransaction().begin();
site1 = em.find(StrIntTestEntity.class, id1);
site2 = em.find(StrIntTestEntity.class, id2);
site1.setNumber(5);
site2.setStr1("a");
em.getTransaction().commit();
}
use of org.hibernate.envers.test.entities.StrIntTestEntity in project hibernate-orm by hibernate.
the class RevisionConstraintQuery method testRevisionTypeNeQuery.
@Test
public void testRevisionTypeNeQuery() {
// The query shouldn't be ordered as always, otherwise - we get an exception.
List results = getAuditReader().createQuery().forRevisionsOfEntity(StrIntTestEntity.class, true, true).add(AuditEntity.id().eq(id1)).add(AuditEntity.revisionType().ne(RevisionType.MOD)).getResultList();
Assert.assertEquals(1, results.size());
Assert.assertEquals(new StrIntTestEntity("a", 10, id1), results.get(0));
}
Aggregations