Skip to content

Add close() method to LazyConnectionDataSourceProxy [SPR-11571] #16195

Closed

Description

@spring-projects-issues

Thomas Zimmermann opened SPR-11571 and commented

It would be a convenient feature if the LazyConnectionDataSourceProxy would provide a public close() method that delegates to a (possibly configurable) destroy-method on the wrapped DataSource if one is present. This would avoid having to declare two datasource beans: one for the LazyConnectionDataSourceProxy and one for the underlying DataSource itself, so that the proper destroy-method can be called on it.

I'm initializing my DataSource as follows:

    @Bean
    public DataSource dataSource() {
        PGSimpleDataSource dataSource = new PGSimpleDataSource();
        // set properties ...

        // set up connection pool, HikariCP in my case
        HikariDataSource connectionPool = new HikariDataSource(config);

        LazyConnectionDataSourceProxy lazyDataSource = new LazyConnectionDataSourceProxy();
        lazyDataSource.setTargetDataSource(connectionPool);
        // set properties ...

        return lazyDataSource;
    }

A suggestion how this could work would be:

    @Bean(destroyMethod="close") // as per default
    public DataSource dataSource() {
        PGSimpleDataSource dataSource = new PGSimpleDataSource();
        // set properties ...

        // set up connection pool, HikariCP in my case
        HikariDataSource connectionPool = new HikariDataSource(config);

        LazyConnectionDataSourceProxy lazyDataSource = new LazyConnectionDataSourceProxy();
        lazyDataSource.setTargetDataSource(connectionPool);
        // set properties ...

        lazyDataSource.setDestroyMethod("shutdown"); // or call "close" by default

        return lazyDataSource;
    }

Affects: 4.0.2

Issue Links:

Referenced from: commits 3c58be0, 6551aa6

Activity

  1. spring-projects-issues commented on Jul 6, 2015

    @spring-projects-issues
    CollaboratorAuthor

    Scott Feldstein commented

    I worked around this issue by instantiating my dataSource Bean as follows:

    @Bean(destroyMethod="close")
    public DataSource dataSource() {
        return new LazyConnectionDataSourceProxy(targetDataSource()) {
            public void close() throws SQLException {
                BasicDataSource target = (BasicDataSource)super.getTargetDataSource();
                target.close();
            }
        };
    }
    
  2. added
    status: waiting-for-triage
    type: enhancement
    and removed
    type: enhancement
    on Jan 11, 2019
  3. added
    status: bulk-closed
    and removed
    status: waiting-for-triage
    on Jan 11, 2019
  4. spring-projects-issues commented on Jan 12, 2019

    @spring-projects-issues
    CollaboratorAuthor

    Bulk closing outdated, unresolved issues. Please, reopen if still relevant.

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

    status: bulk-closed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions