Search in sources :

Example 1 with AuditedDataPoint

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();
}
Also used : SessionFactory(org.hibernate.SessionFactory) AuditedDataPoint(org.hibernate.osgi.test.client.AuditedDataPoint) AuditReader(org.hibernate.envers.AuditReader) ServiceReference(org.osgi.framework.ServiceReference) Session(org.hibernate.Session) Test(org.junit.Test)

Example 2 with AuditedDataPoint

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();
}
Also used : EntityManager(javax.persistence.EntityManager) AuditedDataPoint(org.hibernate.osgi.test.client.AuditedDataPoint) PersistenceProvider(javax.persistence.spi.PersistenceProvider) EntityManagerFactory(javax.persistence.EntityManagerFactory) AuditReader(org.hibernate.envers.AuditReader) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Aggregations

AuditReader (org.hibernate.envers.AuditReader)2 AuditedDataPoint (org.hibernate.osgi.test.client.AuditedDataPoint)2 Test (org.junit.Test)2 ServiceReference (org.osgi.framework.ServiceReference)2 EntityManager (javax.persistence.EntityManager)1 EntityManagerFactory (javax.persistence.EntityManagerFactory)1 PersistenceProvider (javax.persistence.spi.PersistenceProvider)1 Session (org.hibernate.Session)1 SessionFactory (org.hibernate.SessionFactory)1