Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notification for db connection acquired when LazyConnectionDataSourceProxy is used [SPR-17278] #21811

Open
spring-projects-issues opened this issue Sep 17, 2018 · 3 comments
Labels
in: data type: enhancement

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Sep 17, 2018

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)
@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Sep 17, 2018

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?

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Sep 18, 2018

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.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Sep 18, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: data type: enhancement
Projects
None yet
Development

No branches or pull requests

1 participant