HHH-8528 correct docs and quickstarts to support stopping/restarting a

client bundle

Conflicts:
	documentation/src/main/docbook/devguide/en-US/chapters/osgi/OSGi.xml
	documentation/src/main/docbook/quickstart/tutorials/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/DataPointServiceImpl.java
This commit is contained in:
Brett Meyer 2013-10-28 14:34:15 -04:00
parent cd55718f71
commit 70b9644ca4
5 changed files with 21 additions and 25 deletions

View File

@ -383,14 +383,6 @@
tutorials' <literal>features.xml</literal> for example sequences.
</para>
</listitem>
<listitem>
<para>
The environment should be considered STATIC. Hibernate currently does not support the ability
to dynamically add and remove client bundles during runtime. Doing so is typically
catastrophic. We hope to better support at least partially-dynamic environments in
Hibernate 5.
</para>
</listitem>
</itemizedlist>
</section>

View File

@ -30,9 +30,11 @@ import org.hibernate.osgitest.entity.DataPoint;
* @author Brett Meyer
*/
public class DataPointServiceImpl implements DataPointService {
private HibernateUtil hibernateUtil = new HibernateUtil();
public void add(DataPoint dp) {
EntityManager em = HibernateUtil.getEntityManager();
EntityManager em = hibernateUtil.getEntityManager();
em.getTransaction().begin();
em.persist( dp );
em.getTransaction().commit();
@ -40,7 +42,7 @@ public class DataPointServiceImpl implements DataPointService {
}
public void update(DataPoint dp) {
EntityManager em = HibernateUtil.getEntityManager();
EntityManager em = hibernateUtil.getEntityManager();
em.getTransaction().begin();
em.merge( dp );
em.getTransaction().commit();
@ -48,7 +50,7 @@ public class DataPointServiceImpl implements DataPointService {
}
public DataPoint get(long id) {
EntityManager em = HibernateUtil.getEntityManager();
EntityManager em = hibernateUtil.getEntityManager();
em.getTransaction().begin();
DataPoint dp = (DataPoint) em.createQuery( "from DataPoint dp where dp.id=" + id ).getSingleResult();
em.getTransaction().commit();
@ -57,7 +59,7 @@ public class DataPointServiceImpl implements DataPointService {
}
public List<DataPoint> getAll() {
EntityManager em = HibernateUtil.getEntityManager();
EntityManager em = hibernateUtil.getEntityManager();
em.getTransaction().begin();
List list = em.createQuery( "from DataPoint" ).getResultList();
em.getTransaction().commit();
@ -66,7 +68,7 @@ public class DataPointServiceImpl implements DataPointService {
}
public void deleteAll() {
EntityManager em = HibernateUtil.getEntityManager();
EntityManager em = hibernateUtil.getEntityManager();
em.getTransaction().begin();
em.createQuery( "delete from DataPoint" ).executeUpdate();
em.getTransaction().commit();

View File

@ -35,13 +35,13 @@ import org.osgi.framework.ServiceReference;
public class HibernateUtil {
private static EntityManagerFactory emf;
private EntityManagerFactory emf;
public static EntityManager getEntityManager() {
public EntityManager getEntityManager() {
return getEntityManagerFactory().createEntityManager();
}
private static EntityManagerFactory getEntityManagerFactory() {
private EntityManagerFactory getEntityManagerFactory() {
if ( emf == null ) {
Bundle thisBundle = FrameworkUtil.getBundle( HibernateUtil.class );
// Could get this by wiring up OsgiTestBundleActivator as well.

View File

@ -31,9 +31,11 @@ import org.hibernate.osgitest.entity.DataPoint;
* @author Brett Meyer
*/
public class DataPointServiceImpl implements DataPointService {
private HibernateUtil hibernateUtil = new HibernateUtil();
public void add(DataPoint dp) {
Session s = HibernateUtil.getSession();
Session s = hibernateUtil.getSession();
s.getTransaction().begin();
s.persist( dp );
s.getTransaction().commit();
@ -41,7 +43,7 @@ public class DataPointServiceImpl implements DataPointService {
}
public void update(DataPoint dp) {
Session s = HibernateUtil.getSession();
Session s = hibernateUtil.getSession();
s.getTransaction().begin();
s.update( dp );
s.getTransaction().commit();
@ -49,7 +51,7 @@ public class DataPointServiceImpl implements DataPointService {
}
public DataPoint get(long id) {
Session s = HibernateUtil.getSession();
Session s = hibernateUtil.getSession();
s.getTransaction().begin();
DataPoint dp = (DataPoint) s.createCriteria( DataPoint.class ).add(
Restrictions.eq( "id", id ) ).uniqueResult();
@ -60,7 +62,7 @@ public class DataPointServiceImpl implements DataPointService {
// Test lazy loading (mainly to make sure the proxy classes work in OSGi)
public DataPoint load(long id) {
Session s = HibernateUtil.getSession();
Session s = hibernateUtil.getSession();
s.getTransaction().begin();
DataPoint dp = (DataPoint) s.load( DataPoint.class, new Long(id) );
// initialize
@ -71,7 +73,7 @@ public class DataPointServiceImpl implements DataPointService {
}
public List<DataPoint> getAll() {
Session s = HibernateUtil.getSession();
Session s = hibernateUtil.getSession();
s.getTransaction().begin();
List list = s.createQuery( "from DataPoint" ).list();
s.getTransaction().commit();
@ -80,7 +82,7 @@ public class DataPointServiceImpl implements DataPointService {
}
public void deleteAll() {
Session s = HibernateUtil.getSession();
Session s = hibernateUtil.getSession();
s.getTransaction().begin();
s.createQuery( "delete from DataPoint" ).executeUpdate();
s.getTransaction().commit();

View File

@ -33,13 +33,13 @@ import org.osgi.framework.ServiceReference;
public class HibernateUtil {
private static SessionFactory sf;
private SessionFactory sf;
public static Session getSession() {
public Session getSession() {
return getSessionFactory().openSession();
}
private static SessionFactory getSessionFactory() {
private SessionFactory getSessionFactory() {
if ( sf == null ) {
Bundle thisBundle = FrameworkUtil.getBundle( HibernateUtil.class );
// Could get this by wiring up OsgiTestBundleActivator as well.