Skip to content

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

Closed as not planned

Description

@spring-projects-issues

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:

Activity

  1. spring-projects-issues commented on Sep 17, 2018

    @spring-projects-issues
    CollaboratorAuthor

    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?

  2. spring-projects-issues commented on Sep 18, 2018

    @spring-projects-issues
    CollaboratorAuthor

    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.

  3. spring-projects-issues commented on Sep 18, 2018

    @spring-projects-issues
    CollaboratorAuthor

    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.

  4. added
    in: data
    type: enhancement
    on Jan 11, 2019
  5. jhoeller commented on Jul 13, 2023

    @jhoeller
    Contributor

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

  6. added
    status: declined
    on Jul 13, 2023
  7. removed this from the General Backlog milestone on Jul 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: datastatus: declinedtype: enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions