Search in sources :

Example 81 with Priority

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

the class CustomDate method initData.

@Test
@Priority(10)
public void initData() throws InterruptedException {
    timestamp1 = System.currentTimeMillis();
    // CustomDateRevEntity.dateTimestamp field maps to date type which on some RDBMSs gets
    Thread.sleep(1100);
    // truncated to seconds (for example MySQL 5.1).
    // Revision 1
    EntityManager em = getEntityManager();
    em.getTransaction().begin();
    StrTestEntity te = new StrTestEntity("x");
    em.persist(te);
    id = te.getId();
    em.getTransaction().commit();
    timestamp2 = System.currentTimeMillis();
    // CustomDateRevEntity.dateTimestamp field maps to date type which on some RDBMSs gets
    Thread.sleep(1100);
    // truncated to seconds (for example MySQL 5.1).
    // Revision 2
    em.getTransaction().begin();
    te = em.find(StrTestEntity.class, id);
    te.setStr("y");
    em.getTransaction().commit();
    timestamp3 = System.currentTimeMillis();
}
Also used : StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) EntityManager(javax.persistence.EntityManager) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 82 with Priority

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

the class CustomNoListener method initData.

@Test
@Priority(10)
public void initData() throws InterruptedException {
    EntityManager em = getEntityManager();
    // Revision 1
    em.getTransaction().begin();
    StrTestEntity te = new StrTestEntity("x");
    em.persist(te);
    id = te.getId();
    // Setting the data on the revision entity
    CustomDataRevEntity custom = getAuditReader().getCurrentRevision(CustomDataRevEntity.class, false);
    custom.setData("data1");
    em.getTransaction().commit();
    // Revision 2
    em.getTransaction().begin();
    te = em.find(StrTestEntity.class, id);
    te.setStr("y");
    // Setting the data on the revision entity
    custom = getAuditReader().getCurrentRevision(CustomDataRevEntity.class, false);
    custom.setData("data2");
    em.getTransaction().commit();
    // Revision 3 - no changes, but rev entity should be persisted
    em.getTransaction().begin();
    // Setting the data on the revision entity
    custom = getAuditReader().getCurrentRevision(CustomDataRevEntity.class, true);
    custom.setData("data3");
    em.getTransaction().commit();
    // No changes, rev entity won't be persisted
    em.getTransaction().begin();
    // Setting the data on the revision entity
    custom = getAuditReader().getCurrentRevision(CustomDataRevEntity.class, false);
    custom.setData("data4");
    em.getTransaction().commit();
    // Revision 4
    em.getTransaction().begin();
    te = em.find(StrTestEntity.class, id);
    te.setStr("z");
    // Setting the data on the revision entity
    custom = getAuditReader().getCurrentRevision(CustomDataRevEntity.class, false);
    custom.setData("data5");
    custom = getAuditReader().getCurrentRevision(CustomDataRevEntity.class, false);
    custom.setData("data5bis");
    em.getTransaction().commit();
}
Also used : StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) EntityManager(javax.persistence.EntityManager) CustomDataRevEntity(org.hibernate.envers.test.entities.reventity.CustomDataRevEntity) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 83 with Priority

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

the class NullPropertyQuery method initData.

@Test
@Priority(10)
public void initData() {
    // Revision 1
    EntityManager em = getEntityManager();
    em.getTransaction().begin();
    StrIntTestEntity nullSite = new StrIntTestEntity(null, 1);
    StrIntTestEntity notNullSite = new StrIntTestEntity("data", 2);
    em.persist(nullSite);
    em.persist(notNullSite);
    idSimplePropertyNull = nullSite.getId();
    idSimplePropertyNotNull = notNullSite.getId();
    em.getTransaction().commit();
    // Revision 2
    em.getTransaction().begin();
    SetRefIngEmbIdEntity nullParentSrieie = new SetRefIngEmbIdEntity(idMulticolumnReferenceToParentNull, "data", null);
    em.persist(nullParentSrieie);
    em.getTransaction().commit();
    // Revision 3
    em.getTransaction().begin();
    CollectionRefEdEntity parent = new CollectionRefEdEntity(idParent, "data");
    CollectionRefIngEntity notNullParentCrie = new CollectionRefIngEntity(idReferenceToParentNotNull, "data", parent);
    em.persist(parent);
    em.persist(notNullParentCrie);
    em.getTransaction().commit();
}
Also used : StrIntTestEntity(org.hibernate.envers.test.entities.StrIntTestEntity) EntityManager(javax.persistence.EntityManager) SetRefIngEmbIdEntity(org.hibernate.envers.test.entities.onetomany.ids.SetRefIngEmbIdEntity) 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 84 with Priority

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

the class OrderByLimitQuery method initData.

@Test
@Priority(10)
public void initData() {
    // Revision 1
    EntityManager em = getEntityManager();
    em.getTransaction().begin();
    IntTestEntity ite1 = new IntTestEntity(12);
    IntTestEntity ite2 = new IntTestEntity(5);
    IntTestEntity ite3 = new IntTestEntity(8);
    IntTestEntity ite4 = new IntTestEntity(1);
    em.persist(ite1);
    em.persist(ite2);
    em.persist(ite3);
    em.persist(ite4);
    id1 = ite1.getId();
    id2 = ite2.getId();
    id3 = ite3.getId();
    id4 = ite4.getId();
    em.getTransaction().commit();
    // Revision 2
    em.getTransaction().begin();
    IntTestEntity ite5 = new IntTestEntity(3);
    em.persist(ite5);
    id5 = ite5.getId();
    ite1 = em.find(IntTestEntity.class, id1);
    ite1.setNumber(0);
    ite4 = em.find(IntTestEntity.class, id4);
    ite4.setNumber(15);
    em.getTransaction().commit();
}
Also used : EntityManager(javax.persistence.EntityManager) IntTestEntity(org.hibernate.envers.test.entities.IntTestEntity) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 85 with Priority

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

the class CustomPropertyAccess method initData.

@Test
@Priority(10)
public void initData() throws InterruptedException {
    timestamp1 = System.currentTimeMillis();
    Thread.sleep(100);
    // Revision 1
    EntityManager em = getEntityManager();
    em.getTransaction().begin();
    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);
    te.setStr("y");
    em.getTransaction().commit();
    timestamp3 = System.currentTimeMillis();
}
Also used : StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) 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