Search in sources :

Example 66 with Priority

use of org.hibernate.envers.test.Priority in project hibernate-orm by hibernate.

the class BasicCollection method initData.

@Test
@Priority(10)
public void initData() {
    EntityManager em = getEntityManager();
    CollectionRefEdEntity ed1 = new CollectionRefEdEntity(1, "data_ed_1");
    CollectionRefEdEntity ed2 = new CollectionRefEdEntity(2, "data_ed_2");
    CollectionRefIngEntity ing1 = new CollectionRefIngEntity(3, "data_ing_1", ed1);
    CollectionRefIngEntity ing2 = new CollectionRefIngEntity(4, "data_ing_2", ed1);
    // 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(CollectionRefIngEntity.class, ing1.getId());
    ed2 = em.find(CollectionRefEdEntity.class, ed2.getId());
    ing1.setReference(ed2);
    em.getTransaction().commit();
    // Revision 3
    em.getTransaction().begin();
    ing2 = em.find(CollectionRefIngEntity.class, ing2.getId());
    ed2 = em.find(CollectionRefEdEntity.class, ed2.getId());
    ing2.setReference(ed2);
    em.getTransaction().commit();
    //
    ed1_id = ed1.getId();
    ed2_id = ed2.getId();
    ing1_id = ing1.getId();
    ing2_id = ing2.getId();
}
Also used : EntityManager(javax.persistence.EntityManager) CollectionRefIngEntity(org.hibernate.envers.test.entities.onetomany.CollectionRefIngEntity) CollectionRefEdEntity(org.hibernate.envers.test.entities.onetomany.CollectionRefEdEntity) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 67 with Priority

use of org.hibernate.envers.test.Priority in project hibernate-orm by hibernate.

the class BasicList method initData.

@Test
@Priority(10)
public void initData() {
    EntityManager em = getEntityManager();
    ListRefEdEntity ed1 = new ListRefEdEntity(1, "data_ed_1");
    ListRefEdEntity ed2 = new ListRefEdEntity(2, "data_ed_2");
    ListRefIngEntity ing1 = new ListRefIngEntity(3, "data_ing_1", ed1);
    ListRefIngEntity ing2 = new ListRefIngEntity(4, "data_ing_2", ed1);
    // 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(ListRefIngEntity.class, ing1.getId());
    ed2 = em.find(ListRefEdEntity.class, ed2.getId());
    ing1.setReference(ed2);
    em.getTransaction().commit();
    // Revision 3
    em.getTransaction().begin();
    ing2 = em.find(ListRefIngEntity.class, ing2.getId());
    ed2 = em.find(ListRefEdEntity.class, ed2.getId());
    ing2.setReference(ed2);
    em.getTransaction().commit();
    //
    ed1_id = ed1.getId();
    ed2_id = ed2.getId();
    ing1_id = ing1.getId();
    ing2_id = ing2.getId();
}
Also used : EntityManager(javax.persistence.EntityManager) ListRefIngEntity(org.hibernate.envers.test.entities.onetomany.ListRefIngEntity) ListRefEdEntity(org.hibernate.envers.test.entities.onetomany.ListRefEdEntity) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 68 with Priority

use of org.hibernate.envers.test.Priority in project hibernate-orm by hibernate.

the class BasicSetWithEmbId method initData.

@Test
@Priority(10)
public void initData() {
    ed1_id = new EmbId(0, 1);
    ed2_id = new EmbId(2, 3);
    ing2_id = new EmbId(4, 5);
    ing1_id = new EmbId(6, 7);
    EntityManager em = getEntityManager();
    SetRefEdEmbIdEntity ed1 = new SetRefEdEmbIdEntity(ed1_id, "data_ed_1");
    SetRefEdEmbIdEntity ed2 = new SetRefEdEmbIdEntity(ed2_id, "data_ed_2");
    SetRefIngEmbIdEntity ing1 = new SetRefIngEmbIdEntity(ing1_id, "data_ing_1", ed1);
    SetRefIngEmbIdEntity ing2 = new SetRefIngEmbIdEntity(ing2_id, "data_ing_2", ed1);
    // 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(SetRefIngEmbIdEntity.class, ing1.getId());
    ed2 = em.find(SetRefEdEmbIdEntity.class, ed2.getId());
    ing1.setReference(ed2);
    em.getTransaction().commit();
    // Revision 3
    em.getTransaction().begin();
    ing2 = em.find(SetRefIngEmbIdEntity.class, ing2.getId());
    ed2 = em.find(SetRefEdEmbIdEntity.class, ed2.getId());
    ing2.setReference(ed2);
    em.getTransaction().commit();
}
Also used : EntityManager(javax.persistence.EntityManager) SetRefIngEmbIdEntity(org.hibernate.envers.test.entities.onetomany.ids.SetRefIngEmbIdEntity) EmbId(org.hibernate.envers.test.entities.ids.EmbId) SetRefEdEmbIdEntity(org.hibernate.envers.test.entities.onetomany.ids.SetRefEdEmbIdEntity) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 69 with Priority

use of org.hibernate.envers.test.Priority in project hibernate-orm by hibernate.

the class ValidityAuditStrategyRevEndTestCustomRevEnt method initData.

@Test
@Priority(10)
public void initData() {
    EntityManager em = getEntityManager();
    // We need first to modify the columns in the middle (join table) to
    // allow null values. Hbm2ddl doesn't seem
    // to allow this.
    em.getTransaction().begin();
    Session session = (Session) em.getDelegate();
    session.createSQLQuery("DROP TABLE children").executeUpdate();
    session.createSQLQuery("CREATE TABLE children ( parent_id " + getDialect().getTypeName(Types.INTEGER) + ", child1_id " + getDialect().getTypeName(Types.INTEGER) + getDialect().getNullColumnString() + ", child2_id " + getDialect().getTypeName(Types.INTEGER) + getDialect().getNullColumnString() + " )").executeUpdate();
    session.createSQLQuery("DROP TABLE children_AUD").executeUpdate();
    session.createSQLQuery("CREATE TABLE children_AUD ( REV " + getDialect().getTypeName(Types.INTEGER) + " NOT NULL" + ", REVEND " + getDialect().getTypeName(Types.INTEGER) + ", " + revendTimestampColumName + " " + getDialect().getTypeName(Types.TIMESTAMP) + ", REVTYPE " + getDialect().getTypeName(Types.TINYINT) + ", parent_id " + getDialect().getTypeName(Types.INTEGER) + ", child1_id " + getDialect().getTypeName(Types.INTEGER) + getDialect().getNullColumnString() + ", child2_id " + getDialect().getTypeName(Types.INTEGER) + getDialect().getNullColumnString() + " )").executeUpdate();
    em.getTransaction().commit();
    em.clear();
    ParentEntity p1 = new ParentEntity("parent_1");
    ParentEntity p2 = new ParentEntity("parent_2");
    Child1Entity c1_1 = new Child1Entity("child1_1");
    Child1Entity c1_2 = new Child1Entity("child1_2");
    Child2Entity c2_1 = new Child2Entity("child2_1");
    Child2Entity c2_2 = new Child2Entity("child2_2");
    // Revision 1
    em.getTransaction().begin();
    em.persist(p1);
    em.persist(p2);
    em.persist(c1_1);
    em.persist(c1_2);
    em.persist(c2_1);
    em.persist(c2_2);
    em.getTransaction().commit();
    em.clear();
    // Revision 2 - (p1: c1_1, p2: c2_1)
    em.getTransaction().begin();
    p1 = em.find(ParentEntity.class, p1.getId());
    p2 = em.find(ParentEntity.class, p2.getId());
    c1_1 = em.find(Child1Entity.class, c1_1.getId());
    c2_1 = em.find(Child2Entity.class, c2_1.getId());
    p1.getChildren1().add(c1_1);
    p2.getChildren2().add(c2_1);
    em.getTransaction().commit();
    em.clear();
    // Revision 3 - (p1: c1_1, c1_2, c2_2, p2: c1_1, c2_1)
    em.getTransaction().begin();
    p1 = em.find(ParentEntity.class, p1.getId());
    p2 = em.find(ParentEntity.class, p2.getId());
    c1_1 = em.find(Child1Entity.class, c1_1.getId());
    c1_2 = em.find(Child1Entity.class, c1_2.getId());
    c2_2 = em.find(Child2Entity.class, c2_2.getId());
    p1.getChildren1().add(c1_2);
    p1.getChildren2().add(c2_2);
    p2.getChildren1().add(c1_1);
    em.getTransaction().commit();
    em.clear();
    // Revision 4 - (p1: c1_2, c2_2, p2: c1_1, c2_1, c2_2)
    em.getTransaction().begin();
    p1 = em.find(ParentEntity.class, p1.getId());
    p2 = em.find(ParentEntity.class, p2.getId());
    c1_1 = em.find(Child1Entity.class, c1_1.getId());
    c2_2 = em.find(Child2Entity.class, c2_2.getId());
    p1.getChildren1().remove(c1_1);
    p2.getChildren2().add(c2_2);
    em.getTransaction().commit();
    em.clear();
    // Revision 5 - (p1: c2_2, p2: c1_1, c2_1)
    em.getTransaction().begin();
    p1 = em.find(ParentEntity.class, p1.getId());
    p2 = em.find(ParentEntity.class, p2.getId());
    c1_2 = em.find(Child1Entity.class, c1_2.getId());
    c2_2 = em.find(Child2Entity.class, c2_2.getId());
    c2_2.getParents().remove(p2);
    c1_2.getParents().remove(p1);
    em.getTransaction().commit();
    em.clear();
    //
    p1_id = p1.getId();
    p2_id = p2.getId();
    c1_1_id = c1_1.getId();
    c1_2_id = c1_2.getId();
    c2_1_id = c2_1.getId();
    c2_2_id = c2_2.getId();
    Set<Number> revisionNumbers = new HashSet<Number>();
    revisionNumbers.addAll(Arrays.asList(1, 2, 3, 4, 5));
    revisions = getAuditReader().findRevisions(CustomDateRevEntity.class, revisionNumbers);
    assert revisions.size() == 5;
}
Also used : EntityManager(javax.persistence.EntityManager) Child1Entity(org.hibernate.envers.test.entities.manytomany.sametable.Child1Entity) ParentEntity(org.hibernate.envers.test.entities.manytomany.sametable.ParentEntity) Child2Entity(org.hibernate.envers.test.entities.manytomany.sametable.Child2Entity) CustomDateRevEntity(org.hibernate.envers.test.entities.reventity.CustomDateRevEntity) Session(org.hibernate.Session) HashSet(java.util.HashSet) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 70 with Priority

use of org.hibernate.envers.test.Priority in project hibernate-orm by hibernate.

the class ValidityAuditStrategyRevEndTsTest method initData.

@Test
@Priority(10)
public void initData() {
    EntityManager em = getEntityManager();
    // We need first to modify the columns in the middle (join table) to
    // allow null values. Hbm2ddl doesn't seem
    // to allow this.
    em.getTransaction().begin();
    Session session = (Session) em.getDelegate();
    session.createSQLQuery("DROP TABLE children").executeUpdate();
    session.createSQLQuery("CREATE TABLE children ( parent_id " + getDialect().getTypeName(Types.INTEGER) + ", child1_id " + getDialect().getTypeName(Types.INTEGER) + getDialect().getNullColumnString() + ", child2_id " + getDialect().getTypeName(Types.INTEGER) + getDialect().getNullColumnString() + " )").executeUpdate();
    session.createSQLQuery("DROP TABLE children_AUD").executeUpdate();
    session.createSQLQuery("CREATE TABLE children_AUD ( REV " + getDialect().getTypeName(Types.INTEGER) + " NOT NULL" + ", REVEND " + getDialect().getTypeName(Types.INTEGER) + ", " + revendTimestampColumName + " " + getDialect().getTypeName(Types.TIMESTAMP) + ", REVTYPE " + getDialect().getTypeName(Types.TINYINT) + ", parent_id " + getDialect().getTypeName(Types.INTEGER) + ", child1_id " + getDialect().getTypeName(Types.INTEGER) + getDialect().getNullColumnString() + ", child2_id " + getDialect().getTypeName(Types.INTEGER) + getDialect().getNullColumnString() + " )").executeUpdate();
    em.getTransaction().commit();
    em.clear();
    ParentEntity p1 = new ParentEntity("parent_1");
    ParentEntity p2 = new ParentEntity("parent_2");
    Child1Entity c1_1 = new Child1Entity("child1_1");
    Child1Entity c1_2 = new Child1Entity("child1_2");
    Child2Entity c2_1 = new Child2Entity("child2_1");
    Child2Entity c2_2 = new Child2Entity("child2_2");
    // Revision 1
    em.getTransaction().begin();
    em.persist(p1);
    em.persist(p2);
    em.persist(c1_1);
    em.persist(c1_2);
    em.persist(c2_1);
    em.persist(c2_2);
    em.getTransaction().commit();
    em.clear();
    // Revision 2 - (p1: c1_1, p2: c2_1)
    em.getTransaction().begin();
    p1 = em.find(ParentEntity.class, p1.getId());
    p2 = em.find(ParentEntity.class, p2.getId());
    c1_1 = em.find(Child1Entity.class, c1_1.getId());
    c2_1 = em.find(Child2Entity.class, c2_1.getId());
    p1.getChildren1().add(c1_1);
    p2.getChildren2().add(c2_1);
    em.getTransaction().commit();
    em.clear();
    // Revision 3 - (p1: c1_1, c1_2, c2_2, p2: c1_1, c2_1)
    em.getTransaction().begin();
    p1 = em.find(ParentEntity.class, p1.getId());
    p2 = em.find(ParentEntity.class, p2.getId());
    c1_1 = em.find(Child1Entity.class, c1_1.getId());
    c1_2 = em.find(Child1Entity.class, c1_2.getId());
    c2_2 = em.find(Child2Entity.class, c2_2.getId());
    p1.getChildren1().add(c1_2);
    p1.getChildren2().add(c2_2);
    p2.getChildren1().add(c1_1);
    em.getTransaction().commit();
    em.clear();
    // Revision 4 - (p1: c1_2, c2_2, p2: c1_1, c2_1, c2_2)
    em.getTransaction().begin();
    p1 = em.find(ParentEntity.class, p1.getId());
    p2 = em.find(ParentEntity.class, p2.getId());
    c1_1 = em.find(Child1Entity.class, c1_1.getId());
    c2_2 = em.find(Child2Entity.class, c2_2.getId());
    p1.getChildren1().remove(c1_1);
    p2.getChildren2().add(c2_2);
    em.getTransaction().commit();
    em.clear();
    // Revision 5 - (p1: c2_2, p2: c1_1, c2_1)
    em.getTransaction().begin();
    p1 = em.find(ParentEntity.class, p1.getId());
    p2 = em.find(ParentEntity.class, p2.getId());
    c1_2 = em.find(Child1Entity.class, c1_2.getId());
    c2_2 = em.find(Child2Entity.class, c2_2.getId());
    c2_2.getParents().remove(p2);
    c1_2.getParents().remove(p1);
    em.getTransaction().commit();
    em.clear();
    //
    p1_id = p1.getId();
    p2_id = p2.getId();
    c1_1_id = c1_1.getId();
    c1_2_id = c1_2.getId();
    c2_1_id = c2_1.getId();
    c2_2_id = c2_2.getId();
    Set<Number> revisionNumbers = new HashSet<Number>();
    revisionNumbers.addAll(Arrays.asList(1, 2, 3, 4, 5));
    revisions = getAuditReader().findRevisions(SequenceIdRevisionEntity.class, revisionNumbers);
    assert revisions.size() == 5;
}
Also used : EntityManager(javax.persistence.EntityManager) Child1Entity(org.hibernate.envers.test.entities.manytomany.sametable.Child1Entity) SequenceIdRevisionEntity(org.hibernate.envers.enhanced.SequenceIdRevisionEntity) ParentEntity(org.hibernate.envers.test.entities.manytomany.sametable.ParentEntity) Child2Entity(org.hibernate.envers.test.entities.manytomany.sametable.Child2Entity) Session(org.hibernate.Session) HashSet(java.util.HashSet) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Aggregations

Priority (org.hibernate.envers.test.Priority)268 Test (org.junit.Test)268 EntityManager (javax.persistence.EntityManager)249 StrTestEntity (org.hibernate.envers.test.entities.StrTestEntity)48 Session (org.hibernate.Session)16 StrIntTestEntity (org.hibernate.envers.test.entities.StrIntTestEntity)12 EmbId (org.hibernate.envers.test.entities.ids.EmbId)8 UnversionedStrTestEntity (org.hibernate.envers.test.entities.UnversionedStrTestEntity)7 Component1 (org.hibernate.envers.test.entities.components.Component1)7 MulId (org.hibernate.envers.test.entities.ids.MulId)7 HashSet (java.util.HashSet)6 IntTestEntity (org.hibernate.envers.test.entities.IntTestEntity)6 SetRefEdEntity (org.hibernate.envers.test.entities.onetomany.SetRefEdEntity)6 SetRefIngEntity (org.hibernate.envers.test.entities.onetomany.SetRefIngEntity)6 Component2 (org.hibernate.envers.test.entities.components.Component2)5 ComponentTestEntity (org.hibernate.envers.test.entities.components.ComponentTestEntity)4 CollectionRefEdEntity (org.hibernate.envers.test.entities.onetomany.CollectionRefEdEntity)4 CollectionRefIngEntity (org.hibernate.envers.test.entities.onetomany.CollectionRefIngEntity)4 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3