cschneider / Karaf-Tutorial

http://cschneider.github.io/Karaf-Tutorial/
Apache License 2.0
271 stars 305 forks source link

Installing a pooled datasource does not work - now solved! #48

Closed jlolling closed 6 years ago

jlolling commented 6 years ago

I am not able to install a pooled DataSourceFactory. My steps: I have installed a fresh apache-karaf-4.1.0 Then I have started the container - works fine Then I have installed the features:

karaf@root()>   feature:install transaction jndi pax-jdbc-postgresql pax-jdbc-config pax-jdbc-pool-dbcp2
karaf@root()>   feature:list|grep DataSource (output filtered to the started relevant features)
pax-jdbc-postgresql           │ 1.1.0            │ x        │ Started     │ org.ops4j.pax.jdbc-1.1.0          │ Provides JDBC PostgreSQL DataSourceFactory
pax-jdbc-pool-dbcp2           │ 1.1.0            │ x        │ Started     │ org.ops4j.pax.jdbc-1.1.0          │ Provides JDBC Pooling DataSourceFactory
karaf@root()>   feature:list|grep jdbc
pax-jdbc-spec                 │ 1.1.0            │ x        │ Started     │ org.ops4j.pax.jdbc-1.1.0          │ Provides OSGi JDBC Service spec
pax-jdbc                      │ 1.1.0            │ x        │ Started     │ org.ops4j.pax.jdbc-1.1.0          │ Provides JDBC Service support
pax-jdbc-config               │ 1.1.0            │ x        │ Started     │ org.ops4j.pax.jdbc-1.1.0          │ Provides JDBC Config support
pax-jdbc-postgresql           │ 1.1.0            │ x        │ Started     │ org.ops4j.pax.jdbc-1.1.0          │ Provides JDBC PostgreSQL DataSourceFactory
pax-jdbc-pool-dbcp2           │ 1.1.0            │ x        │ Started     │ org.ops4j.pax.jdbc-1.1.0          │ Provides JDBC Pooling DataSourceFactory
karaf@root()>  service:list DataSourceFactory                                                                                                           [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.1212.jre7
 service.bundleid = 78
 service.id = 132
 service.scope = singleton
Provided by : 
 PostgreSQL JDBC Driver JDBC41 (78)

Unfortunately there is no database pool at all! I am very under pressure to solve this. It would be great to have a fixed documentation.

cschneider commented 6 years ago

Pax-jdbc works differently since 1.0.0. See https://ops4j1.jira.com/wiki/spaces/PAXJDBC/pages/119078914/Pooling+and+XA+support+in+1.0.0

Karaf 4.1.0 refers to the new pax-jdbc by default so you run into this problem. I just updating the Tutorial 6 (jdbc) to match the new pax-jdbc version.

cschneider commented 6 years ago

See: http://cschneider.github.io/Karaf-Tutorial/06/

jlolling commented 6 years ago

Thanks dear Christian. I will asap rerun my attempt and follow step by step your guide - hoping it works now.

cschneider commented 6 years ago

Closing this issue as I hope it is fixed

jlolling commented 3 years ago

I can confirm, this description works also in the Talend Runtime 7.3.1 In the client I have installed these features:

> feature:repo-add pax-jdbc 1.3.0
> feature:install transaction jndi pax-jdbc-postgresql pax-jdbc-pool-dbcp2 pax-jdbc-config

Here an example of an postgresql datasource configuration file (org.ops4j.datasource-etlcontrol.cfg):

osgi.jdbc.driver.name=PostgreSQL JDBC Driver
pool=dbcp2
serverName=ubuntuserver.local
databaseName=etlcontrol
portNumber=5432
user=postgres
password=postgres
dataSourceName=jdbc/etlcontrol-ds
factory.defaultAutoCommit=true
factory.validationQuery=select current_date
pool.timeBetweenEvictionRunsMillis=60000
pool.minEvictableIdleTimeMillis=20000
pool.maxTotal=300
pool.maxIdle=300

Here the output of the list command:

tadmin@trun()> service:list DataSource
[javax.sql.DataSource]
----------------------
 factory.defaultAutoCommit = true
 pax.jdbc.managed = true
 service.id = 724
 pool.minEvictableIdleTimeMillis = 20000
 service.bundleid = 281
 service.scope = singleton
 dataSourceName = jdbc/etlcontrol-ds
 user = postgres
 pool.timeBetweenEvictionRunsMillis = 60000
 osgi.jdbc.driver.name = PostgreSQL JDBC Driver
 pool.maxIdle = 300
 portNumber = 5432
 pool.maxTotal = 300
 password = postgres
 databaseName = etlcontrol
 osgi.jndi.service.name = jdbc/etlcontrol-ds
 serverName = ubuntuserver.local
 factory.validationQuery = select current_date
 service.factoryPid = org.ops4j.datasource
 felix.fileinstall.filename = file:/Data/Talend/Studio/TOS_ESB-731/Runtime_ESBSE/container/etc/org.ops4j.datasource-etlcontrol.cfg
 service.pid = org.ops4j.datasource.41513306-53b7-4d5d-915f-6057510f1035
Provided by :
 OPS4J Pax JDBC Config (281)

Thanks for your help @cschneider !