Package org.hibernate.envers.test.entities.manytomany

Examples of org.hibernate.envers.test.entities.manytomany.SetOwnedEntity


    @BeforeClass(enabled = true, dependsOnMethods = "init")
    public void initData() {
        final EntityManager em = getEntityManager();

        final SetOwningEntity setOwningEntity = new SetOwningEntity(1, "parent");
        final SetOwnedEntity setOwnedEntity = new SetOwnedEntity(2, "child");

        // Revision 1: Initial persist
        em.getTransaction().begin();

        em.persist(setOwningEntity);
        em.persist(setOwnedEntity);

        em.getTransaction().commit();
        em.clear();

        ing_id = setOwningEntity.getId();
        ed_id = setOwnedEntity.getId();
    }
View Full Code Here


        // Revision 2: add child for first time
        em.getTransaction().begin();

        SetOwningEntity owningEntity = getEntityManager().find(SetOwningEntity.class, ing_id);
        SetOwnedEntity ownedEntity = getEntityManager().find(SetOwnedEntity.class, ed_id);

        owningEntity.setReferences(new HashSet<SetOwnedEntity>());
        owningEntity.getReferences().add(ownedEntity);

        em.getTransaction().commit();
View Full Code Here

  }

  @Test(enabled = true, dependsOnMethods = "testMultipleAddAndRemove")
  public void testHistoryOfIng1() {
    SetOwningEntity ver_empty = createOwningEntity();
    SetOwningEntity ver_child = createOwningEntity(new SetOwnedEntity(ed_id, "child"));

        assertEquals(getAuditReader().find(SetOwningEntity.class, ing_id, 1), ver_empty);
        assertEquals(getAuditReader().find(SetOwningEntity.class, ing_id, 2), ver_child);
        assertEquals(getAuditReader().find(SetOwningEntity.class, ing_id, 3), ver_empty);
        assertEquals(getAuditReader().find(SetOwningEntity.class, ing_id, 4), ver_child);
View Full Code Here

        assertEquals(getAuditReader().find(SetOwningEntity.class, ing_id, 5), ver_empty);
  }

    @Test(enabled = true, dependsOnMethods = "testMultipleAddAndRemove")
  public void testHistoryOfEd1() {
    SetOwnedEntity ver_empty = createOwnedEntity();
    SetOwnedEntity ver_child = createOwnedEntity(new SetOwningEntity(ing_id, "parent"));

        assertEquals(getAuditReader().find(SetOwnedEntity.class, ed_id, 1), ver_empty);
        assertEquals(getAuditReader().find(SetOwnedEntity.class, ed_id, 2), ver_child);
        assertEquals(getAuditReader().find(SetOwnedEntity.class, ed_id, 3), ver_empty);
        assertEquals(getAuditReader().find(SetOwnedEntity.class, ed_id, 4), ver_child);
View Full Code Here

        return result;
    }

    private SetOwnedEntity createOwnedEntity(SetOwningEntity... owning) {
        SetOwnedEntity result = new SetOwnedEntity(ed_id, "child");
        result.setReferencing(new HashSet<SetOwningEntity>());
        for (SetOwningEntity setOwningEntity : owning) {
            result.getReferencing().add(setOwningEntity);
        }

        return result;
    }
View Full Code Here

    @BeforeClass(dependsOnMethods = "init")
    public void initData() {
        EntityManager em = getEntityManager();

        SetOwnedEntity ed1 = new SetOwnedEntity(1, "data_ed_1");
        SetOwnedEntity ed2 = new SetOwnedEntity(2, "data_ed_2");

        SetOwningEntity ing1 = new SetOwningEntity(3, "data_ing_1");
        SetOwningEntity ing2 = new SetOwningEntity(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(SetOwningEntity.class, ing1.getId());
        ing2 = em.find(SetOwningEntity.class, ing2.getId());
        ed1 = em.find(SetOwnedEntity.class, ed1.getId());
        ed2 = em.find(SetOwnedEntity.class, ed2.getId());

        ing1.setReferences(new HashSet<SetOwnedEntity>());
        ing1.getReferences().add(ed1);

        ing2.setReferences(new HashSet<SetOwnedEntity>());
        ing2.getReferences().add(ed1);
        ing2.getReferences().add(ed2);

        em.getTransaction().commit();

        // Revision 3
        em.getTransaction().begin();

        ing1 = em.find(SetOwningEntity.class, ing1.getId());
        ed2 = em.find(SetOwnedEntity.class, ed2.getId());
        ed1 = em.find(SetOwnedEntity.class, ed1.getId());

        ing1.getReferences().add(ed2);

        em.getTransaction().commit();

        // Revision 4
        em.getTransaction().begin();

        ing1 = em.find(SetOwningEntity.class, ing1.getId());
        ed2 = em.find(SetOwnedEntity.class, ed2.getId());
        ed1 = em.find(SetOwnedEntity.class, ed1.getId());

        ing1.getReferences().remove(ed1);

        em.getTransaction().commit();

        // Revision 5
        em.getTransaction().begin();

        ing1 = em.find(SetOwningEntity.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();
    }
View Full Code Here

    @Test
    public void testHistoryOfEdId1() {
        SetOwningEntity ing1 = getEntityManager().find(SetOwningEntity.class, ing1_id);
        SetOwningEntity ing2 = getEntityManager().find(SetOwningEntity.class, ing2_id);

        SetOwnedEntity rev1 = getAuditReader().find(SetOwnedEntity.class, ed1_id, 1);
        SetOwnedEntity rev2 = getAuditReader().find(SetOwnedEntity.class, ed1_id, 2);
        SetOwnedEntity rev3 = getAuditReader().find(SetOwnedEntity.class, ed1_id, 3);
        SetOwnedEntity rev4 = getAuditReader().find(SetOwnedEntity.class, ed1_id, 4);
        SetOwnedEntity rev5 = getAuditReader().find(SetOwnedEntity.class, ed1_id, 5);

        assert rev1.getReferencing().equals(Collections.EMPTY_SET);
        assert rev2.getReferencing().equals(TestTools.makeSet(ing1, ing2));
        assert rev3.getReferencing().equals(TestTools.makeSet(ing1, ing2));
        assert rev4.getReferencing().equals(TestTools.makeSet(ing2));
        assert rev5.getReferencing().equals(TestTools.makeSet(ing2));
    }
View Full Code Here

    @Test
    public void testHistoryOfEdId2() {
        SetOwningEntity ing1 = getEntityManager().find(SetOwningEntity.class, ing1_id);
        SetOwningEntity ing2 = getEntityManager().find(SetOwningEntity.class, ing2_id);

        SetOwnedEntity rev1 = getAuditReader().find(SetOwnedEntity.class, ed2_id, 1);
        SetOwnedEntity rev2 = getAuditReader().find(SetOwnedEntity.class, ed2_id, 2);
        SetOwnedEntity rev3 = getAuditReader().find(SetOwnedEntity.class, ed2_id, 3);
        SetOwnedEntity rev4 = getAuditReader().find(SetOwnedEntity.class, ed2_id, 4);
        SetOwnedEntity rev5 = getAuditReader().find(SetOwnedEntity.class, ed2_id, 5);

        assert rev1.getReferencing().equals(Collections.EMPTY_SET);
        assert rev2.getReferencing().equals(TestTools.makeSet(ing2));
        assert rev3.getReferencing().equals(TestTools.makeSet(ing1, ing2));
        assert rev4.getReferencing().equals(TestTools.makeSet(ing1, ing2));
        assert rev5.getReferencing().equals(TestTools.makeSet(ing2));
    }
View Full Code Here

        assert rev5.getReferencing().equals(TestTools.makeSet(ing2));
    }

    @Test
    public void testHistoryOfEdIng1() {
        SetOwnedEntity ed1 = getEntityManager().find(SetOwnedEntity.class, ed1_id);
        SetOwnedEntity ed2 = getEntityManager().find(SetOwnedEntity.class, ed2_id);

        SetOwningEntity rev1 = getAuditReader().find(SetOwningEntity.class, ing1_id, 1);
        SetOwningEntity rev2 = getAuditReader().find(SetOwningEntity.class, ing1_id, 2);
        SetOwningEntity rev3 = getAuditReader().find(SetOwningEntity.class, ing1_id, 3);
        SetOwningEntity rev4 = getAuditReader().find(SetOwningEntity.class, ing1_id, 4);
View Full Code Here

        assert rev5.getReferences().equals(Collections.EMPTY_SET);
    }

    @Test
    public void testHistoryOfEdIng2() {
        SetOwnedEntity ed1 = getEntityManager().find(SetOwnedEntity.class, ed1_id);
        SetOwnedEntity ed2 = getEntityManager().find(SetOwnedEntity.class, ed2_id);

        SetOwningEntity rev1 = getAuditReader().find(SetOwningEntity.class, ing2_id, 1);
        SetOwningEntity rev2 = getAuditReader().find(SetOwningEntity.class, ing2_id, 2);
        SetOwningEntity rev3 = getAuditReader().find(SetOwningEntity.class, ing2_id, 3);
        SetOwningEntity rev4 = getAuditReader().find(SetOwningEntity.class, ing2_id, 4);
View Full Code Here

TOP

Related Classes of org.hibernate.envers.test.entities.manytomany.SetOwnedEntity

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.