Package org.hibernate.envers.test.entities

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


    }

    @BeforeClass(dependsOnMethods = "init")
    public void initData() {
        DetachedNamingTestEntity uni1 = new DetachedNamingTestEntity(1, "data1");
        StrTestEntity str1 = new StrTestEntity("str1");

        // Revision 1
        EntityManager em = getEntityManager();
        em.getTransaction().begin();

        uni1.setCollection(new HashSet<StrTestEntity>());
        em.persist(uni1);
        em.persist(str1);

        em.getTransaction().commit();

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

        uni1 = em.find(DetachedNamingTestEntity.class, uni1.getId());
        str1 = em.find(StrTestEntity.class, str1.getId());
        uni1.getCollection().add(str1);

        em.getTransaction().commit();

        //

        uni1_id = uni1.getId();
        str1_id = str1.getId();
    }
View Full Code Here


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

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

        DetachedNamingTestEntity rev1 = getAuditReader().find(DetachedNamingTestEntity.class, uni1_id, 1);
        DetachedNamingTestEntity rev2 = getAuditReader().find(DetachedNamingTestEntity.class, uni1_id, 2);

        assert rev1.getCollection().equals(TestTools.makeSet());
View Full Code Here

        Thread.sleep(100);

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

        timestamp2 = System.currentTimeMillis();

        Thread.sleep(100);

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

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

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

    @Test
    public void testHistoryOfId1() {
        StrTestEntity ver1 = new StrTestEntity("x", id);
        StrTestEntity ver2 = new StrTestEntity("y", 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 str1 = new StrTestEntity("str1");
        StrTestEntity str2 = new StrTestEntity("str2");

        DoubleSetRefCollEntity coll1 = new DoubleSetRefCollEntity(3, "coll1");

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

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

        coll1.setCollection(new HashSet<StrTestEntity>());
        coll1.getCollection().add(str1);
        em.persist(coll1);

        coll1.setCollection2(new HashSet<StrTestEntity>());
        coll1.getCollection2().add(str2);
        em.persist(coll1);

        em.getTransaction().commit();

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

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

        coll1.getCollection().add(str2);

        em.getTransaction().commit();

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

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

        coll1.getCollection().remove(str1);
        coll1.getCollection2().add(str1);

        em.getTransaction().commit();

        //

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

        coll1_id = coll1.getId();
    }
View Full Code Here

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

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

        DoubleSetRefCollEntity rev1 = getAuditReader().find(DoubleSetRefCollEntity.class, coll1_id, 1);
        DoubleSetRefCollEntity rev2 = getAuditReader().find(DoubleSetRefCollEntity.class, coll1_id, 2);
        DoubleSetRefCollEntity rev3 = getAuditReader().find(DoubleSetRefCollEntity.class, coll1_id, 3);
View Full Code Here

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

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

        em.getTransaction().commit();

        // No revision - we change the data, but do not flush the session
        em.getTransaction().begin();

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

        em.getTransaction().commit();

        // Revision 2 - only the first change should be saved
        em.getTransaction().begin();

        fe = em.find(StrTestEntity.class, fe.getId());
        fe.setStr("z");
        em.flush();

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

        em.getTransaction().commit();

        //

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

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

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

        MapUniEntity coll1 = new MapUniEntity(3, "coll1");

        // Revision 1 (coll1: initialy one mapping)
        em.getTransaction().begin();

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

        coll1.setMap(new HashMap<String, StrTestEntity>());
        coll1.getMap().put("1", str1);
        em.persist(coll1);

        em.getTransaction().commit();

        // Revision 2 (coll1: adding one mapping)
        em.getTransaction().begin();

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

        coll1.getMap().put("2", str2);

        em.getTransaction().commit();

        // Revision 3 (coll1: replacing one mapping)
        em.getTransaction().begin();

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

        coll1.getMap().put("2", str1);

        em.getTransaction().commit();

        // Revision 4 (coll1: removing one mapping)
        em.getTransaction().begin();

        coll1 = em.find(MapUniEntity.class, coll1.getId());

        coll1.getMap().remove("1");

        em.getTransaction().commit();

        //

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

        coll1_id = coll1.getId();
    }
View Full Code Here

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

    @Test
    public void testHistoryOfId() {
        StrTestEntity ver1 = new StrTestEntity("x", 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

        assert getAuditReader().find(StrTestEntity.class, id, 2).equals(ver2);
    }

    @Test
    public void testCurrent() {
        assert getEntityManager().find(StrTestEntity.class, id).equals(new StrTestEntity("z", id));
    }
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.