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();
}
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();
}
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();
}
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;
}
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;
}
Aggregations