Search in sources :

Example 6 with StrIntTestEntity

use of org.hibernate.envers.test.entities.StrIntTestEntity in project hibernate-orm by hibernate.

the class SimpleQuery method testEntitiesPropertyEqualsQuery.

@Test
public void testEntitiesPropertyEqualsQuery() {
    List ver1 = getAuditReader().createQuery().forEntitiesAtRevision(StrIntTestEntity.class, 1).add(AuditEntity.property("str1").eq("a")).getResultList();
    List ver2 = getAuditReader().createQuery().forEntitiesAtRevision(StrIntTestEntity.class, 2).add(AuditEntity.property("str1").eq("a")).getResultList();
    List ver3 = getAuditReader().createQuery().forEntitiesAtRevision(StrIntTestEntity.class, 3).add(AuditEntity.property("str1").eq("a")).getResultList();
    assert new HashSet(ver1).equals(TestTools.makeSet(new StrIntTestEntity("a", 10, id1), new StrIntTestEntity("a", 10, id2)));
    assert new HashSet(ver2).equals(TestTools.makeSet(new StrIntTestEntity("a", 20, id2)));
    assert new HashSet(ver3).equals(TestTools.makeSet(new StrIntTestEntity("a", 20, id2), new StrIntTestEntity("a", 5, id3)));
}
Also used : StrIntTestEntity(org.hibernate.envers.test.entities.StrIntTestEntity) List(java.util.List) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 7 with StrIntTestEntity

use of org.hibernate.envers.test.entities.StrIntTestEntity in project hibernate-orm by hibernate.

the class SimpleQuery method testEntitiesAddedAtRevision.

@Test
public void testEntitiesAddedAtRevision() {
    StrIntTestEntity site1 = new StrIntTestEntity("a", 10, id1);
    StrIntTestEntity site2 = new StrIntTestEntity("a", 10, id2);
    StrIntTestEntity site3 = new StrIntTestEntity("b", 5, id3);
    List result = getAuditReader().createQuery().forEntitiesModifiedAtRevision(StrIntTestEntity.class, StrIntTestEntity.class.getName(), 1).getResultList();
    RevisionType revisionType = (RevisionType) getAuditReader().createQuery().forEntitiesModifiedAtRevision(StrIntTestEntity.class, 1).addProjection(AuditEntity.revisionType()).add(AuditEntity.id().eq(id1)).getSingleResult();
    Assert.assertTrue(TestTools.checkCollection(result, site1, site2, site3));
    Assert.assertEquals(revisionType, RevisionType.ADD);
}
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 StrIntTestEntity

use of org.hibernate.envers.test.entities.StrIntTestEntity in project hibernate-orm by hibernate.

the class SimpleQuery method testIdPropertyRestriction.

@Test
@TestForIssue(jiraKey = "HHH-8567")
public void testIdPropertyRestriction() {
    StrIntTestEntity ver2 = (StrIntTestEntity) getAuditReader().createQuery().forEntitiesAtRevision(StrIntTestEntity.class, 2).add(AuditEntity.property("id").eq(id2)).getSingleResult();
    Assert.assertEquals(new StrIntTestEntity("a", 20, id2), ver2);
}
Also used : StrIntTestEntity(org.hibernate.envers.test.entities.StrIntTestEntity) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 9 with StrIntTestEntity

use of org.hibernate.envers.test.entities.StrIntTestEntity in project hibernate-orm by hibernate.

the class SimpleQuery 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("a", 10);
    StrIntTestEntity site3 = new StrIntTestEntity("b", 5);
    em.persist(site1);
    em.persist(site2);
    em.persist(site3);
    id1 = site1.getId();
    id2 = site2.getId();
    id3 = site3.getId();
    em.getTransaction().commit();
    // Revision 2
    em.getTransaction().begin();
    mulId1 = new MulId(1, 2);
    em.persist(new MulIdTestEntity(mulId1.getId1(), mulId1.getId2(), "data"));
    embId1 = new EmbId(3, 4);
    em.persist(new EmbIdTestEntity(embId1, "something"));
    site1 = em.find(StrIntTestEntity.class, id1);
    site2 = em.find(StrIntTestEntity.class, id2);
    site1.setStr1("aBc");
    site2.setNumber(20);
    em.getTransaction().commit();
    // Revision 3
    em.getTransaction().begin();
    site3 = em.find(StrIntTestEntity.class, id3);
    site3.setStr1("a");
    em.getTransaction().commit();
    // Revision 4
    em.getTransaction().begin();
    site1 = em.find(StrIntTestEntity.class, id1);
    em.remove(site1);
    em.getTransaction().commit();
}
Also used : StrIntTestEntity(org.hibernate.envers.test.entities.StrIntTestEntity) EntityManager(javax.persistence.EntityManager) MulIdTestEntity(org.hibernate.envers.test.entities.ids.MulIdTestEntity) EmbIdTestEntity(org.hibernate.envers.test.entities.ids.EmbIdTestEntity) EmbId(org.hibernate.envers.test.entities.ids.EmbId) MulId(org.hibernate.envers.test.entities.ids.MulId) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 10 with StrIntTestEntity

use of org.hibernate.envers.test.entities.StrIntTestEntity in project hibernate-orm by hibernate.

the class StoreDeletedData method initData.

@Test
@Priority(10)
public void initData() {
    EntityManager em = getEntityManager();
    // Revision 1
    em.getTransaction().begin();
    StrIntTestEntity site1 = new StrIntTestEntity("a", 10);
    em.persist(site1);
    id1 = site1.getId();
    em.getTransaction().commit();
    // Revision 2
    em.getTransaction().begin();
    em.remove(site1);
    em.getTransaction().commit();
    // Revision 3
    em.getTransaction().begin();
    StrIntTestEntity site2 = new StrIntTestEntity("b", 20);
    em.persist(site2);
    id2 = site2.getId();
    StrIntTestEntity site3 = new StrIntTestEntity("c", 30);
    em.persist(site3);
    id3 = site3.getId();
    em.getTransaction().commit();
    // Revision 4
    em.getTransaction().begin();
    em.remove(site2);
    em.remove(site3);
    em.getTransaction().commit();
    em.close();
}
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