Hello

I added a comment to
https://github.com/pgjdbc/pgjdbc/issues/1476#issuecomment-497635922

regards
Grzegorz Grzybek

pt., 31 maj 2019 o 10:48 Grzegorz Grzybek <[email protected]> napisał(a):

> Hello
>
> Interesting case. I did some work in pax-jdbc and was especially happy
> with how PostgreSQL driver natively registers
> org.osgi.service.jdbc.DataSourceFactory OSGi service. But tbh, even if I
> did lot of pooling/non-pooling, XA/non-XA tests (under or without several
> TX managers), I never tried (shame!) restarting postgresql driver bundle!.
>
> With this etc/org.ops4j.datasource-postgres.cfg configuration:
>
> osgi.jdbc.driver.class=org.postgresql.Driver
> dataSourceName=postgres
> dataSourceType=DataSource
> jdbc.url=jdbc:postgresql://localhost:5432/reportdb
> jdbc.user=xxx
> jdbc.password=xxx
>
> pool=dbcp2
> # dbcp2 specific configuration of
> org.apache.commons.pool2.impl.GenericObjectPoolConfig
> pool.minIdle = 10
> pool.maxTotal = 100
> pool.blockWhenExhausted = true
> pool.maxWaitMillis = 2000
> pool.testOnBorrow = true
> pool.testWhileIdle = false
> pool.timeBetweenEvictionRunsMillis = 120000
> pool.evictionPolicyClassName =
> org.apache.commons.pool2.impl.DefaultEvictionPolicy
>
> # dbcp2 specific configuration of
> org.apache.commons.dbcp2.PoolableConnectionFactory
> factory.maxConnLifetimeMillis = 30000
> factory.validationQuery  = select schema_name from
> information_schema.schemata
> factory.validationQueryTimeout = 2
>
> I also had this problem:
>
> java.sql.SQLException: No suitable driver found for
> jdbc:postgresql://localhost:5432/reportdb?loglevel[…]
> at java.sql.DriverManager.getConnection(DriverManager.java:689) ~[?:?]
> at java.sql.DriverManager.getConnection(DriverManager.java:247) ~[?:?]
> at
> org.postgresql.ds.common.BaseDataSource.getConnection(BaseDataSource.java:86)
> ~[?:?]
> at
> org.postgresql.ds.common.BaseDataSource.getConnection(BaseDataSource.java:71)
> ~[?:?]
> at
> org.apache.commons.dbcp2.DataSourceConnectionFactory.createConnection(DataSourceConnectionFactory.java:44)
> ~[?:?]
> at
> org.apache.commons.dbcp2.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:256)
> ~[?:?]
> at
> org.apache.commons.pool2.impl.GenericObjectPool.create(GenericObjectPool.java:889)
> ~[?:?]
> at
> org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:433)
> ~[?:?]
> at
> org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:362)
> ~[?:?]
> at
> org.apache.commons.dbcp2.PoolingDataSource.getConnection(PoolingDataSource.java:134)
> ~[?:?]
> at
> org.apache.karaf.jdbc.internal.JdbcConnector.connect(JdbcConnector.java:49)
> ~[?:?]
> at
> org.apache.karaf.jdbc.internal.JdbcConnector.createStatement(JdbcConnector.java:61)
> ~[?:?]
> at
> org.apache.karaf.jdbc.internal.JdbcServiceImpl.query(JdbcServiceImpl.java:139)
> ~[?:?]
> at
> org.apache.karaf.jdbc.command.QueryCommand.execute(QueryCommand.java:50)
> ~[?:?]
> ...
>
> because, underneath there's always java.sql.DriverManager.getConnection()
> call. And postgresql driver unregisters the driver when bundle stops, but
> never registers it again when it starts (because the registration was in
> static{} block, not in BundleActivator.start().
>
> simply refreshing postgresql driver bundle after restarting did the trick
> (new classloader → static{} block invoked again).
>
> I'll switch to https://github.com/pgjdbc/pgjdbc/issues/1476 to continue
> the thread.
>
> regards
> Grzegorz Grzybek
>
> czw., 2 maj 2019 o 07:15 'Christoph Läubrich' via OPS4J <
> [email protected]> napisał(a):
>
>> Correctly, the PGDataSourceFactory should simply instatiate the required
>> class directly, no need for using the DriverManager at all!
>> See [1] line 131 or [2] line 40, 47, 54 for example.
>>
>> The problem with DataSourceFactory is that it does not support dynmics
>> or different class-loader spaces very well.
>>
>> [1]
>>
>> https://github.com/MariaDB/mariadb-connector-j/blob/1d831664f7d871ccd871fb9b2137ce3cd3421c4d/src/main/java/org/mariadb/jdbc/internal/osgi/MariaDbDataSourceFactory.java
>>
>> [2]
>>
>> https://github.com/Microsoft/mssql-jdbc/blob/dev/src/main/java/com/microsoft/sqlserver/jdbc/osgi/SQLServerDataSourceFactory.java
>>
>> Am 01.05.19 um 16:49 schrieb Steinar Bang:
>> >>>>>> 'Christoph Läubrich' via OPS4J <ops4j-/
>> [email protected]>:
>> >
>> >> DriverManger.register/unregister can't work reliable in OSGi
>> >> (especially with static insitilizer), thus always the
>> >> DataSourceFactory should be used instead!
>> >
>> > PGDataSourceFactory is currently implemented using the regular PG JDBC
>> > driver, ie. the Driver class, which in turn uses the DriverManager in
>> > rt.jar.
>> >
>> > So the fix should be to change the implementation of PGDataSourceFactory
>> > to not use the Driver class via DriverManager?  Maybe
>> > PGDataSourceFactory should create and own a Driver instance?
>> >
>>
>> --
>> --
>> ------------------
>> OPS4J - http://www.ops4j.org - [email protected]
>>
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "OPS4J" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
-- 
------------------
OPS4J - http://www.ops4j.org - [email protected]

--- 
You received this message because you are subscribed to the Google Groups 
"OPS4J" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ops4j/CAAdXmhrCc9fy6E0dh87YZ0X%2B%2BmrawEZd%3DNyR21t6ZNBxE56TrA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to