Package org.hibernate.envers.test.entities

Examples of org.hibernate.envers.test.entities.StrTestEntity


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

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

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


        Thread.sleep(100);

        // Revision 1
        EntityManager em = getEntityManager();
        em.getTransaction().begin();
        StrTestEntity rfd = new StrTestEntity("x");
        em.persist(rfd);
        Integer id = rfd.getId();
        em.getTransaction().commit();

        timestamp2 = System.currentTimeMillis();

        Thread.sleep(100);

        // Revision 2
        em.getTransaction().begin();
        rfd = em.find(StrTestEntity.class, id);
        rfd.setStr("y");
        em.getTransaction().commit();

        timestamp3 = System.currentTimeMillis();

        Thread.sleep(100);

        // Revision 3
        em.getTransaction().begin();
        rfd = em.find(StrTestEntity.class, id);
        rfd.setStr("z");
        em.getTransaction().commit();

        timestamp4 = System.currentTimeMillis();
    }
View Full Code Here

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

        StrTestEntity fe = new StrTestEntity("x");
        em.persist(fe);

        em.flush();

        fe.setStr("y");

        em.flush();

        em.getTransaction().commit();

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

        fe = em.find(StrTestEntity.class, fe.getId());

        fe.setStr("z");
        em.flush();

        em.getTransaction().commit();

        //

        id = fe.getId();
    }
View Full Code Here

        assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(StrTestEntity.class, id));
    }

    @Test
    public void testHistoryOfId() {
        StrTestEntity ver1 = new StrTestEntity("y", id);
        StrTestEntity ver2 = new StrTestEntity("z", id);

        assert getAuditReader().find(StrTestEntity.class, id, 1).equals(ver1);
        assert getAuditReader().find(StrTestEntity.class, id, 2).equals(ver2);
    }
View Full Code Here

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

        StrTestEntity ed1 = new StrTestEntity("data_ed_1");
        StrTestEntity ed2 = new StrTestEntity("data_ed_2");

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

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

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

        em.getTransaction().commit();

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

        ing1 = em.find(SetUniEntity.class, ing1.getId());
        ed2 = em.find(StrTestEntity.class, ed2.getId());
        ed1 = em.find(StrTestEntity.class, ed1.getId());

        ing1.getReferences().add(ed2);

        em.getTransaction().commit();

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

        ing1 = em.find(SetUniEntity.class, ing1.getId());
        ed2 = em.find(StrTestEntity.class, ed2.getId());
        ed1 = em.find(StrTestEntity.class, ed1.getId());

        ing1.getReferences().remove(ed1);

        em.getTransaction().commit();

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

        ing1 = em.find(SetUniEntity.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

        assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(SetUniEntity.class, ing2_id));
    }

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

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

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

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

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

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

        StrTestEntity str1 = new StrTestEntity("a");
        StrTestEntity str2 = new StrTestEntity("b");

        IntTestEntity int1 = new IntTestEntity(1);
        IntTestEntity int2 = new IntTestEntity(2);

        TernaryMapEntity map1 = new TernaryMapEntity();
        TernaryMapEntity map2 = new TernaryMapEntity();

        // Revision 1 (map1: initialy one mapping int1 -> str1, map2: empty)
        em.getTransaction().begin();

        em.persist(str1);
        em.persist(str2);
        em.persist(int1);
        em.persist(int2);

        map1.getMap().put(int1, str1);

        em.persist(map1);
        em.persist(map2);

        em.getTransaction().commit();

        // Revision 2 (map1: replacing the mapping, map2: adding two mappings)

        em.getTransaction().begin();

        map1 = em.find(TernaryMapEntity.class, map1.getId());
        map2 = em.find(TernaryMapEntity.class, map2.getId());

        str1 = em.find(StrTestEntity.class, str1.getId());
        str2 = em.find(StrTestEntity.class, str2.getId());

        int1 = em.find(IntTestEntity.class, int1.getId());
        int2 = em.find(IntTestEntity.class, int2.getId());

        map1.getMap().put(int1, str2);

        map2.getMap().put(int1, str1);
        map2.getMap().put(int2, str1);

        em.getTransaction().commit();

        // Revision 3 (map1: removing a non-existing mapping, adding an existing mapping - no changes, map2: removing a mapping)
        em.getTransaction().begin();

        map1 = em.find(TernaryMapEntity.class, map1.getId());
        map2 = em.find(TernaryMapEntity.class, map2.getId());

        str2 = em.find(StrTestEntity.class, str2.getId());

        int1 = em.find(IntTestEntity.class, int1.getId());
        int2 = em.find(IntTestEntity.class, int2.getId());

        map1.getMap().remove(int2);
        map1.getMap().put(int1, str2);

        map2.getMap().remove(int1);

        em.getTransaction().commit();

        // Revision 4 (map1: adding a mapping, map2: adding a mapping)
        em.getTransaction().begin();

        map1 = em.find(TernaryMapEntity.class, map1.getId());
        map2 = em.find(TernaryMapEntity.class, map2.getId());

        str2 = em.find(StrTestEntity.class, str2.getId());

        int1 = em.find(IntTestEntity.class, int1.getId());
        int2 = em.find(IntTestEntity.class, int2.getId());

        map1.getMap().put(int2, str2);

        map2.getMap().put(int1, str2);

        em.getTransaction().commit();
        //

        map1_id = map1.getId();
        map2_id = map2.getId();

        str1_id = str1.getId();
        str2_id = str2.getId();

        int1_id = int1.getId();
        int2_id = int2.getId();
    }
View Full Code Here

        assert Arrays.asList(1).equals(getAuditReader().getRevisions(IntTestEntity.class, int2_id));
    }

    @Test
    public void testHistoryOfMap1() {
        StrTestEntity str1 = getEntityManager().find(StrTestEntity.class, str1_id);
        StrTestEntity str2 = getEntityManager().find(StrTestEntity.class, str2_id);

        IntTestEntity int1 = getEntityManager().find(IntTestEntity.class, int1_id);
        IntTestEntity int2 = getEntityManager().find(IntTestEntity.class, int2_id);

        TernaryMapEntity rev1 = getAuditReader().find(TernaryMapEntity.class, map1_id, 1);
View Full Code Here

        assert rev4.getMap().equals(TestTools.makeMap(int1, str2, int2, str2));
    }

    @Test
    public void testHistoryOfMap2() {
        StrTestEntity str1 = getEntityManager().find(StrTestEntity.class, str1_id);
        StrTestEntity str2 = getEntityManager().find(StrTestEntity.class, str2_id);

        IntTestEntity int1 = getEntityManager().find(IntTestEntity.class, int1_id);
        IntTestEntity int2 = getEntityManager().find(IntTestEntity.class, int2_id);

        TernaryMapEntity rev1 = getAuditReader().find(TernaryMapEntity.class, map2_id, 1);
View Full Code Here

TOP

Related Classes of org.hibernate.envers.test.entities.StrTestEntity

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.