Cameron,
There are at least two ways to use JDBC from an OSGi application in
GlassFish;
a) Using our JDBC/OSGi bridge as described in section #9.3 of this doc
[1]. This is the preferred approach in GlassFish as you can leverage
connection pooling, transaction association feature of GlassFish JDBC
subsystem.
b) Using an OSGi compliant JDBC driver (rfc 122). If you have an OSGi
compliant driver, then you can just deploy it like any other OSGi
bundle. Since many JDBC drivers are not OSGi compliant, GlassFish also
has the ability to wrap a regular driver as an OSGi bundle. You have to
install such a driver with /jdbcdriver/ scheme. e.g., you can do:
install jdbcdriver:file:/tmp/foo.jar
When the wrapped bundle or osgi compliant bundle is started, GlassFish
will enlist it as a DataSourceFactory in the service registry. You can
use the same as a service.
I should probably document option #b in that doc as well. Currently
there are some issues about having the same driver both registered as an
OSGi bundle and installed in glassfish lib directory. So, avoid such a
configuration.
Thanks,
Sahoo
[1]
http://wikis.sun.com/download/attachments/209655166/GF-OSGi-Features-1.0.pdf
On Wednesday 08 June 2011 02:13 PM, Cameron Rochester wrote:
> Hi Sahoo,
>
> Is there a page outlining how to register and consume JDBC drivers
> using the rfc 122 functionality in Glassfish. I have done some looking
> around but can't seem to find any examples.
>
> I have looked at the source code for the osgi-jdbc and can probably
> figure it out from the code, but I thought there might be a write-up
> somewhere.
>
> I assume this will allow me to package up a jdbc driver bundle that
> can be distributed with my application. I can then get a JDBC
> connection from the DataSourceFactory that is registered in the OSGi
> registry?
>
> Cheers
> Cameron