Re: embeded tomcat and correct DataSource. - Mailing list pgsql-jdbc

From Rob Sargent
Subject Re: embeded tomcat and correct DataSource.
Date
Msg-id dd7bb079-7123-c0b1-7cec-a4f3807b2f54@gmail.com
Whole thread Raw
In response to Re: embeded tomcat and correct DataSource.  (Dave Cramer <davecramer@postgres.rocks>)
List pgsql-jdbc


On 11/17/20 4:04 PM, Dave Cramer wrote:

On Tue, 17 Nov 2020 at 17:57, Rob Bygrave <robin.bygrave@gmail.com> wrote:
Hi,

Sorry I'm probably mis-interpreting your question.  Hopefully the comments below are useful.


I should use the PGConnectionPoolDataSource if I wish to use Apache connection pool mechanism.

In short, I'm pretty sure the answer is no.

The longer answer is, PGPoolingDataSource is the DataSource implementation provided in pgjdbc. PGPoolingDataSource is deprecated with the comment below and noting that PGPoolingDataSource uses PGConnectionPoolDataSource (as an implementation detail).  We could think of PGConnectionPoolDataSource as part of the DataSource implementation provided with postgresql jdbc driver that is marked as deprecated (with the suggestion that we migrate to any other third party DataSource implementation). 

* @deprecated Since 42.0.0, instead of this class you should use a fully featured connection pool
* like HikariCP, vibur-dbcp, commons-dbcp, c3p0, etc.
 


Any third party javax.sql.DataSource implementation would be extremely unlikely to use anything in the org.postgresql.ds package including PGConnectionPoolDataSource.


Rob,

Thanks for catching this. I mis-read the question.

Rob is correct! Do not use the PGPooling source for anything. It is really there for completeness. There are so many other good pooling implementations it just does not make sense for us to re-implement one.
 

Dave Cramer



Yes, that was corrected after I posted before I got anything to work.


current wiring is:

ContextResource contextResource = new ContextResource();

contextResource.setName("jdbc/sgsdb");
contextResource.setType("javax.sql.DataSource");
contextResource.setProperty("url", "jdbc:postgresql://localhost:5432/version4007");
contextResource.setProperty("driverClassName", "org.postgresql.Driver");
contextResource.setProperty("username", "postgres");
contextResource.setProperty("password", "notnull");
contextResource.setProperty("testWhileIdle", "false");
contextResource.setProperty("testOnBorrow", "true");
contextResource.setProperty("validationQuery", "SELECT 1");
contextResource.setProperty("testOnReturn", "false");
contextResource.setProperty("validationInterval", "30000");
contextResource.setProperty("timeBetweenEvictionRunsMillis", "30000");
contextResource.setProperty("maxActive", "50");
contextResource.setProperty("initialSize", "5");
contextResource.setProperty("maxWait", "10000");
contextResource.setProperty("removeAbandonedTimeout", "60");
contextResource.setProperty("minEvictableIdleTimeMillis", "30000");
contextResource.setProperty("minIdle", "3");
contextResource.setProperty("logAbandoned", "true");
contextResource.setProperty("removeAbandoned", "true");

contextResource.setProperty("factory", "org.apache.tomcat.jdbc.pool.DataSourceFactory");
ctx.getNamingResources().addResource(contextResource);

where ctx is the webapp context.

Thanks for reading!


pgsql-jdbc by date:

Previous
From: Dave Cramer
Date:
Subject: Re: embeded tomcat and correct DataSource.
Next
From: Dave Cramer
Date:
Subject: [pgjdbc/pgjdbc] e5e906: fix: Postgres version 14 changes the returned PSQL...