Search in sources :

Example 11 with StrIntTestEntity

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]);
}
Also used : StrIntTestEntity(org.hibernate.envers.test.entities.StrIntTestEntity) AuditDisjunction(org.hibernate.envers.query.criteria.AuditDisjunction) AuditCriterion(org.hibernate.envers.query.criteria.AuditCriterion) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 12 with StrIntTestEntity

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();
}
Also used : StrIntTestEntity(org.hibernate.envers.test.entities.StrIntTestEntity) EntityManager(javax.persistence.EntityManager) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 13 with StrIntTestEntity

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();
}
Also used : StrIntTestEntity(org.hibernate.envers.test.entities.StrIntTestEntity) EntityManager(javax.persistence.EntityManager) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 14 with StrIntTestEntity

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());
}
Also used : StrIntTestEntity(org.hibernate.envers.test.entities.StrIntTestEntity) Test(org.junit.Test)

Example 15 with StrIntTestEntity

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();
}
Also used : StrIntTestEntity(org.hibernate.envers.test.entities.StrIntTestEntity) EntityManager(javax.persistence.EntityManager) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Aggregations

StrIntTestEntity (org.hibernate.envers.test.entities.StrIntTestEntity)36 Test (org.junit.Test)36 List (java.util.List)14 EntityManager (javax.persistence.EntityManager)12 Priority (org.hibernate.envers.test.Priority)12 StrTestEntity (org.hibernate.envers.test.entities.StrTestEntity)8 TestForIssue (org.hibernate.testing.TestForIssue)7 RevisionType (org.hibernate.envers.RevisionType)6 HashSet (java.util.HashSet)3 AuditDisjunction (org.hibernate.envers.query.criteria.AuditDisjunction)2 AuditCriterion (org.hibernate.envers.query.criteria.AuditCriterion)1 EmbId (org.hibernate.envers.test.entities.ids.EmbId)1 EmbIdTestEntity (org.hibernate.envers.test.entities.ids.EmbIdTestEntity)1 MulId (org.hibernate.envers.test.entities.ids.MulId)1 MulIdTestEntity (org.hibernate.envers.test.entities.ids.MulIdTestEntity)1 CollectionRefEdEntity (org.hibernate.envers.test.entities.onetomany.CollectionRefEdEntity)1 CollectionRefIngEntity (org.hibernate.envers.test.entities.onetomany.CollectionRefIngEntity)1 SetRefIngEmbIdEntity (org.hibernate.envers.test.entities.onetomany.ids.SetRefIngEmbIdEntity)1