use of org.hibernate.osgi.test.client.AuditedDataPoint in project hibernate-orm by hibernate.
the class OsgiIntegrationTest method testNativeEnvers.
@Test
public void testNativeEnvers() throws Exception {
final ServiceReference sr = bundleContext.getServiceReference(SessionFactory.class.getName());
final SessionFactory sf = (SessionFactory) bundleContext.getService(sr);
final Integer adpId;
Session s = sf.openSession();
s.getTransaction().begin();
AuditedDataPoint adp = new AuditedDataPoint("Chris");
s.persist(adp);
s.getTransaction().commit();
adpId = adp.getId();
s.close();
s = sf.openSession();
s.getTransaction().begin();
adp = s.get(AuditedDataPoint.class, adpId);
adp.setName("Chris2");
s.getTransaction().commit();
s.close();
s = sf.openSession();
AuditReader ar = AuditReaderFactory.get(s);
assertEquals(2, ar.getRevisions(AuditedDataPoint.class, adpId).size());
AuditedDataPoint rev1 = ar.find(AuditedDataPoint.class, adpId, 1);
AuditedDataPoint rev2 = ar.find(AuditedDataPoint.class, adpId, 2);
assertEquals(new AuditedDataPoint(adpId, "Chris"), rev1);
assertEquals(new AuditedDataPoint(adpId, "Chris2"), rev2);
s.close();
}
use of org.hibernate.osgi.test.client.AuditedDataPoint in project hibernate-orm by hibernate.
the class OsgiIntegrationTest method testJpaEnvers.
@Test
public void testJpaEnvers() throws Exception {
final ServiceReference serviceReference = bundleContext.getServiceReference(PersistenceProvider.class.getName());
final PersistenceProvider persistenceProvider = (PersistenceProvider) bundleContext.getService(serviceReference);
final EntityManagerFactory emf = persistenceProvider.createEntityManagerFactory("hibernate-osgi-test", null);
final Integer adpId;
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
AuditedDataPoint adp = new AuditedDataPoint("Chris");
em.persist(adp);
em.getTransaction().commit();
adpId = adp.getId();
em.close();
em = emf.createEntityManager();
em.getTransaction().begin();
adp = em.find(AuditedDataPoint.class, adpId);
adp.setName("Chris2");
em.getTransaction().commit();
em.close();
em = emf.createEntityManager();
AuditReader ar = AuditReaderFactory.get(em);
assertEquals(2, ar.getRevisions(AuditedDataPoint.class, adpId).size());
AuditedDataPoint rev1 = ar.find(AuditedDataPoint.class, adpId, 1);
AuditedDataPoint rev2 = ar.find(AuditedDataPoint.class, adpId, 2);
assertEquals(new AuditedDataPoint(adpId, "Chris"), rev1);
assertEquals(new AuditedDataPoint(adpId, "Chris2"), rev2);
em.close();
}
Aggregations