swaldman / c3p0

a mature, highly concurrent JDBC Connection pooling library, with support for caching and reuse of PreparedStatements.
http://www.mchange.com/projects/c3p0
Other
1.28k stars 338 forks source link

Need to understand undocumented functions #144

Open steowens opened 4 years ago

steowens commented 4 years ago

I am attempting to migrate an app which uses c3po over to leveraging AWS IAM credentials:

https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/UsingWithRDS.IAMDBAuth.Connecting.Java.html

Apparently AWS issues a new access token every 15 minutes, and this is used as the password for the jdbc credentials. We use the ComboPooledDataSource which extends AbstractComboPooledDataSource which extends AbstractPoolBackedDataSource which extends PoolBackedDataSourceBase which extends IdentityTokenResolvable

ComboPooledDataSource uses WrapperConnectionPoolDataSource which wraps DriverManagerDataSource.

Anyway there are a whole bunch of undocumented public functions and methods on this heirarchy, and what I am trying to figure out as I weed my way through this code is what do I need to do to fix it so that we can have a ComboPooledDataSource connect to RDS hosts in multiple regions using the host list stragegy on the JDBC url, and have it execute failover the way it does very well with ordinary static credentials, subject to the constraint that if using IAM credentials instead, the password on each host is different and is subject to change every 15 minutes?

swaldman commented 6 months ago

One way to address this would be to create your own DataSource implementation, reorganizing the example code that you link. You'd want to just implement the getConnection() method, maybe throw or delegate to that if getConnection(String user, String password) ever gets called, quick stubbish implementations of all the rest. getConnection() would do authentication as shown.

Then wrap your custom DataSource into a PooledDataSource. See https://www.mchange.com/projects/c3p0/#using_datasources_factory