Skip to content

Commit 3bd3f54

Browse files
committed
HHH-9919 Re-write hibernate-osgi user guide based on published features.xml and ORM 5.0
1 parent a8a367b commit 3bd3f54

File tree

7 files changed

+193
-126
lines changed

7 files changed

+193
-126
lines changed

documentation/src/main/asciidoc/quickstart/guides/index.adoc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,3 @@ include::tutorial_annotations.adoc[]
1414
include::tutorial_jpa.adoc[]
1515

1616
include::tutorial_envers.adoc[]
17-
18-
include::tutorial_osgi.adoc[]

documentation/src/main/asciidoc/quickstart/guides/tutorial_osgi.adoc

Lines changed: 0 additions & 17 deletions
This file was deleted.

documentation/src/main/docbook/userGuide/en-US/chapters/osgi/OSGi.xml

Lines changed: 118 additions & 107 deletions
Large diffs are not rendered by default.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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>

0 commit comments

Comments
 (0)