HikariCP with configuration property "initSQL" not supported?

213 views
Skip to first unread message

tilois

unread,
Jul 24, 2015, 7:16:29 PM7/24/15
to play-framework
Hi everyone,

I am trying to use the configuration parameter "initSQL" which was previously provided by BoneCP and let each connection perform an action before it is added to the pool.
My use case is to switch the schema to another on each connection.

HikariCP supports an equal concept by the "connectionInitSql" configuration property (see https://github.com/brettwooldridge/HikariCP).
If I see this right, all that is left is a call to

     setConnectionInitSql   (see https://github.com/brettwooldridge/HikariCP/blob/60e0eb1b8bb87242665c37e1f3ecf549b2457206/hikaricp-common/src/main/java/com/zaxxer/hikari/AbstractHikariConfig.java#L254)

somewhere where the play configuration is mapped to the Hikari Configuration: https://github.com/playframework/playframework/blob/master/framework/src/play-jdbc/src/main/scala/play/api/db/HikariCPModule.scala#L90

So my assumption is that this is currently not supported but could be easily added?

Best Regards
Tilois

tilois

unread,
Jul 25, 2015, 9:52:40 AM7/25/15
to play-framework, timo...@gmail.com
Just a short update:

I have done a proof-of-concept in Java, which basically binds the `play.api.db.ConnectionPool` (yes, the Scala one in order to be able to still use the DBModule which relies on that beeing bound) to another connection pool
 which uses another HikariCP Configuration object which in turn reads the "InitSQL" parameter again.

This works fine for me now but was a bit of a hassle.

My suggestion would be:

1) Unrelated to my initial problem: Register a `Provider<HikariConfig>` to the Guice Injector to make that Mapping (Play Config to Hikari CP Config) more easily exchangeable.
Disadvantage: If that Provider is not bound Guice will instantiate a default config which is not valid (ouch).
Currently this mapping is more tighly coupled to the Connection Pool than it needs to be in my view.

2) Enhance the current mapping to read the "InitSQL" again and to pass it to the `setConnectionInitSql`.

In case this is acceptable, I would make a pull request.
But before that, a question:

Where is the right place to expect the "InitSQL" configuration? Is it

a) db.default.initSQL or
b) db.default.hikaricp.initSQL

My personal preference is for (a)

tilois

unread,
Jul 25, 2015, 9:53:19 AM7/25/15
to play-framework, timo...@gmail.com

Marcos Silva Pereira

unread,
Jul 27, 2015, 10:05:17 AM7/27/15
to play-framework, timo...@gmail.com
Tilois, 

Could you please open an issue:


I think this is a problem we should correct.

Best regards,

Marcos Silva Pereira

unread,
Jul 28, 2015, 9:06:55 PM7/28/15
to play-framework, timo...@gmail.com, marcos...@gmail.com
Here is a pull request to fix this issue:


Tilois, thank you for reporting it.

Best,
Reply all
Reply to author
Forward
0 new messages