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());
}
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();
}
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();
}
}
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());
}
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());
}
Aggregations