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

Allow any datasource to be used. #21

Closed
timmolter opened this issue Feb 14, 2015 · 5 comments
Closed

Allow any datasource to be used. #21

timmolter opened this issue Feb 14, 2015 · 5 comments

Comments

@timmolter
Copy link
Member

Idea: take a look at how Tomcat accepts any datasource and shuts it down properly.

@timmolter
Copy link
Member Author

From @eepstein

Here’s part of a Java 1.5 Generics way to support other DataSources and also the release() functionality:

public final class YankPoolManager<T extends DataSource & Closeable> {
    …
       private final Map<String, T> pools = ...
    ...
       protected void addDataSource(String name, T ds) {
          pools.put(name, ds);
       }

and then, inside #release() call close() inside a try block.

@timmolter
Copy link
Member Author

Of the following connection pools, only Hikari and BoneCP implement Closeable.

JDBC Connection Pool Implements methods
Hikari DataSource, Closeable close(),shutdown()
BoneCP DataSource, Closeable close(),shutdown()
C3P0 DataSource close()
DBCP DataSource close()
ViburCP DataSource terminate()

It's lame that DataSource doesn't have a close() method.

@eepstein
Copy link
Contributor

2 out of 5 . .. not bad ;-)

Bummer is that 4 of the 5 implement close() but don’t declare the interface. Fall-back would be dynamic dispatch via something like javassist with introspection, which is what Hikari does for calls to the underlying DataSource… but seems like a hassle. The nice thing about doing the generic is it leaves the door open to anyone who wants to write such a wrapper / delegation - whether implemented via dynamic dispatch or long-hand. And it makes the coupling to the CP looser.

But still, less coverage than getting all 5 of those, which would be ideal.

On Feb 14, 2015, at 4:34 PM, Tim Molter notifications@github.com wrote:

Of the following connection pools, only Hikari and BoneCP implement Closeable.

| JDBC Connection Pool | Implements | methods |
|---|---|
|Hikari|DataSource, Closeable|close(),shutdown()|
|BoneCP|DataSource, Closeable|close(),shutdown()|
|C3P0|DataSource|close()|
|DBCP|DataSource|close()|
|ViburCP|DataSource|terminate()|


Reply to this email directly or view it on GitHub #21 (comment).

@eepstein
Copy link
Contributor

hmm. The Java-8 approach I’d take would be to include an optional “closer” Function in the addConnectionPool() method. Default (null) would cast to closable and call close(), but if caller provided a closer function the release method would invoke that. This is fully general then, but with lambda’s required an Interface and someone to implement for each CP type they want to use. That said, the Interface in this case has 1 method, so unlike wrapping and delegating this is lightweight and goes general purpose…. Works , but is clearly a work-around. That said, if you think that fits, then it’s light-weight on the coding side. So, if yes, lemme know if you want me to code that.

On Feb 14, 2015, at 4:34 PM, Tim Molter notifications@github.com wrote:

Of the following connection pools, only Hikari and BoneCP implement Closeable.

| JDBC Connection Pool | Implements | methods |
|---|---|
|Hikari|DataSource, Closeable|close(),shutdown()|
|BoneCP|DataSource, Closeable|close(),shutdown()|
|C3P0|DataSource|close()|
|DBCP|DataSource|close()|
|ViburCP|DataSource|terminate()|


Reply to this email directly or view it on GitHub #21 (comment).

@timmolter
Copy link
Member Author

Nah, using the default Hikari is simple and effective for the purpose of this lib.

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

No branches or pull requests

2 participants