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

what's the purpose to generate HikariProxyConnection by javaassist since you already write ProxyConnection ? #1198

Closed
dumbdonkey opened this issue Jul 11, 2018 · 5 comments

Comments

@dumbdonkey
Copy link

according to the source code, I found ProxyConnection already do a lot of things, HikariProxyConnection only add a try catch block to every method.
I was so confused. it would be nice if anyone can give an explanation. thanks in advance!

@brettwooldridge
Copy link
Owner

The proxies delegate to the real driver classes. Some proxies, like the one for ResultSet, only intercept a few methods. Without the code generation, the proxy would have to implement all 50+ methods which simply delegate to the wrapped instance.

Code generation, based on reflection, also means that nothing needs to be done when a new JDK version introduces new JDBC methods to existing interfaces.

@dumbdonkey
Copy link
Author

@brettwooldridge thanks a lot

@fengchangsheng
Copy link

Although the ProxyConnection is a abstract class, as a connection-pooling, must impl this method in fact. Generate these class just for compatible with high version JDK?

@brettwooldridge
Copy link
Owner

A concrete class is generated from the abstract ProxyConnection class. Any methods that are not "overridden" by the abstract class, and that throw SQLException have delegates generated with the following code:

{
  try {
    return delegate.method($$);
  } catch (SQLException e) {
    throw checkException(e);
  }
}

... which allows us to inspect the exception to see if it represents a disconnection error.

A side-effect is that, yes, the code ends of being flexible with respect to JDBC API changes -- at least all that we have encountered so far.

@fengchangsheng
Copy link

@brettwooldridge thanks for the "official" response!

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

3 participants