Search in sources :

Example 1 with ListOwningEntity

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

the class RemovedObjectQueryTest method testManyToManyCollectionSemantics.

// Many to many tests.
@Test
public void testManyToManyCollectionSemantics() {
    final ListOwnedEntity edVer1 = new ListOwnedEntity(1, "data_ed_1");
    final ListOwningEntity ingVer1 = new ListOwningEntity(2, "data_ing_1");
    final ListOwningEntity ingVer2 = new ListOwningEntity(2, "modified data_ing_1");
    ListOwnedEntity entity = getAuditReader().find(ListOwnedEntity.class, 1, 21);
    Assert.assertEquals(edVer1, entity);
    Assert.assertTrue(TestTools.checkCollection(entity.getReferencing(), ingVer1));
    entity = getAuditReader().find(ListOwnedEntity.class, 1, 22);
    Assert.assertTrue(TestTools.checkCollection(entity.getReferencing(), ingVer2));
    List queryResult = getAuditReader().createQuery().forRevisionsOfEntity(ListOwnedEntity.class, false, true).add(AuditEntity.id().eq(1)).add(AuditEntity.revisionType().eq(RevisionType.DEL)).getResultList();
    Object[] objArray = (Object[]) queryResult.get(0);
    Assert.assertEquals(23, getRevisionNumber(objArray[1]));
    entity = (ListOwnedEntity) objArray[0];
    Assert.assertEquals("data_ed_1", entity.getData());
    Assert.assertTrue(TestTools.checkCollection(entity.getReferencing(), ingVer2));
}
Also used : ListOwnedEntity(org.hibernate.envers.test.entities.manytomany.ListOwnedEntity) ListOwningEntity(org.hibernate.envers.test.entities.manytomany.ListOwningEntity) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 2 with ListOwningEntity

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

the class BasicList method initData.

@Test
@Priority(10)
public void initData() {
    EntityManager em = getEntityManager();
    ListOwnedEntity ed1 = new ListOwnedEntity(1, "data_ed_1");
    ListOwnedEntity ed2 = new ListOwnedEntity(2, "data_ed_2");
    ListOwningEntity ing1 = new ListOwningEntity(3, "data_ing_1");
    ListOwningEntity ing2 = new ListOwningEntity(4, "data_ing_2");
    // Revision 1
    em.getTransaction().begin();
    em.persist(ed1);
    em.persist(ed2);
    em.persist(ing1);
    em.persist(ing2);
    em.getTransaction().commit();
    // Revision 2
    em.getTransaction().begin();
    ing1 = em.find(ListOwningEntity.class, ing1.getId());
    ing2 = em.find(ListOwningEntity.class, ing2.getId());
    ed1 = em.find(ListOwnedEntity.class, ed1.getId());
    ed2 = em.find(ListOwnedEntity.class, ed2.getId());
    ing1.setReferences(new ArrayList<ListOwnedEntity>());
    ing1.getReferences().add(ed1);
    ing2.setReferences(new ArrayList<ListOwnedEntity>());
    ing2.getReferences().add(ed1);
    ing2.getReferences().add(ed2);
    em.getTransaction().commit();
    // Revision 3
    em.getTransaction().begin();
    ing1 = em.find(ListOwningEntity.class, ing1.getId());
    ed2 = em.find(ListOwnedEntity.class, ed2.getId());
    ed1 = em.find(ListOwnedEntity.class, ed1.getId());
    ing1.getReferences().add(ed2);
    em.getTransaction().commit();
    // Revision 4
    em.getTransaction().begin();
    ing1 = em.find(ListOwningEntity.class, ing1.getId());
    ed2 = em.find(ListOwnedEntity.class, ed2.getId());
    ed1 = em.find(ListOwnedEntity.class, ed1.getId());
    ing1.getReferences().remove(ed1);
    em.getTransaction().commit();
    // Revision 5
    em.getTransaction().begin();
    ing1 = em.find(ListOwningEntity.class, ing1.getId());
    ing1.setReferences(null);
    em.getTransaction().commit();
    // 
    ed1_id = ed1.getId();
    ed2_id = ed2.getId();
    ing1_id = ing1.getId();
    ing2_id = ing2.getId();
}
Also used : EntityManager(javax.persistence.EntityManager) ListOwnedEntity(org.hibernate.envers.test.entities.manytomany.ListOwnedEntity) ListOwningEntity(org.hibernate.envers.test.entities.manytomany.ListOwningEntity) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 3 with ListOwningEntity

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

the class BasicList method testHistoryOfEdId1.

@Test
public void testHistoryOfEdId1() {
    ListOwningEntity ing1 = getEntityManager().find(ListOwningEntity.class, ing1_id);
    ListOwningEntity ing2 = getEntityManager().find(ListOwningEntity.class, ing2_id);
    ListOwnedEntity rev1 = getAuditReader().find(ListOwnedEntity.class, ed1_id, 1);
    ListOwnedEntity rev2 = getAuditReader().find(ListOwnedEntity.class, ed1_id, 2);
    ListOwnedEntity rev3 = getAuditReader().find(ListOwnedEntity.class, ed1_id, 3);
    ListOwnedEntity rev4 = getAuditReader().find(ListOwnedEntity.class, ed1_id, 4);
    ListOwnedEntity rev5 = getAuditReader().find(ListOwnedEntity.class, ed1_id, 5);
    assert rev1.getReferencing().equals(Collections.EMPTY_LIST);
    assert TestTools.checkCollection(rev2.getReferencing(), ing1, ing2);
    assert TestTools.checkCollection(rev3.getReferencing(), ing1, ing2);
    assert TestTools.checkCollection(rev4.getReferencing(), ing2);
    assert TestTools.checkCollection(rev5.getReferencing(), ing2);
}
Also used : ListOwnedEntity(org.hibernate.envers.test.entities.manytomany.ListOwnedEntity) ListOwningEntity(org.hibernate.envers.test.entities.manytomany.ListOwningEntity) Test(org.junit.Test)

Example 4 with ListOwningEntity

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

the class BasicList method testHistoryOfEdId2.

@Test
public void testHistoryOfEdId2() {
    ListOwningEntity ing1 = getEntityManager().find(ListOwningEntity.class, ing1_id);
    ListOwningEntity ing2 = getEntityManager().find(ListOwningEntity.class, ing2_id);
    ListOwnedEntity rev1 = getAuditReader().find(ListOwnedEntity.class, ed2_id, 1);
    ListOwnedEntity rev2 = getAuditReader().find(ListOwnedEntity.class, ed2_id, 2);
    ListOwnedEntity rev3 = getAuditReader().find(ListOwnedEntity.class, ed2_id, 3);
    ListOwnedEntity rev4 = getAuditReader().find(ListOwnedEntity.class, ed2_id, 4);
    ListOwnedEntity rev5 = getAuditReader().find(ListOwnedEntity.class, ed2_id, 5);
    assert rev1.getReferencing().equals(Collections.EMPTY_LIST);
    assert TestTools.checkCollection(rev2.getReferencing(), ing2);
    assert TestTools.checkCollection(rev3.getReferencing(), ing1, ing2);
    assert TestTools.checkCollection(rev4.getReferencing(), ing1, ing2);
    assert TestTools.checkCollection(rev5.getReferencing(), ing2);
}
Also used : ListOwnedEntity(org.hibernate.envers.test.entities.manytomany.ListOwnedEntity) ListOwningEntity(org.hibernate.envers.test.entities.manytomany.ListOwningEntity) Test(org.junit.Test)

Example 5 with ListOwningEntity

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

the class BasicList method testHistoryOfEdIng1.

@Test
public void testHistoryOfEdIng1() {
    ListOwnedEntity ed1 = getEntityManager().find(ListOwnedEntity.class, ed1_id);
    ListOwnedEntity ed2 = getEntityManager().find(ListOwnedEntity.class, ed2_id);
    ListOwningEntity rev1 = getAuditReader().find(ListOwningEntity.class, ing1_id, 1);
    ListOwningEntity rev2 = getAuditReader().find(ListOwningEntity.class, ing1_id, 2);
    ListOwningEntity rev3 = getAuditReader().find(ListOwningEntity.class, ing1_id, 3);
    ListOwningEntity rev4 = getAuditReader().find(ListOwningEntity.class, ing1_id, 4);
    ListOwningEntity rev5 = getAuditReader().find(ListOwningEntity.class, ing1_id, 5);
    assert rev1.getReferences().equals(Collections.EMPTY_LIST);
    assert TestTools.checkCollection(rev2.getReferences(), ed1);
    assert TestTools.checkCollection(rev3.getReferences(), ed1, ed2);
    assert TestTools.checkCollection(rev4.getReferences(), ed2);
    assert rev5.getReferences().equals(Collections.EMPTY_LIST);
}
Also used : ListOwnedEntity(org.hibernate.envers.test.entities.manytomany.ListOwnedEntity) ListOwningEntity(org.hibernate.envers.test.entities.manytomany.ListOwningEntity) Test(org.junit.Test)

Aggregations

ListOwnedEntity (org.hibernate.envers.test.entities.manytomany.ListOwnedEntity)8 ListOwningEntity (org.hibernate.envers.test.entities.manytomany.ListOwningEntity)8 Test (org.junit.Test)8 EntityManager (javax.persistence.EntityManager)3 Priority (org.hibernate.envers.test.Priority)3 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 IntTestPrivSeqEntity (org.hibernate.envers.test.entities.IntTestPrivSeqEntity)1 StrTestEntity (org.hibernate.envers.test.entities.StrTestEntity)1 StrTestPrivSeqEntity (org.hibernate.envers.test.entities.StrTestPrivSeqEntity)1 UnversionedStrTestEntity (org.hibernate.envers.test.entities.UnversionedStrTestEntity)1 StringSetEntity (org.hibernate.envers.test.entities.collection.StringSetEntity)1 SetOwnedEntity (org.hibernate.envers.test.entities.manytomany.SetOwnedEntity)1 SetOwningEntity (org.hibernate.envers.test.entities.manytomany.SetOwningEntity)1 M2MIndexedListTargetNotAuditedEntity (org.hibernate.envers.test.entities.manytomany.unidirectional.M2MIndexedListTargetNotAuditedEntity)1 CollectionRefEdEntity (org.hibernate.envers.test.entities.onetomany.CollectionRefEdEntity)1 CollectionRefIngEntity (org.hibernate.envers.test.entities.onetomany.CollectionRefIngEntity)1 SetRefEdEntity (org.hibernate.envers.test.entities.onetomany.SetRefEdEntity)1 SetRefIngEntity (org.hibernate.envers.test.entities.onetomany.SetRefIngEntity)1