Search in sources :

Example 1 with Component1

use of org.hibernate.envers.test.entities.components.Component1 in project hibernate-orm by hibernate.

the class CollectionOfComponents method initData.

@Test
@Priority(10)
public void initData() {
    // Revision 1
    EntityManager em = getEntityManager();
    em.getTransaction().begin();
    ComponentSetTestEntity cte1 = new ComponentSetTestEntity();
    ComponentSetTestEntity cte2 = new ComponentSetTestEntity();
    cte2.getComps().add(new Component1("string1", null));
    em.persist(cte2);
    em.persist(cte1);
    em.getTransaction().commit();
    // Revision 2
    em = getEntityManager();
    em.getTransaction().begin();
    cte1 = em.find(ComponentSetTestEntity.class, cte1.getId());
    cte1.getComps().add(new Component1("a", "b"));
    em.getTransaction().commit();
    id1 = cte1.getId();
    id2 = cte2.getId();
}
Also used : EntityManager(javax.persistence.EntityManager) Component1(org.hibernate.envers.test.entities.components.Component1) ComponentSetTestEntity(org.hibernate.envers.test.entities.components.ComponentSetTestEntity) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 2 with Component1

use of org.hibernate.envers.test.entities.components.Component1 in project hibernate-orm by hibernate.

the class Components method testHistoryOfId4.

@Test
public void testHistoryOfId4() {
    ComponentTestEntity ver1 = new ComponentTestEntity(id4, null, null);
    ComponentTestEntity ver2 = new ComponentTestEntity(id4, new Component1("n", null), null);
    ComponentTestEntity ver3 = new ComponentTestEntity(id4, null, null);
    assert getAuditReader().find(ComponentTestEntity.class, id4, 1).equals(ver1);
    assert getAuditReader().find(ComponentTestEntity.class, id4, 2).equals(ver2);
    assert getAuditReader().find(ComponentTestEntity.class, id4, 3).equals(ver3);
    assert getAuditReader().find(ComponentTestEntity.class, id4, 4).equals(ver3);
}
Also used : Component1(org.hibernate.envers.test.entities.components.Component1) ComponentTestEntity(org.hibernate.envers.test.entities.components.ComponentTestEntity) Test(org.junit.Test)

Example 3 with Component1

use of org.hibernate.envers.test.entities.components.Component1 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 4 with Component1

use of org.hibernate.envers.test.entities.components.Component1 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 5 with Component1

use of org.hibernate.envers.test.entities.components.Component1 in project hibernate-orm by hibernate.

the class HasChangedComponents method initData.

@Test
@Priority(10)
public void initData() {
    // Revision 1
    EntityManager em = getEntityManager();
    em.getTransaction().begin();
    ComponentTestEntity cte1 = new ComponentTestEntity(new Component1("a", "b"), new Component2("x", "y"));
    ComponentTestEntity cte2 = new ComponentTestEntity(new Component1("a2", "b2"), new Component2("x2", "y2"));
    ComponentTestEntity cte3 = new ComponentTestEntity(new Component1("a3", "b3"), new Component2("x3", "y3"));
    ComponentTestEntity cte4 = new ComponentTestEntity(null, null);
    em.persist(cte1);
    em.persist(cte2);
    em.persist(cte3);
    em.persist(cte4);
    em.getTransaction().commit();
    // Revision 2
    em = getEntityManager();
    em.getTransaction().begin();
    cte1 = em.find(ComponentTestEntity.class, cte1.getId());
    cte2 = em.find(ComponentTestEntity.class, cte2.getId());
    cte3 = em.find(ComponentTestEntity.class, cte3.getId());
    cte4 = em.find(ComponentTestEntity.class, cte4.getId());
    cte1.setComp1(new Component1("a'", "b'"));
    cte2.getComp1().setStr1("a2'");
    cte3.getComp2().setStr6("y3'");
    cte4.setComp1(new Component1());
    cte4.getComp1().setStr1("n");
    cte4.setComp2(new Component2());
    cte4.getComp2().setStr5("m");
    em.getTransaction().commit();
    // Revision 3
    em = getEntityManager();
    em.getTransaction().begin();
    cte1 = em.find(ComponentTestEntity.class, cte1.getId());
    cte2 = em.find(ComponentTestEntity.class, cte2.getId());
    cte3 = em.find(ComponentTestEntity.class, cte3.getId());
    cte4 = em.find(ComponentTestEntity.class, cte4.getId());
    cte1.setComp2(new Component2("x'", "y'"));
    cte3.getComp1().setStr2("b3'");
    cte4.setComp1(null);
    cte4.setComp2(null);
    em.getTransaction().commit();
    // Revision 4
    em = getEntityManager();
    em.getTransaction().begin();
    cte2 = em.find(ComponentTestEntity.class, cte2.getId());
    em.remove(cte2);
    em.getTransaction().commit();
    id1 = cte1.getId();
    id2 = cte2.getId();
    id3 = cte3.getId();
    id4 = cte4.getId();
}
Also used : EntityManager(javax.persistence.EntityManager) Component1(org.hibernate.envers.test.entities.components.Component1) Component2(org.hibernate.envers.test.entities.components.Component2) ComponentTestEntity(org.hibernate.envers.test.entities.components.ComponentTestEntity) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Aggregations

Component1 (org.hibernate.envers.test.entities.components.Component1)12 Test (org.junit.Test)12 ComponentTestEntity (org.hibernate.envers.test.entities.components.ComponentTestEntity)8 EntityManager (javax.persistence.EntityManager)7 Priority (org.hibernate.envers.test.Priority)7 Component2 (org.hibernate.envers.test.entities.components.Component2)5 ComponentSetTestEntity (org.hibernate.envers.test.entities.components.ComponentSetTestEntity)2 StrTestEntity (org.hibernate.envers.test.entities.StrTestEntity)1 ComponentMapKeyEntity (org.hibernate.envers.test.integration.collection.mapkey.ComponentMapKeyEntity)1 PartialModifiedFlagsEntity (org.hibernate.envers.test.integration.modifiedflags.entities.PartialModifiedFlagsEntity)1 WithModifiedFlagReferencingEntity (org.hibernate.envers.test.integration.modifiedflags.entities.WithModifiedFlagReferencingEntity)1 TestForIssue (org.hibernate.testing.TestForIssue)1