Hi Holly,

See my response below.

Cheers

Brian DePradine
Web Services Development
IBM Hursley
External  +44 (0) 1962 816319         Internal 246319

If you can't find the time to do it right the first time, where will you
find the time to do it again?


Holly Cummins/UK/IBM@IBMGB wrote on 05/03/2011 14:53:30:

> From:
>
> Holly Cummins/UK/IBM@IBMGB
>
> To:
>
> [email protected]
>
> Date:
>
> 05/03/2011 14:54
>
> Subject:
>
> Re: DataSource and XADataSource services and osgi.jndi.service.name
property
>
> Er, that should have read:
>
> ...
>
> "Unfortunately, once this has been done we have two services with the
same
>
> JNDI service name. Anything which uses the JNDI name
> osgi:service/jdbc/blogdb, expecting a *DataSource*, gets the following
> cast exception:"
>
> ...
>
> --
> Holly Cummins
> OSGi Applications
> Desk DE3B18, MP 211,
> IBM Hursley, UK
> [email protected]
> Phone: External +44 (0) 1962 815104 ; Internal 7-245104;
>
> Holly Cummins/UK/IBM@IBMGB wrote on 03/05/2011 02:43:56 PM:
>
> > Holly Cummins/UK/IBM@IBMGB
> > 03/05/2011 02:43 PM
> >
> > Please respond to
> > [email protected]
> >
> > To
> >
> > [email protected]
> >
> > cc
> >
> > Subject
> >
> > DataSource and XADataSource services and osgi.jndi.service.name
property
> >
> > Hi all,
> >
> > I'm working through a variant of the blog sample at the moment. In the
> > blog sample we use the service property osgi.jndi.service.name to
> uniquely
> > identify the datasource services. However, in the persistence.xml, we
> only
> > use the jndi service name as a filter property, like:
> >
> >
> > <jta-data-source>osgi:service/javax.sql.DataSource/
> > (osgi.jndi.service.name=jdbc/blogdb)</jta-data-source>
> >
> > instead of writing:
> >
> >     <jta-data-source>osgi:service/jdbc/blogdb</jta-data-source>
> >
> > It seems a shame to bother to specify the jndi.service.name property
but
>
> > then not take advantage of the shorter JNDI name, but there's a good
> > reason we don't - it doesn't work. :)
> >
> > The datasource blueprint.xml declares two services, for DataSource and
> > XADataSource, and then Aries helpfully auto-creates a third service,
> which
> > makes the EmbeddedXADataSource bean for lookups of the DataSource
> > interface.
> >
> > Unfortunately, once this has been done we have two services with the
> same
> > JNDI service name. Anything which uses the JNDI name
> > osgi:service/jdbc/blogdb, expecting an XADataSource, gets the following

> > cast exception:
> >
> > <openjpa-2.0.0-r422266:935683 nonfatal general error>
> > org.apache.openjpa.persistence.PersistenceException: $Proxy13
> incompatible
> > with javax.sql.DataSource
> >         at
> > org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker
> > (AbstractBrokerFactory.java:208)
> >         at
> > org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker
> > (DelegatingBrokerFactory.java:156)
> >         at
> >
>
org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager
> > (EntityManagerFactoryImpl.java:213)
> >         at
> >
>
org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager
> > (EntityManagerFactoryImpl.java:57)
> >         at
> >
>
org.apache.aries.jpa.container.impl.CountingEntityManagerFactory.createEntityManager

> > (CountingEntityManagerFactory.java:70)
> >         at
> >
>
org.apache.aries.jpa.container.context.transaction.impl.JTAPersistenceContextRegistry.getCurrentPersistenceContext

> > (JTAPersistenceContextRegistry.java:131)
> >
> > I have a few questions:
> >
> > 1. When we create the DataSource service from the XADataSource, should
> we
> > treat the osgi.jndi.service.name differently from the other properties?

> It
> > seems wrong for us to deliberately create a JNDI name clash.

The dataSource blueprint.xml file is meant to be the equivalent of the
configuration that you would provide to an application server when
configuring data sources, i.e. this is the way that the data source is
configured to use a particular jndi name. This name is then copied to the
data source that the application uses (see below).

> > 2. In my testing, I found that just registering the
EmbeddedXADataSource
>
> > as a javax.sql.DataSource service and not registering any services for
> the
> > XADataSource worked quite well. However, I assume there's a reason we
> > didn't write the sample this way. :) What's the service under the
> > XADataSource interface used for? The service isn't referenced in the
> blog
> > persistence.xml, so I'm assuming that the blog persistence unit never
> sees
> > it.

This may work fine for the blog sample, but if you have an application that
needs to participate in XA transactions then you need to provide an
XADataSource so that the transaction wrappers bundle can detect it and
create a DataSource capable of enlisting in XA transactions for the
application to use.

> >
> > (For those who don't have the code in front of them, the persistence
XML
>
> > only uses the DataSource services:
> >
> >
> > <jta-data-source>osgi:service/javax.sql.DataSource/
> > (osgi.jndi.service.name=jdbc/blogdb)</jta-data-source>
> >
> > <non-jta-data-source>osgi:service/javax.sql.DataSource/
> > (osgi.jndi.service.name=jdbc/blogdbnojta)</non-jta-data-source>
> >
> >
> > If I rewrite the dataSource.xml blueprint to remove the bit in the
> square
> > brackets,
> >
> >   <service id="xaDataSource" ref="derbyXADataSource"
> > interface="javax.sql.[XA]DataSource">
> >   <service-properties>
> >     <entry key="osgi.jndi.service.name" value="jdbc/blogdb"/>
> >    </service-properties>
> >   </service>
> >
> > I can rewrite the persistence.xml to
> >
> >     <jta-data-source>osgi:service/jdbc/blogdb)</jta-data-source>
> >
> <non-jta-data-source>osgi:service/jdbc/blogdbnojta)</non-jta-data-source>

> >
> >
> > without apparent ill effects, *and* the Aries container has to do less
> > work.  I assume I'm not hitting some important scenario in my test
> > coverage, but I'm not sure what it is.)
> >
> > Holly
> >
> > --
> > Holly Cummins
> > OSGi Applications
> > IBM Hursley, UK
> > [email protected]
> >
> >
> >
> >
> >
> >
> > Unless stated otherwise above:
> > IBM United Kingdom Limited - Registered in England and Wales with
number
>
> > 741598.
> > Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6
> 3AU
> >
> >
> >
> >
> >
>
>
>
>
>
>
> Unless stated otherwise above:
> IBM United Kingdom Limited - Registered in England and Wales with number
> 741598.
> Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6
3AU
>
>
>
>
>

Reply via email to