Keshav Gupta opened SPR-17278 and commented

We are using LazyConnectionDataSourceProxy to lazily fetch DB connection. When DB connection is fetched from pool there is no notification fired which can tell that db connection has been acquired. This is really helpful whenever some action needs to be taken on acquiring db connection(eg. logging).


Issue Links: - #16195 Add close() method to LazyConnectionDataSourceProxy - #21749 HibernateTransactionManager should lazily acquire JDBC Connection (like HibernateJpaDialect)

Comment From: spring-projects-issues

Juergen Hoeller commented

LazyConnectionDataSourceProxy will trigger a getConnection call on the configured targetDataSource whenever it acquires a new Connection. You could decorate that target DataSource accordingly, logging getConnection calls at that level.

Is there anything more specific you'd like to be notified of here?

Comment From: spring-projects-issues

Keshav Gupta commented

Juergen Hoeller then it will will data source dependent. We use Hikari as data source, if we use different data source then things will have to be changed over there also. Instead if this change is done in LazyConnectionDataSourceProxy then it can be utilised irrespective of data sources.

Comment From: spring-projects-issues

Juergen Hoeller commented

What I meant is another DataSource decorator inbetween: E.g. a custom subclass of Spring's DelegatingDataSource, overriding the getConnection methods accordingly for some logging there before delegating to super. This could sit inbetween LazyConnectionDataSourceProxy and the actual connection pool, as one further layer of decoration (similar to InputStream decoration).

Alternatively, we could also bake some protected callback method into LazyConnectionDataSourceProxy itself, e.g. onConnectionRetrieval. At the moment we perform a callback already but just to checkDefaultConnectionProperties; you could override that one for that purpose but that's a bit of a workaround for a better named solution.

Comment From: jhoeller

With the options above in mind, I'm going to close this issue here.