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

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

Closed
spring-projects-issues opened this issue Mar 18, 2014 · 2 comments
Closed
Labels
status: bulk-closed

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Mar 18, 2014

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:

  • #21811 Notification for db connection acquired when LazyConnectionDataSourceProxy is used

Referenced from: commits 3c58be0, 6551aa6

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jul 6, 2015

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();
        }
    };
}

@spring-projects-issues spring-projects-issues added status: waiting-for-triage type: enhancement labels Jan 11, 2019
@spring-projects-issues spring-projects-issues removed the type: enhancement label Jan 11, 2019
@rstoyanchev rstoyanchev added status: bulk-closed and removed status: waiting-for-triage labels Jan 11, 2019
@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jan 12, 2019

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
Labels
status: bulk-closed
Projects
None yet
Development

No branches or pull requests

2 participants