HikariCP
HikariCP copied to clipboard
`HikariProxyConnection` directly calls `delegate.getTransactionIsolation()`, causing a network call every time.
Version: Hibernate 5.1
What
HikariProxyConnection.getTransactionIsolation()
causes a network call everytime due to invoking delegate.getTransactionIsolation()
The method for HikariProxyConnection
says:
public int getTransactionIsolation() throws SQLException {
try {
return super.delegate.getTransactionIsolation();
} catch (SQLException var2) {
throw this.checkException(var2);
}
This causes a call to the underlying Connection.getTransactionIsolation()
, which is usually a network call to the database.
Curiously, in ProxyConnection
there is a similarly named method
https://github.com/brettwooldridge/HikariCP/blob/0a6ccdb334b2ecde25ae090034669d534736a0de/src/main/java/com/zaxxer/hikari/pool/ProxyConnection.java#L126-L129
Which returns the cached transaction isolation level stored by Hikari.
Why is this a problem
Example: In Spring, there is a check to see if the isolation level of the transaction matches that of the connection. https://github.com/spring-projects/spring-framework/blob/8137cc95669690f3e4055d6ccf484e98a07b6703/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/DataSourceUtils.java#L208-L218
Thank you for your valuable time and attention!
Which returns the cached transaction isolation level stored by Hikari.
The cached transaction isolation only available if Connection::setTransactionIsolation
called, I think it could be improved here, but the network call cannot be avoided if Connection::setTransactionIsolation
not called first.
https://github.com/brettwooldridge/HikariCP/blob/0a6ccdb334b2ecde25ae090034669d534736a0de/src/main/java/com/zaxxer/hikari/pool/ProxyConnection.java#L419-L424