File tree Expand file tree Collapse file tree 7 files changed +193
-126
lines changed
asciidoc/quickstart/guides
docbook/userGuide/en-US/chapters/osgi Expand file tree Collapse file tree 7 files changed +193
-126
lines changed Original file line number Diff line number Diff line change @@ -14,5 +14,3 @@ include::tutorial_annotations.adoc[]
14
14
include::tutorial_jpa.adoc[]
15
15
16
16
include::tutorial_envers.adoc[]
17
-
18
- include::tutorial_osgi.adoc[]
Load Diff This file was deleted.
Load Diff Large diffs are not rendered by default.
Original file line number Diff line number Diff line change
1
+ public class HibernateUtil {
2
+
3
+ private SessionFactory sf ;
4
+
5
+ public Session getSession () {
6
+ return getSessionFactory ().openSession ();
7
+ }
8
+
9
+ private SessionFactory getSessionFactory () {
10
+ if ( sf == null ) {
11
+ Bundle thisBundle = FrameworkUtil .getBundle ( HibernateUtil .class );
12
+ BundleContext context = thisBundle .getBundleContext ();
13
+
14
+ ServiceReference sr = context .getServiceReference ( SessionFactory .class .getName () );
15
+ sf = (SessionFactory ) context .getService ( sr );
16
+ }
17
+ return sf ;
18
+ }
19
+ }
Original file line number Diff line number Diff line change
1
+ public class HibernateUtil {
2
+
3
+ private EntityManagerFactory emf ;
4
+
5
+ public EntityManager getEntityManager () {
6
+ return getEntityManagerFactory ().createEntityManager ();
7
+ }
8
+
9
+ private EntityManagerFactory getEntityManagerFactory () {
10
+ if ( emf == null ) {
11
+ Bundle thisBundle = FrameworkUtil .getBundle ( HibernateUtil .class );
12
+ BundleContext context = thisBundle .getBundleContext ();
13
+
14
+ ServiceReference serviceReference = context .getServiceReference ( PersistenceProvider .class .getName () );
15
+ PersistenceProvider persistenceProvider = (PersistenceProvider ) context .getService ( serviceReference );
16
+
17
+ emf = persistenceProvider .createEntityManagerFactory ( "YourPersistenceUnitName" , null );
18
+ }
19
+ return emf ;
20
+ }
21
+ }
Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2
+ <blueprint default-activation =" eager"
3
+ xmlns =" http://www.osgi.org/xmlns/blueprint/v1.0.0"
4
+ xmlns : jpa =" http://aries.apache.org/xmlns/jpa/v1.0.0"
5
+ xmlns : tx =" http://aries.apache.org/xmlns/transactions/v1.0.0" >
6
+
7
+ <!-- This gets the container-managed EntityManager and injects it into the DataPointServiceImpl bean.
8
+ Assumes DataPointServiceImpl has an "entityManager" field with a getter and setter. -->
9
+ <bean id =" dpService" class =" org.hibernate.osgitest.DataPointServiceImpl" >
10
+ <jpa : context unitname =" managed-jpa" property =" entityManager" />
11
+ <tx : transaction method =" *" value =" Required" />
12
+ </bean >
13
+ <service ref =" dpService" interface =" org.hibernate.osgitest.DataPointService" />
14
+ </blueprint >
Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2
+ <!--
3
+ First install the H2 driver using:
4
+ > install -s mvn:com.h2database/h2/1.3.163
5
+
6
+ Then copy this file to the deploy folder
7
+ -->
8
+ <blueprint xmlns =" http://www.osgi.org/xmlns/blueprint/v1.0.0" >
9
+
10
+ <bean id =" dataSource" class =" org.h2.jdbcx.JdbcDataSource" >
11
+ <property name =" URL" value =" jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE" />
12
+ <property name =" user" value =" sa" />
13
+ <property name =" password" value =" " />
14
+ </bean >
15
+
16
+ <service interface =" javax.sql.DataSource" ref =" dataSource" >
17
+ <service-properties >
18
+ <entry key =" osgi.jndi.service.name" value =" jdbc/h2ds" />
19
+ </service-properties >
20
+ </service >
21
+ </blueprint >
You can’t perform that action at this time.
0 commit comments