Search in sources :

Example 91 with StrTestEntity

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

the class BasicDetachedSet method testHistoryOfColl1.

@Test
public void testHistoryOfColl1() {
    StrTestEntity str1 = getEntityManager().find(StrTestEntity.class, str1_id);
    StrTestEntity str2 = getEntityManager().find(StrTestEntity.class, str2_id);
    SetRefCollEntity rev1 = getAuditReader().find(SetRefCollEntity.class, coll1_id, 1);
    SetRefCollEntity rev2 = getAuditReader().find(SetRefCollEntity.class, coll1_id, 2);
    SetRefCollEntity rev3 = getAuditReader().find(SetRefCollEntity.class, coll1_id, 3);
    SetRefCollEntity rev4 = getAuditReader().find(SetRefCollEntity.class, coll1_id, 4);
    assert rev1.getCollection().equals(TestTools.makeSet(str1));
    assert rev2.getCollection().equals(TestTools.makeSet(str1, str2));
    assert rev3.getCollection().equals(TestTools.makeSet(str2));
    assert rev4.getCollection().equals(TestTools.makeSet());
    assert "coll1".equals(rev1.getData());
    assert "coll1".equals(rev2.getData());
    assert "coll1".equals(rev3.getData());
    assert "coll1".equals(rev4.getData());
}
Also used : SetRefCollEntity(org.hibernate.envers.test.entities.onetomany.detached.SetRefCollEntity) StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) Test(org.junit.Test)

Example 92 with StrTestEntity

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

the class InsertsOneTransactionPerformance method doTest.

protected void doTest() {
    EntityManager entityManager = getEntityManager();
    entityManager.getTransaction().begin();
    start();
    for (int i = 0; i < NUMBER_INSERTS; i++) {
        entityManager.persist(new StrTestEntity("x" + i));
    }
    entityManager.getTransaction().commit();
    stop();
}
Also used : StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) EntityManager(javax.persistence.EntityManager)

Example 93 with StrTestEntity

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

the class UpdatesPerformance method doTest.

protected void doTest() {
    setup();
    for (int i = 0; i < NUMBER_UPDATES; i++) {
        newEntityManager();
        EntityManager entityManager = getEntityManager();
        entityManager.getTransaction().begin();
        Integer id = ids.get(random.nextInt(NUMBER_ENTITIES));
        start();
        StrTestEntity testEntity = entityManager.find(StrTestEntity.class, id);
        testEntity.setStr("z" + i);
        entityManager.getTransaction().commit();
        stop();
    }
}
Also used : StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) EntityManager(javax.persistence.EntityManager)

Example 94 with StrTestEntity

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

the class RegisterUserEventListenersTest method testTransactionProcessSynchronization.

@Test
@TestForIssue(jiraKey = "HHH-7478")
public void testTransactionProcessSynchronization() {
    final EventListenerRegistry registry = sessionFactory().getServiceRegistry().getService(EventListenerRegistry.class);
    final CountingPostInsertTransactionBoundaryListener listener = new CountingPostInsertTransactionBoundaryListener();
    registry.getEventListenerGroup(EventType.POST_INSERT).appendListener(listener);
    Session session = openSession();
    session.getTransaction().begin();
    StrTestEntity entity = new StrTestEntity("str1");
    session.save(entity);
    session.getTransaction().commit();
    session.close();
    // Post insert listener invoked three times - before/after insertion of original data,
    // revision entity and audit row.
    Assert.assertEquals(3, listener.getBeforeCount());
    Assert.assertEquals(3, listener.getAfterCount());
}
Also used : StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) EventListenerRegistry(org.hibernate.event.service.spi.EventListenerRegistry) Session(org.hibernate.Session) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 95 with StrTestEntity

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

the class CommitFlushSingleRevisionInTransaction method testSingleRevisionInTransaction.

@Test
@TestForIssue(jiraKey = "HHH-11575")
public void testSingleRevisionInTransaction() {
    EntityManager em = getEntityManager();
    em.getTransaction().begin();
    SequenceIdRevisionEntity revisionBeforeFlush = getAuditReader().getCurrentRevision(SequenceIdRevisionEntity.class, true);
    int revisionNumberBeforeFlush = revisionBeforeFlush.getId();
    em.flush();
    StrTestEntity entity = new StrTestEntity("entity");
    em.persist(entity);
    em.getTransaction().commit();
    SequenceIdRevisionEntity entity2Revision = (SequenceIdRevisionEntity) ((Object[]) getAuditReader().createQuery().forRevisionsOfEntity(StrTestEntity.class, false, false).add(AuditEntity.id().eq(entity.getId())).getSingleResult())[1];
    assertEquals("The revision number obtained before the flush and the persisting of the entity should be the same as the revision number of the entity because there should only be one revision number per transaction", revisionNumberBeforeFlush, entity2Revision.getId());
}
Also used : StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) EntityManager(javax.persistence.EntityManager) SequenceIdRevisionEntity(org.hibernate.envers.enhanced.SequenceIdRevisionEntity) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Aggregations

StrTestEntity (org.hibernate.envers.test.entities.StrTestEntity)103 Test (org.junit.Test)99 EntityManager (javax.persistence.EntityManager)51 Priority (org.hibernate.envers.test.Priority)48 Session (org.hibernate.Session)8 StrIntTestEntity (org.hibernate.envers.test.entities.StrIntTestEntity)8 TestForIssue (org.hibernate.testing.TestForIssue)5 ListRefCollEntity (org.hibernate.envers.test.entities.onetomany.detached.ListRefCollEntity)4 SetRefCollEntity (org.hibernate.envers.test.entities.onetomany.detached.SetRefCollEntity)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