Search in sources :

Example 26 with StrIntTestEntity

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

the class SimpleQuery method testEntitiesPropertyLeQuery.

@Test
public void testEntitiesPropertyLeQuery() {
    List ver1 = getAuditReader().createQuery().forEntitiesAtRevision(StrIntTestEntity.class, 1).add(AuditEntity.property("number").le(10)).getResultList();
    List ver2 = getAuditReader().createQuery().forEntitiesAtRevision(StrIntTestEntity.class, 2).add(AuditEntity.property("number").le(10)).getResultList();
    List ver3 = getAuditReader().createQuery().forEntitiesAtRevision(StrIntTestEntity.class, 3).add(AuditEntity.property("number").le(10)).getResultList();
    assert new HashSet(ver1).equals(TestTools.makeSet(new StrIntTestEntity("a", 10, id1), new StrIntTestEntity("a", 10, id2), new StrIntTestEntity("b", 5, id3)));
    assert new HashSet(ver2).equals(TestTools.makeSet(new StrIntTestEntity("aBc", 10, id1), new StrIntTestEntity("b", 5, id3)));
    assert new HashSet(ver3).equals(TestTools.makeSet(new StrIntTestEntity("aBc", 10, id1), 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 27 with StrIntTestEntity

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

the class StoreDeletedData method testRevisionsPropertyEqQuery.

@Test
public void testRevisionsPropertyEqQuery() {
    List revs_id1 = getAuditReader().createQuery().forRevisionsOfEntity(StrIntTestEntity.class, false, true).add(AuditEntity.id().eq(id1)).getResultList();
    Assert.assertEquals(2, revs_id1.size());
    Assert.assertEquals(new StrIntTestEntity("a", 10, id1), ((Object[]) revs_id1.get(0))[0]);
    Assert.assertEquals(new StrIntTestEntity("a", 10, id1), ((Object[]) revs_id1.get(1))[0]);
}
Also used : StrIntTestEntity(org.hibernate.envers.test.entities.StrIntTestEntity) List(java.util.List) Test(org.junit.Test)

Example 28 with StrIntTestEntity

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

the class CustomTrackingEntitiesTest method initData.

@Test
@Priority(10)
public void initData() {
    EntityManager em = getEntityManager();
    // Revision 1 - Adding two entities
    em.getTransaction().begin();
    StrTestEntity ste = new StrTestEntity("x");
    StrIntTestEntity site = new StrIntTestEntity("y", 1);
    em.persist(ste);
    em.persist(site);
    steId = ste.getId();
    siteId = site.getId();
    em.getTransaction().commit();
    // Revision 2 - Modifying one entity
    em.getTransaction().begin();
    site = em.find(StrIntTestEntity.class, siteId);
    site.setNumber(2);
    em.getTransaction().commit();
    // Revision 3 - Deleting both entities
    em.getTransaction().begin();
    ste = em.find(StrTestEntity.class, steId);
    site = em.find(StrIntTestEntity.class, siteId);
    em.remove(ste);
    em.remove(site);
    em.getTransaction().commit();
}
Also used : StrIntTestEntity(org.hibernate.envers.test.entities.StrIntTestEntity) StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) EntityManager(javax.persistence.EntityManager) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 29 with StrIntTestEntity

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

the class DefaultTrackingEntitiesTest method testFindChangedEntitiesByRevisionTypeDEL.

@Test
public void testFindChangedEntitiesByRevisionTypeDEL() {
    StrTestEntity ste = new StrTestEntity(null, steId);
    StrIntTestEntity site = new StrIntTestEntity(null, null, siteId);
    assert TestTools.checkCollection(getCrossTypeRevisionChangesReader().findEntities(3, RevisionType.DEL), ste, site);
}
Also used : StrIntTestEntity(org.hibernate.envers.test.entities.StrIntTestEntity) StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) Test(org.junit.Test)

Example 30 with StrIntTestEntity

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

the class DefaultTrackingEntitiesTest method initData.

@Test
@Priority(10)
public void initData() {
    EntityManager em = getEntityManager();
    // Revision 1 - Adding two entities
    em.getTransaction().begin();
    StrTestEntity ste = new StrTestEntity("x");
    StrIntTestEntity site = new StrIntTestEntity("y", 1);
    em.persist(ste);
    em.persist(site);
    steId = ste.getId();
    siteId = site.getId();
    em.getTransaction().commit();
    // Revision 2 - Modifying one entity
    em.getTransaction().begin();
    site = em.find(StrIntTestEntity.class, siteId);
    site.setNumber(2);
    em.getTransaction().commit();
    // Revision 3 - Deleting both entities
    em.getTransaction().begin();
    ste = em.find(StrTestEntity.class, steId);
    site = em.find(StrIntTestEntity.class, siteId);
    em.remove(ste);
    em.remove(site);
    em.getTransaction().commit();
}
Also used : StrIntTestEntity(org.hibernate.envers.test.entities.StrIntTestEntity) StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) 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