gpt4 book ai didi

java - 既然作者已经写了ProxyConnection,为什么要通过javaassist生成HikariProxyConnection呢?

转载 作者:行者123 更新时间:2023-11-30 06:01:34 31 4
gpt4 key购买 nike

根据HikariCP的源代码,我发现作者通过javaassist生成了HikariProxyConnection,但是该类除了调用父类(super class)方法之外什么也没做。

例如,HikariProxyConnection 的父类(super class)是 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);
}
} }

我发现ProxyConnection已经做了很多事情,HikariProxyConnection只是在每个方法中添加了一个try catch block 。

如果有人能给出解释就好了。

最佳答案

有一个Hikari issue关于 @brettwooldridge 回答的 HikariProxyConnection 的目的:

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.

关于java - 既然作者已经写了ProxyConnection,为什么要通过javaassist生成HikariProxyConnection呢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52181840/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com