Package org.hibernate.envers.test.entities.components

Examples of org.hibernate.envers.test.entities.components.ComponentTestEntity


    public void initData() {
        // Revision 1
        EntityManager em = getEntityManager();
        em.getTransaction().begin();

        ComponentTestEntity cte1 = new ComponentTestEntity(new Component1("a", "b"), new Component2("x", "y"));
        ComponentTestEntity cte2 = new ComponentTestEntity(new Component1("a2", "b2"), new Component2("x2", "y2"));
        ComponentTestEntity cte3 = new ComponentTestEntity(new Component1("a3", "b3"), new Component2("x3", "y3"));
        ComponentTestEntity cte4 = new ComponentTestEntity(null, null);

        em.persist(cte1);
        em.persist(cte2);
        em.persist(cte3);
        em.persist(cte4);

        em.getTransaction().commit();

        // Revision 2
        em = getEntityManager();
        em.getTransaction().begin();

        cte1 = em.find(ComponentTestEntity.class, cte1.getId());
        cte2 = em.find(ComponentTestEntity.class, cte2.getId());
        cte3 = em.find(ComponentTestEntity.class, cte3.getId());
    cte4 = em.find(ComponentTestEntity.class, cte4.getId());

        cte1.setComp1(new Component1("a'", "b'"));
        cte2.getComp1().setStr1("a2'");
        cte3.getComp2().setStr6("y3'");
    cte4.setComp1(new Component1());
    cte4.getComp1().setStr1("n");
    cte4.setComp2(new Component2());
    cte4.getComp2().setStr5("m");

        em.getTransaction().commit();

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

        cte1 = em.find(ComponentTestEntity.class, cte1.getId());
        cte2 = em.find(ComponentTestEntity.class, cte2.getId());
        cte3 = em.find(ComponentTestEntity.class, cte3.getId());
    cte4 = em.find(ComponentTestEntity.class, cte4.getId());

        cte1.setComp2(new Component2("x'", "y'"));
        cte3.getComp1().setStr2("b3'");
    cte4.setComp1(null);
    cte4.setComp2(null);

        em.getTransaction().commit();

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

        cte2 = em.find(ComponentTestEntity.class, cte2.getId());

        em.remove(cte2);

        em.getTransaction().commit();

        id1 = cte1.getId();
        id2 = cte2.getId();
        id3 = cte3.getId();
        id4 = cte4.getId();
    }
View Full Code Here


    assert Arrays.asList(1, 2, 3).equals(getAuditReader().getRevisions(ComponentTestEntity.class, id4));
    }

    @Test
    public void testHistoryOfId1() {
        ComponentTestEntity ver1 = new ComponentTestEntity(id1, new Component1("a", "b"), null);
        ComponentTestEntity ver2 = new ComponentTestEntity(id1, new Component1("a'", "b'"), null);

        assert getAuditReader().find(ComponentTestEntity.class, id1, 1).equals(ver1);
        assert getAuditReader().find(ComponentTestEntity.class, id1, 2).equals(ver2);
        assert getAuditReader().find(ComponentTestEntity.class, id1, 3).equals(ver2);
        assert getAuditReader().find(ComponentTestEntity.class, id1, 4).equals(ver2);
View Full Code Here

        assert getAuditReader().find(ComponentTestEntity.class, id1, 4).equals(ver2);
    }

    @Test
    public void testHistoryOfId2() {
        ComponentTestEntity ver1 = new ComponentTestEntity(id2, new Component1("a2", "b2"), null);
        ComponentTestEntity ver2 = new ComponentTestEntity(id2, new Component1("a2'", "b2"), null);

        assert getAuditReader().find(ComponentTestEntity.class, id2, 1).equals(ver1);
        assert getAuditReader().find(ComponentTestEntity.class, id2, 2).equals(ver2);
        assert getAuditReader().find(ComponentTestEntity.class, id2, 3).equals(ver2);
        assert getAuditReader().find(ComponentTestEntity.class, id2, 4) == null;
View Full Code Here

        assert getAuditReader().find(ComponentTestEntity.class, id2, 4) == null;
    }

    @Test
    public void testHistoryOfId3() {
        ComponentTestEntity ver1 = new ComponentTestEntity(id3, new Component1("a3", "b3"), null);
        ComponentTestEntity ver2 = new ComponentTestEntity(id3, new Component1("a3", "b3'"), null);

        assert getAuditReader().find(ComponentTestEntity.class, id3, 1).equals(ver1);
        assert getAuditReader().find(ComponentTestEntity.class, id3, 2).equals(ver1);
        assert getAuditReader().find(ComponentTestEntity.class, id3, 3).equals(ver2);
        assert getAuditReader().find(ComponentTestEntity.class, id3, 4).equals(ver2);
View Full Code Here

        assert getAuditReader().find(ComponentTestEntity.class, id3, 4).equals(ver2);
    }

    @Test
    public void testHistoryOfId4() {
        ComponentTestEntity ver1 = new ComponentTestEntity(id4, null, null);
        ComponentTestEntity ver2 = new ComponentTestEntity(id4, new Component1("n", null), null);
        ComponentTestEntity ver3 = new ComponentTestEntity(id4, null, null);

        assert getAuditReader().find(ComponentTestEntity.class, id4, 1).equals(ver1);
        assert getAuditReader().find(ComponentTestEntity.class, id4, 2).equals(ver2);
        assert getAuditReader().find(ComponentTestEntity.class, id4, 3).equals(ver3);
        assert getAuditReader().find(ComponentTestEntity.class, id4, 4).equals(ver3);
View Full Code Here

        ComponentMapKeyEntity imke = new ComponentMapKeyEntity();

        // Revision 1 (intialy 1 mapping)
        em.getTransaction().begin();

        ComponentTestEntity cte1 = new ComponentTestEntity(new Component1("x1", "y2"), new Component2("a1", "b2"));
        ComponentTestEntity cte2 = new ComponentTestEntity(new Component1("x1", "y2"), new Component2("a1", "b2"));

        em.persist(cte1);
        em.persist(cte2);

        imke.getIdmap().put(cte1.getComp1(), cte1);

        em.persist(imke);

        em.getTransaction().commit();

        // Revision 2 (sse1: adding 1 mapping)
        em.getTransaction().begin();

        cte2 = em.find(ComponentTestEntity.class, cte2.getId());
        imke = em.find(ComponentMapKeyEntity.class, imke.getId());

        imke.getIdmap().put(cte2.getComp1(), cte2);

        em.getTransaction().commit();

        //

        cmke_id = imke.getId();

        cte1_id = cte1.getId();
        cte2_id = cte2.getId();
    }
View Full Code Here

        assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(ComponentMapKeyEntity.class, cmke_id));
    }

    @Test
    public void testHistoryOfImke() {
        ComponentTestEntity cte1 = getEntityManager().find(ComponentTestEntity.class, cte1_id);
        ComponentTestEntity cte2 = getEntityManager().find(ComponentTestEntity.class, cte2_id);

        // These fields are unversioned.
        cte1.setComp2(null);
        cte2.setComp2(null);

        ComponentMapKeyEntity rev1 = getAuditReader().find(ComponentMapKeyEntity.class, cmke_id, 1);
        ComponentMapKeyEntity rev2 = getAuditReader().find(ComponentMapKeyEntity.class, cmke_id, 2);

        assert rev1.getIdmap().equals(TestTools.makeMap(cte1.getComp1(), cte1));
        assert rev2.getIdmap().equals(TestTools.makeMap(cte1.getComp1(), cte1, cte2.getComp1(), cte2));
    }
View Full Code Here

TOP

Related Classes of org.hibernate.envers.test.entities.components.ComponentTestEntity

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.