Package org.hibernate.envers.test.entities

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


        EntityManager em = getEntityManager();
        em.getTransaction().begin();

        TestRevisionListener.data = "data1";

        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);

        TestRevisionListener.data = "data2";

        te.setStr("y");
        em.getTransaction().commit();

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


        // Trying to persist an entity - however the listener should throw an exception, so the entity
    // shouldn't be persisted
        newEntityManager();
        EntityManager em = getEntityManager();
        em.getTransaction().begin();
        StrTestEntity te = new StrTestEntity("x");
        em.persist(te);

        SimpleJtaTransactionManagerImpl.getInstance().commit();
    }
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");

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

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

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

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

        em.getTransaction().commit();

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

        str2 = em.find(StrTestEntity.class, str2.getId());
        coll1 = em.find(ListRefCollEntity.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(ListRefCollEntity.class, coll1.getId());

        coll1.getCollection().remove(str1);

        em.getTransaction().commit();

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

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

        coll1.getCollection().clear();

        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);

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

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

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

        SetRefCollEntity coll1 = new SetRefCollEntity(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);

        em.getTransaction().commit();

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

        str2 = em.find(StrTestEntity.class, str2.getId());
        coll1 = em.find(SetRefCollEntity.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(SetRefCollEntity.class, coll1.getId());

        coll1.getCollection().remove(str1);

        em.getTransaction().commit();

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

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

        coll1.getCollection().clear();

        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);

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

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

        StrTestEntity str1 = new StrTestEntity("str1");

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

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

        em.persist(str1);

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

        em.getTransaction().commit();

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

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

        coll1.getCollection().add(str1);
        coll1.setData("coll2");

        em.getTransaction().commit();

        //

        str1_id = str1.getId();

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

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

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

        SetRefCollEntity rev1 = getAuditReader().find(SetRefCollEntity.class, coll1_id, 1);
        SetRefCollEntity rev2 = getAuditReader().find(SetRefCollEntity.class, coll1_id, 2);

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

        // Revision 2

        em.getTransaction().begin();

        entity1 = em.find(SortedSetEntity.class, 1);
        final StrTestEntity strTestEntity1 = new StrTestEntity("abc");
        em.persist(strTestEntity1);
        id1 = strTestEntity1.getId();
        entity1.getSortedSet().add(strTestEntity1);
    entity1.getSortedMap().put(strTestEntity1, "abc");

        em.getTransaction().commit();

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

        entity1 = em.find(SortedSetEntity.class, 1);
        final StrTestEntity strTestEntity2 = new StrTestEntity("aaa");
        em.persist(strTestEntity2);
        id2 = strTestEntity2.getId();
        entity1.getSortedSet().add(strTestEntity2);
    entity1.getSortedMap().put(strTestEntity2, "aaa");

        em.getTransaction().commit();

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

        entity1 = em.find(SortedSetEntity.class, 1);
        final StrTestEntity strTestEntity3 = new StrTestEntity("aba");
        em.persist(strTestEntity3);
        id3 = strTestEntity3.getId();
        entity1.getSortedSet().add(strTestEntity3);
    entity1.getSortedMap().put(strTestEntity3, "aba");

        em.getTransaction().commit();

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

        entity1 = em.find(SortedSetEntity.class, 1);
        final StrTestEntity strTestEntity4 = new StrTestEntity("aac");
        em.persist(strTestEntity4);
        id4 = strTestEntity4.getId();
        entity1.getSortedSet().add(strTestEntity4);
    entity1.getSortedMap().put(strTestEntity4, "aac");

        em.getTransaction().commit();
    }
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.