Search in sources :

Example 36 with Priority

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

the class HasChangedEnumSet method initData.

@Test
@Priority(10)
public void initData() {
    EntityManager em = getEntityManager();
    EnumSetEntity sse1 = new EnumSetEntity();
    // Revision 1 (sse1: initialy 1 element)
    em.getTransaction().begin();
    sse1.getEnums1().add(E1.X);
    sse1.getEnums2().add(E2.A);
    em.persist(sse1);
    em.getTransaction().commit();
    // Revision 2 (sse1: adding 1 element/removing a non-existing element)
    em.getTransaction().begin();
    sse1 = em.find(EnumSetEntity.class, sse1.getId());
    sse1.getEnums1().add(E1.Y);
    sse1.getEnums2().remove(E2.B);
    em.getTransaction().commit();
    // Revision 3 (sse1: removing 1 element/adding an exisiting element)
    em.getTransaction().begin();
    sse1 = em.find(EnumSetEntity.class, sse1.getId());
    sse1.getEnums1().remove(E1.X);
    sse1.getEnums2().add(E2.A);
    em.getTransaction().commit();
    //
    sse1_id = sse1.getId();
}
Also used : EntityManager(javax.persistence.EntityManager) EnumSetEntity(org.hibernate.envers.test.entities.collection.EnumSetEntity) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 37 with Priority

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

the class HasChangedForDefaultNotUsing method initData.

@Test
@Priority(10)
public void initData() {
    PartialModifiedFlagsEntity entity = new PartialModifiedFlagsEntity(entityId);
    // Revision 1
    EntityManager em = getEntityManager();
    em.getTransaction().begin();
    em.persist(entity);
    em.getTransaction().commit();
    // Revision 2
    em.getTransaction().begin();
    entity.setData("data1");
    entity = em.merge(entity);
    em.getTransaction().commit();
    // Revision 3
    em.getTransaction().begin();
    entity.setComp1(new Component1("str1", "str2"));
    entity = em.merge(entity);
    em.getTransaction().commit();
    // Revision 4
    em.getTransaction().begin();
    entity.setComp2(new Component2("str1", "str2"));
    entity = em.merge(entity);
    em.getTransaction().commit();
    // Revision 5
    em.getTransaction().begin();
    WithModifiedFlagReferencingEntity withModifiedFlagReferencingEntity = new WithModifiedFlagReferencingEntity(refEntityId, "first");
    withModifiedFlagReferencingEntity.setReference(entity);
    em.persist(withModifiedFlagReferencingEntity);
    em.getTransaction().commit();
    // Revision 6
    em.getTransaction().begin();
    withModifiedFlagReferencingEntity = em.find(WithModifiedFlagReferencingEntity.class, refEntityId);
    withModifiedFlagReferencingEntity.setReference(null);
    withModifiedFlagReferencingEntity.setSecondReference(entity);
    em.merge(withModifiedFlagReferencingEntity);
    em.getTransaction().commit();
    // Revision 7
    em.getTransaction().begin();
    entity.getStringSet().add("firstElement");
    entity.getStringSet().add("secondElement");
    entity = em.merge(entity);
    em.getTransaction().commit();
    // Revision 8
    em.getTransaction().begin();
    entity.getStringSet().remove("secondElement");
    entity.getStringMap().put("someKey", "someValue");
    entity = em.merge(entity);
    em.getTransaction().commit();
    // Revision 9 - main entity doesn't change
    em.getTransaction().begin();
    StrTestEntity strTestEntity = new StrTestEntity("first");
    em.persist(strTestEntity);
    em.getTransaction().commit();
    // Revision 10
    em.getTransaction().begin();
    entity.getEntitiesSet().add(strTestEntity);
    entity = em.merge(entity);
    em.getTransaction().commit();
    // Revision 11
    em.getTransaction().begin();
    entity.getEntitiesSet().remove(strTestEntity);
    entity.getEntitiesMap().put("someKey", strTestEntity);
    em.merge(entity);
    em.getTransaction().commit();
    // Revision 12 - main entity doesn't change
    em.getTransaction().begin();
    strTestEntity.setStr("second");
    em.merge(strTestEntity);
    em.getTransaction().commit();
}
Also used : StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) EntityManager(javax.persistence.EntityManager) Component1(org.hibernate.envers.test.entities.components.Component1) Component2(org.hibernate.envers.test.entities.components.Component2) WithModifiedFlagReferencingEntity(org.hibernate.envers.test.integration.modifiedflags.entities.WithModifiedFlagReferencingEntity) PartialModifiedFlagsEntity(org.hibernate.envers.test.integration.modifiedflags.entities.PartialModifiedFlagsEntity) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 38 with Priority

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

the class VersionsJoinTableRangeComponentNamingTest method initData.

@Test
@Priority(10)
public void initData() {
    // Revision 1
    EntityManager em = getEntityManager();
    em.getTransaction().begin();
    // create an instance of the test entity
    VersionsJoinTableRangeComponentTestEntity vjrcte = new VersionsJoinTableRangeComponentTestEntity();
    em.persist(vjrcte);
    em.getTransaction().commit();
    // Revision 2
    em.getTransaction().begin();
    vjrcte = em.find(VersionsJoinTableRangeComponentTestEntity.class, vjrcte.getId());
    // create a component containing a list of
    // VersionsJoinTableRangeTestEntity-instances
    VersionsJoinTableRangeTestEntity vjtrte = new VersionsJoinTableRangeTestEntity();
    vjtrte.setGenericValue("generic1");
    vjtrte.setValue("value1");
    // and add it to the test entity
    vjrcte.getComponent1().getRange().add(vjtrte);
    // create a second component containing a list of
    // VersionsJoinTableRangeTestAlternateEntity-instances
    VersionsJoinTableRangeTestAlternateEntity vjtrtae1 = new VersionsJoinTableRangeTestAlternateEntity();
    vjtrtae1.setGenericValue("generic2");
    vjtrtae1.setAlternateValue("alternateValue2");
    // and add it to the test entity
    vjrcte.getComponent2().getRange().add(vjtrtae1);
    // create a third component, and add it to the test entity
    Component1 simpleComponent = new Component1("string1", "string2");
    vjrcte.setComponent3(simpleComponent);
    em.persist(vjtrte);
    em.persist(vjtrtae1);
    em.persist(vjrcte);
    em.getTransaction().commit();
    // Revision 2
    em.getTransaction().begin();
    vjrcte = em.find(VersionsJoinTableRangeComponentTestEntity.class, vjrcte.getId());
    vjtrte = em.find(VersionsJoinTableRangeTestEntity.class, vjtrte.getId());
    vjtrtae1 = em.find(VersionsJoinTableRangeTestAlternateEntity.class, vjtrtae1.getId());
    assert vjrcte != null;
    assert vjtrte != null;
    assert vjtrtae1 != null;
    List<VersionsJoinTableRangeTestEntity> ent1List = vjrcte.getComponent1().getRange();
    assert ent1List.size() == 1;
    assert vjtrte.equals(ent1List.get(0));
    List<VersionsJoinTableRangeTestAlternateEntity> ent2List = vjrcte.getComponent2().getRange();
    assert ent2List.size() == 1;
    assert vjtrtae1.equals(ent2List.get(0));
    em.getTransaction().commit();
    vjrcte_id = vjrcte.getId();
    vjtrte_id = vjtrte.getId();
    vjtrtae_id1 = vjtrtae1.getId();
}
Also used : EntityManager(javax.persistence.EntityManager) Component1(org.hibernate.envers.test.entities.components.Component1) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 39 with Priority

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

the class JoinMulIdNaming method initData.

@Test
@Priority(10)
public void initData() {
    ed_id1 = new MulIdNaming(10, 20);
    ed_id2 = new MulIdNaming(11, 21);
    ing_id1 = new MulIdNaming(12, 22);
    JoinMulIdNamingRefEdEntity ed1 = new JoinMulIdNamingRefEdEntity(ed_id1, "data1");
    JoinMulIdNamingRefEdEntity ed2 = new JoinMulIdNamingRefEdEntity(ed_id2, "data2");
    JoinMulIdNamingRefIngEntity ing1 = new JoinMulIdNamingRefIngEntity(ing_id1, "x", ed1);
    // Revision 1
    EntityManager em = getEntityManager();
    em.getTransaction().begin();
    em.persist(ed1);
    em.persist(ed2);
    em.persist(ing1);
    em.getTransaction().commit();
    // Revision 2
    em.getTransaction().begin();
    ed2 = em.find(JoinMulIdNamingRefEdEntity.class, ed_id2);
    ing1 = em.find(JoinMulIdNamingRefIngEntity.class, ing_id1);
    ing1.setData("y");
    ing1.setReference(ed2);
    em.getTransaction().commit();
}
Also used : EntityManager(javax.persistence.EntityManager) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 40 with Priority

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

the class QuotedFieldsTest method initData.

@Test
@Priority(10)
public void initData() {
    QuotedFieldsEntity qfe1 = new QuotedFieldsEntity("data1", 1);
    QuotedFieldsEntity qfe2 = new QuotedFieldsEntity("data2", 2);
    // Revision 1
    EntityManager em = getEntityManager();
    em.getTransaction().begin();
    em.persist(qfe1);
    em.persist(qfe2);
    em.getTransaction().commit();
    // Revision 2
    em.getTransaction().begin();
    qfe1 = em.find(QuotedFieldsEntity.class, qfe1.getId());
    qfe1.setData1("data1 changed");
    em.getTransaction().commit();
    // Revision 3
    em.getTransaction().begin();
    qfe2 = em.find(QuotedFieldsEntity.class, qfe2.getId());
    qfe2.setData2(3);
    em.getTransaction().commit();
    qfeId1 = qfe1.getId();
    qfeId2 = qfe2.getId();
}
Also used : EntityManager(javax.persistence.EntityManager) 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