2

On my karaf 4.0.8 I've installed the feature pax-jdbc-postgresql. The DataFactory for PostgreSQL is installed:

org.osgi.service.jdbc.DataSourceFactory]
osgi.jdbc.driver.class  org.postgresql.Driver
osgi.jdbc.driver.name   PostgreSQL JDBC Driver
osgi.jdbc.driver.version    PostgreSQL 9.4 JDBC4.1 (build 1203)
service.bundleid    204
service.scope   singleton
Using Bundles   com.eclipsesource.jaxrs.publisher (184)

I've create the file etc/org.ops4j.datasource-psql-sandbox.cfg:

osgi.jdbc.driver.class=org.postgresql.Driver
osgi.jdbc.driver.name=PostgreSQL
url=jdbc:postgresql://localhost:5432/sandbox
dataSourceName=psql-sandbox
user=sandbox
password=sandbox

After that, I see the confirmation in karaf.log that the file was processed:

2017-02-10 14:54:17,468 | INFO | 41-88b277ae0921) | DataSourceRegistration | 154 - org.ops4j.pax.jdbc.config - 0.9.0 | Detected config for DataSource psql-sandbox. Tracking DSF with filter (&(objectClass=org.osgi.service.jdbc.DataSourceFactory)(osgi.jdbc.driver.class=org.postgresql.Driver)(osgi.jdbc.driver.name=PostgreSQL))

However, I see no new DataSource in services list in console. What went wrong? I see no exceptions in log ....

Cœur
  • 37,241
  • 25
  • 195
  • 267
9ilsdx 9rvj 0lo
  • 7,955
  • 10
  • 38
  • 77

1 Answers1

3

The log message tell you that the config was processed and it is now searching for a suitable DataSourceFactory OSGi service.

The problem in your case is that it does not find such a service. So to debug this you should list all DataSourceFactory services and check their properties.

service:list DataSourceFactory

In my case it shows this:

[org.osgi.service.jdbc.DataSourceFactory]
-----------------------------------------
osgi.jdbc.driver.class = org.postgresql.Driver
osgi.jdbc.driver.name = PostgreSQL JDBC Driver
...

As you see it does not match the filter you see in the log. Generally you should only provide either osgi.jdbc.driver.class or osgi.jdbc.driver.name not both. If you remove the osgi.jdbc.driver.name line the config will work.

There is no error message as the system can not know if the error is transient or not. Basically as soon as you install a matching OSGi service the DataSource will be created.

Christian Schneider
  • 19,420
  • 2
  • 39
  • 64
  • So, the driver name should be verbosely "PostgreSQL JDBC Driver"? For feture "sqlite" it's "sqlite", for "mysql" it's "mysl", so for "postgresql" I've expected "postgresql" or at least something to be easy to find out ... – 9ilsdx 9rvj 0lo Feb 10 '17 at 14:29
  • The name can be freely chosen by whoever exports the DataSourceFactory. So the safe way is to simply list the DataSourceDactory services and check what they actually use. – Christian Schneider Feb 10 '17 at 15:10
  • No chance to force DataSourceFactory exporters to keep any predictable convention? – 9ilsdx 9rvj 0lo Feb 10 '17 at 15:16
  • Unfortunately not .. and even worse in some cases the naming changed between versions of the same database. – Christian Schneider Feb 10 '17 at 15:36
  • That drove me mad for a moment when debugging a client site. Version 1.0.0 fixes this correct? – Namphibian May 30 '17 at 23:23
  • Version 1.x makes it easier to debug when you use a wrong name. So it should be easier to spot in the log. Of course it can not influence how the original DataSourceFactory is announced. – Christian Schneider May 31 '17 at 05:11