use of org.hibernate.envers.test.entities.StrIntTestEntity in project hibernate-orm by hibernate.
the class StoreDeletedData method testMaximizeInDisjunction.
@Test
@TestForIssue(jiraKey = "HHH-7800")
public void testMaximizeInDisjunction() {
List<Integer> queryIds = Arrays.asList(id2, id3);
AuditDisjunction disjunction = AuditEntity.disjunction();
for (Integer id : queryIds) {
AuditCriterion crit = AuditEntity.revisionNumber().maximize().add(AuditEntity.id().eq(id)).add(AuditEntity.revisionType().ne(RevisionType.DEL));
disjunction.add(crit);
// Workaround: using this line instead works correctly:
// disjunction.add(AuditEntity.conjunction().add(crit));
}
List<?> beforeDeletionRevisions = getAuditReader().createQuery().forRevisionsOfEntity(StrIntTestEntity.class, false, false).add(disjunction).addOrder(AuditEntity.property("id").asc()).getResultList();
Assert.assertEquals(2, beforeDeletionRevisions.size());
Object[] result1 = (Object[]) beforeDeletionRevisions.get(0);
Object[] result2 = (Object[]) beforeDeletionRevisions.get(1);
Assert.assertEquals(new StrIntTestEntity("b", 20, id2), result1[0]);
// Making sure that we have received an entity added at revision 3.
Assert.assertEquals(3, ((SequenceIdRevisionEntity) result1[1]).getId());
Assert.assertEquals(RevisionType.ADD, result1[2]);
Assert.assertEquals(new StrIntTestEntity("c", 30, id3), result2[0]);
// Making sure that we have received an entity added at revision 3.
Assert.assertEquals(3, ((SequenceIdRevisionEntity) result2[1]).getId());
Assert.assertEquals(RevisionType.ADD, result2[2]);
}
use of org.hibernate.envers.test.entities.StrIntTestEntity in project hibernate-orm by hibernate.
the class CustomRevEntityQuery method initData.
@Test
@Priority(10)
public void initData() throws InterruptedException {
// 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();
id2 = site2.getId();
em.getTransaction().commit();
Thread.sleep(100);
timestamp = System.currentTimeMillis();
Thread.sleep(100);
// Revision 2
em.getTransaction().begin();
site1 = em.find(StrIntTestEntity.class, id1);
site1.setStr1("c");
em.getTransaction().commit();
}
use of org.hibernate.envers.test.entities.StrIntTestEntity in project hibernate-orm by hibernate.
the class MaximalizePropertyQuery 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);
StrIntTestEntity site3 = new StrIntTestEntity("c", 42);
StrIntTestEntity site4 = new StrIntTestEntity("d", 52);
em.persist(site1);
em.persist(site2);
em.persist(site3);
em.persist(site4);
id1 = site1.getId();
id2 = site2.getId();
id3 = site3.getId();
id4 = site4.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(30);
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();
// Revision 5
em.getTransaction().begin();
site4 = em.find(StrIntTestEntity.class, id4);
em.remove(site4);
em.getTransaction().commit();
}
use of org.hibernate.envers.test.entities.StrIntTestEntity in project hibernate-orm by hibernate.
the class TotalAuditParentsTest method testCompleteAuditParents.
@Test
public void testCompleteAuditParents() {
// expectedBaby.notAudited shall be null, because it is not audited.
BabyCompleteEntity expectedBaby = new BabyCompleteEntity(babyCompleteId, "grandparent 1", null, "parent 1", "child 1", new StrIntTestEntity("data 1", 1, siteCompleteId), "baby 1");
BabyCompleteEntity baby = getAuditReader().find(BabyCompleteEntity.class, babyCompleteId, 1);
Assert.assertEquals(expectedBaby, baby);
Assert.assertEquals(expectedBaby.getRelation().getId(), baby.getRelation().getId());
}
use of org.hibernate.envers.test.entities.StrIntTestEntity in project hibernate-orm by hibernate.
the class DeletedEntities 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", 11);
em.persist(site1);
em.persist(site2);
id2 = site2.getId();
em.getTransaction().commit();
// Revision 2
em.getTransaction().begin();
site2 = em.find(StrIntTestEntity.class, id2);
em.remove(site2);
em.getTransaction().commit();
}
Aggregations