According to the source code of HikariCP, I found the author generates HikariProxyConnection by javaassist, but the class do nothing but invoke the super class method.
For example, the HikariProxyConnection's super class is ProxyConnection:
public class HikariProxyConnection extends ProxyConnection implements AutoCloseable, Connection, Wrapper {
public Statement createStatement() throws SQLException {
try {
return super.createStatement();
} catch (SQLException var2) {
throw this.checkException(var2);
}
}
public PreparedStatement prepareStatement(String var1) throws SQLException {
try {
return super.prepareStatement(var1);
} catch (SQLException var3) {
throw this.checkException(var3);
}
} }
I found ProxyConnection already do a lot of things, HikariProxyConnection only add a try catch block to every method.
It would be nice if anyone can give an explanation.
There's a Hikari issue on the purpose of HikariProxyConnection
answered by @brettwooldridge :
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.