brettwooldridge / HikariCP

光 HikariCP・A solid, high-performance, JDBC connection pool at last.
Apache License 2.0
19.91k stars 2.92k forks source link

Hooking the connection.close() call #2169

Open valley-fordham opened 7 months ago

valley-fordham commented 7 months ago

I currently have some logic that occurs when retrieving a database connection from a wrapper class on HikariDataSource, and I'd like to rollback those changes by hooking the indirect calls to .close() we make on the connection using try-with-resources.

Is there an easy way to provide a callback which can do this, without building a new connection wrapper around the Hikari connection? I can't see any documentation to this end but I may have missed it.

Happy to provide a code snippet if I'm not making sense.

valley-fordham commented 7 months ago

To expand further, I've looked into doing this by using a wrapper and it seems that the close method on the abstract ProxyConnection is final, so I can't override it without using unsafe methods, as far as I can see. Open to ideas!