Hi Harald, Thanks for your reply. What I understood so far is: I have to create a service that provides the datasource. But, what if the datasource has to be configured by someone else? Not me, for e.g. if I want to "sell" an application based on OSGI, the datasource must be configured by the buyer's admin, not me. That's why I came up with tomcat (I know it's not an OSGI web container). With tomcat the admin can declare a jdbc datasource which can be accessed via JNDI in the webapp. My question is, is it possible to do something similar with OSGI? The datasource must be configurable.
Is creating i.e. a database.properties file which is read by my OSGI service the only way to achieve this goal? I hope I could explain what my current problem is. Thanks again for your help! Daniel Am 29.06.2011 um 00:34 schrieb Harald Wellmann: > Hi Daniel, > > there's a tutorial for setting up Aries + OpenJPA + JNDI + Datasource I wrote > last autumn: > > http://hwellmann.blogspot.com/2010/09/openjpa-and-osgi.html > > The version numbers are out of date by now, but if you know the basics about > JPA in classic web containers like Tomcat, this post may help you to > understand some of the differences when using JPA with OSGi and Aries. > > Am 28.06.2011 16:40, schrieb Daniel Plappert: >> I am new to OSGI and currently trying to understand its mechanism. I >> want to create a service (bundle), which creates a JDNI datasource >> and provides this datasource to other services. What I've read so far >> is, OSGI "itself" (felix/equinox) can't use JNDI, but aries can. >> That's why I am asking. >> > > OSGi Core doesn't know about JNDI. The OSGi Enterprise Spec defines an OSGi > JNDI service, and Aries provides an implementation. > > >> What I am trying to do is to provide a flexible service, let's say a >> JDNIDatasourceService. This service creates a JNDI datasource, which >> connection parameters can be configured "from the outside". > > JNDI datasource? You mean a JDBC datasource registered in a JNDI naming > context... > > > I don't >> what to deploy the bundle with a persistence.xml, in which the >> username, password and so on are hard coded. What I want is the same >> possible mechanism like i.e. a tomcat server provides. It is possible >> to declare a JNDI datasource with tomcat so that all my webapps can >> access this datasource. > > Forget about Tomcat for a moment - Tomcat is not an OSGi web container. > > You can write a tiny bundle that creates a datasource (in plain old Java > code) and then registers this datasource as an OSGi service. > > Aries JNDI assigns a JNDI name to all OSGi services, so your persistence > bundle can simply access the datasource by a JNDI name like > osgi:service/javax.sql.DataSource, without depending on any driver and > connection details. > > Some more pointers: > > Simple sample with OSGi + Derby + OpenJPA + Aries JNDI + Aries JPA: > http://code.google.com/p/osgi-enterprise/source/browse/#hg%2Fjpa > > Aries Blog Sample > http://aries.apache.org/modules/samples/blog-sample.html > > Aries JNDI: > http://aries.apache.org/modules/jndiproject.html > > Hope that helps, > Harald >
