Search in sources :

Example 26 with StrTestEntity

use of org.hibernate.envers.test.entities.StrTestEntity 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 27 with StrTestEntity

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

the class CustomNoListener method testHistoryOfId1.

@Test
public void testHistoryOfId1() {
    StrTestEntity ver1 = new StrTestEntity("x", id);
    StrTestEntity ver2 = new StrTestEntity("y", id);
    StrTestEntity ver3 = new StrTestEntity("z", id);
    assert getAuditReader().find(StrTestEntity.class, id, 1).equals(ver1);
    assert getAuditReader().find(StrTestEntity.class, id, 2).equals(ver2);
    assert getAuditReader().find(StrTestEntity.class, id, 3).equals(ver2);
    assert getAuditReader().find(StrTestEntity.class, id, 4).equals(ver3);
}
Also used : StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) Test(org.junit.Test)

Example 28 with StrTestEntity

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

the class CustomPropertyAccess method testHistoryOfId1.

@Test
public void testHistoryOfId1() {
    StrTestEntity ver1 = new StrTestEntity("x", id);
    StrTestEntity ver2 = new StrTestEntity("y", id);
    assert getAuditReader().find(StrTestEntity.class, id, 1).equals(ver1);
    assert getAuditReader().find(StrTestEntity.class, id, 2).equals(ver2);
}
Also used : StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) Test(org.junit.Test)

Example 29 with StrTestEntity

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

the class DefaultTrackingEntitiesTest method testTrackDeletedEntities.

@Test
public void testTrackDeletedEntities() {
    StrTestEntity ste = new StrTestEntity(null, steId);
    StrIntTestEntity site = new StrIntTestEntity(null, null, siteId);
    assert TestTools.checkCollection(getCrossTypeRevisionChangesReader().findEntities(3), site, ste);
}
Also used : StrIntTestEntity(org.hibernate.envers.test.entities.StrIntTestEntity) StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) Test(org.junit.Test)

Example 30 with StrTestEntity

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

the class DefaultTrackingEntitiesTest method testTrackDeletedEntitiesGroupByRevisionType.

@Test
public void testTrackDeletedEntitiesGroupByRevisionType() {
    StrTestEntity ste = new StrTestEntity(null, steId);
    StrIntTestEntity site = new StrIntTestEntity(null, null, siteId);
    Map<RevisionType, List<Object>> result = getCrossTypeRevisionChangesReader().findEntitiesGroupByRevisionType(3);
    assert TestTools.checkCollection(result.get(RevisionType.ADD));
    assert TestTools.checkCollection(result.get(RevisionType.MOD));
    assert TestTools.checkCollection(result.get(RevisionType.DEL), site, ste);
}
Also used : StrIntTestEntity(org.hibernate.envers.test.entities.StrIntTestEntity) StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) RevisionType(org.hibernate.envers.RevisionType) List(java.util.List) Test(org.junit.Test)

Aggregations

StrTestEntity (org.hibernate.envers.test.entities.StrTestEntity)102 Test (org.junit.Test)98 EntityManager (javax.persistence.EntityManager)50 Priority (org.hibernate.envers.test.Priority)48 Session (org.hibernate.Session)8 StrIntTestEntity (org.hibernate.envers.test.entities.StrIntTestEntity)8 ListRefCollEntity (org.hibernate.envers.test.entities.onetomany.detached.ListRefCollEntity)4 SetRefCollEntity (org.hibernate.envers.test.entities.onetomany.detached.SetRefCollEntity)4 TestForIssue (org.hibernate.testing.TestForIssue)4 ManyToOneComponent (org.hibernate.envers.test.entities.components.relations.ManyToOneComponent)3 ManyToOneComponentTestEntity (org.hibernate.envers.test.entities.components.relations.ManyToOneComponentTestEntity)3 OneToManyComponent (org.hibernate.envers.test.entities.components.relations.OneToManyComponent)3 OneToManyComponentTestEntity (org.hibernate.envers.test.entities.components.relations.OneToManyComponentTestEntity)3 SortedSetEntity (org.hibernate.envers.test.entities.manytomany.SortedSetEntity)3 ListUniEntity (org.hibernate.envers.test.entities.manytomany.unidirectional.ListUniEntity)3 SetUniEntity (org.hibernate.envers.test.entities.manytomany.unidirectional.SetUniEntity)3 List (java.util.List)2 RevisionType (org.hibernate.envers.RevisionType)2 JoinTableEntity (org.hibernate.envers.test.entities.manytomany.unidirectional.JoinTableEntity)2 MapUniEntity (org.hibernate.envers.test.entities.manytomany.unidirectional.MapUniEntity)2