I think having a
Import-Service: javax.sql.DataSource
in the Manifest. The maven bundle plugin should do this.

So blueprint will make sure the service is there.

Christian

 Am 19.04.2012 17:34, schrieb Brunner Basil:
Hi

I have two OSGi bundles The first one contains only a Blueprint data source 
definition:

====================
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0";>

   <bean id="dataSource" class="org.h2.jdbcx.JdbcDataSource">
     <property name="URL" value="jdbc:h2:db/database" />
   </bean>

   <service interface="javax.sql.DataSource" ref="dataSource">
     <service-properties>
       <entry key="osgi.jndi.service.name" value="jdbc/database" />
     </service-properties>
   </service>

</blueprint>
====================

The second bundle contains a JPA persistence file and a blueprint file:

====================
<persistence xmlns="http://java.sun.com/xml/ns/persistence";
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; version="1.0">

   <persistence-unit name="CaptureAgentCore" transaction-type="JTA">
     <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
     
<jta-data-source>osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=jdbc/database)</jta-data-source>
     <class>ch.entwine.captureagent.scheduler.RecordingEvent</class>
     <class>ch.entwine.captureagent.config.ConfigOption</class>
     <class>ch.entwine.captureagent.felix.configadmin.ConfigurationData</class>
     <exclude-unlisted-classes>true</exclude-unlisted-classes>
   </persistence-unit>

</persistence>

<blueprint default-activation="eager"
   xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
   xmlns:jpa="http://aries.apache.org/xmlns/jpa/v1.0.0"; 
xmlns:tx="http://aries.apache.org/xmlns/transactions/v1.0.0";>

   <bean id="SchedulerService" 
class="ch.entwine.captureagent.scheduler.Scheduler">
     <jpa:context property="entityManager" unitname="CaptureAgentCore" />
     <tx:transaction method="*" value="Required" />
   </bean>

   <service ref="SchedulerService" interface="ch.entwine.captureagent.scheduler.Scheduler" 
depends-on="dataSource" />
</blueprint>
====================

I ran into the problem that the data source is not yet registered when the JPA 
entity manager tries to get a reference to it. Error message:

2012-04-19 16:17:38 ERROR (DelayedLookupDataSource:57) No JTA datasource could 
be located using the JNDI name 
osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=jdbc/database)
javax.naming.NameNotFoundException: 
osgi:service/javax.sql.DataSource/"(osgi.jndi.service.name=jdbc/database)"

I've now tried to set the 'depends-on' attribute on the SchedulerService 
definition in the blueprint file of bundle two (see above). Unfortunately I get 
the following error now:

17:19:09 ERROR (BlueprintContainerImpl:348) Unable to start blueprint container 
for bundle ch.entwine.matterhorn.core
org.osgi.service.blueprint.container.ComponentDefinitionException: Unresolved 
ref/idref to component: dataSource

So, my question is how I can make sure the data source gets registered before 
the JPA entity manager gets started?


Thanks for your help!


--
Christian Schneider
http://www.liquid-reality.de

Open Source Architect
Talend Application Integration Division http://www.talend.com

Reply via email to