From 53376d601e6d48318b93a7f7a137032e26a2951c Mon Sep 17 00:00:00 2001 From: Brett Wooldridge Date: Mon, 21 Oct 2013 07:47:00 +0900 Subject: [PATCH] Eliminate some unneeded casts. --- .../zaxxer/hikari/proxy/ConnectionProxy.java | 102 +++++++++--------- .../hikari/proxy/IHikariStatementProxy.java | 3 +- .../zaxxer/hikari/proxy/StatementProxy.java | 5 +- 3 files changed, 55 insertions(+), 55 deletions(-) diff --git a/src/main/java/com/zaxxer/hikari/proxy/ConnectionProxy.java b/src/main/java/com/zaxxer/hikari/proxy/ConnectionProxy.java index 440dce43..aec04e77 100644 --- a/src/main/java/com/zaxxer/hikari/proxy/ConnectionProxy.java +++ b/src/main/java/com/zaxxer/hikari/proxy/ConnectionProxy.java @@ -54,7 +54,7 @@ public class ConnectionProxy extends HikariProxyBase implements IHikariConnectio @HikariInject private static final Set POSTGRESQL_ERRORS; @HikariInject private static final Set SPECIAL_ERRORS; - @HikariInject private ArrayList _openStatements; + @HikariInject private ArrayList _openStatements; @HikariInject private AtomicBoolean _isClosed; @HikariInject private HikariPool _parentPool; @@ -82,18 +82,11 @@ public class ConnectionProxy extends HikariProxyBase implements IHikariConnectio __static(); } - @HikariInject - private void __init() - { - _openStatements = new ArrayList(64); - _isClosed = new AtomicBoolean(); - _creationTime = _lastAccess = System.currentTimeMillis(); - } - protected ConnectionProxy(HikariPool parentPool, Connection connection) { this._parentPool = parentPool; this.delegate = connection; + __init(); } @@ -139,11 +132,6 @@ public class ConnectionProxy extends HikariProxyBase implements IHikariConnectio _isClosed.set(false); } - public final Connection getDelegate() - { - return delegate; - } - @HikariInject public void captureStack(long leakDetectionThreshold, Timer scheduler) { @@ -183,6 +171,19 @@ public class ConnectionProxy extends HikariProxyBase implements IHikariConnectio return sqle; } + @HikariInject + private void __init() + { + _openStatements = new ArrayList(64); + _isClosed = new AtomicBoolean(); + _creationTime = _lastAccess = System.currentTimeMillis(); + } + + public final Connection getDelegate() + { + return delegate; + } + // ********************************************************************** // "Overridden" java.sql.Connection Methods // ********************************************************************** @@ -205,7 +206,7 @@ public class ConnectionProxy extends HikariProxyBase implements IHikariConnectio try { - for (IHikariStatementProxy statement : _openStatements) + for (Statement statement : _openStatements) { statement.close(); } @@ -233,11 +234,11 @@ public class ConnectionProxy extends HikariProxyBase implements IHikariConnectio { try { - IHikariStatementProxy statementProxy = (IHikariStatementProxy) __createStatement(); - statementProxy.setConnectionProxy((Connection) this); + Statement statementProxy = __createStatement(); + ((IHikariStatementProxy) statementProxy).setConnectionProxy(this); _openStatements.add(statementProxy); - return (Statement) statementProxy; + return statementProxy; } catch (SQLException e) { @@ -250,11 +251,11 @@ public class ConnectionProxy extends HikariProxyBase implements IHikariConnectio { try { - IHikariStatementProxy statementProxy = (IHikariStatementProxy) __createStatement(resultSetType, resultSetConcurrency); - statementProxy.setConnectionProxy((Connection) this); + Statement statementProxy = __createStatement(resultSetType, resultSetConcurrency); + ((IHikariStatementProxy) statementProxy).setConnectionProxy(this); _openStatements.add(statementProxy); - return (Statement) statementProxy; + return statementProxy; } catch (SQLException e) { @@ -267,11 +268,11 @@ public class ConnectionProxy extends HikariProxyBase implements IHikariConnectio { try { - IHikariStatementProxy statementProxy = (IHikariStatementProxy) __createStatement(resultSetType, resultSetConcurrency, resultSetHoldability); - statementProxy.setConnectionProxy((Connection) this); + Statement statementProxy = __createStatement(resultSetType, resultSetConcurrency, resultSetHoldability); + ((IHikariStatementProxy) statementProxy).setConnectionProxy(this); _openStatements.add(statementProxy); - return (Statement) statementProxy; + return statementProxy; } catch (SQLException e) { @@ -284,11 +285,11 @@ public class ConnectionProxy extends HikariProxyBase implements IHikariConnectio { try { - IHikariStatementProxy statementProxy = (IHikariStatementProxy) __prepareCall(sql); - statementProxy.setConnectionProxy((Connection) this); + CallableStatement statementProxy = __prepareCall(sql); + ((IHikariStatementProxy) statementProxy).setConnectionProxy(this); _openStatements.add(statementProxy); - return (CallableStatement) statementProxy; + return statementProxy; } catch (SQLException e) { @@ -301,11 +302,11 @@ public class ConnectionProxy extends HikariProxyBase implements IHikariConnectio { try { - IHikariStatementProxy statementProxy = (IHikariStatementProxy) __prepareCall(sql, resultSetType, resultSetConcurrency); - statementProxy.setConnectionProxy((Connection) this); + CallableStatement statementProxy = __prepareCall(sql, resultSetType, resultSetConcurrency); + ((IHikariStatementProxy) statementProxy).setConnectionProxy(this); _openStatements.add(statementProxy); - return (CallableStatement) statementProxy; + return statementProxy; } catch (SQLException e) { @@ -318,11 +319,11 @@ public class ConnectionProxy extends HikariProxyBase implements IHikariConnectio { try { - IHikariStatementProxy statementProxy = (IHikariStatementProxy) __prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability); - statementProxy.setConnectionProxy((Connection) this); + CallableStatement statementProxy = __prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability); + ((IHikariStatementProxy) statementProxy).setConnectionProxy(this); _openStatements.add(statementProxy); - return (CallableStatement) statementProxy; + return statementProxy; } catch (SQLException e) { @@ -335,11 +336,11 @@ public class ConnectionProxy extends HikariProxyBase implements IHikariConnectio { try { - IHikariStatementProxy statementProxy = (IHikariStatementProxy) __prepareStatement(sql); - statementProxy.setConnectionProxy((Connection) this); + PreparedStatement statementProxy = __prepareStatement(sql); + ((IHikariStatementProxy) statementProxy).setConnectionProxy(this); _openStatements.add(statementProxy); - return (PreparedStatement) statementProxy; + return statementProxy; } catch (SQLException e) { @@ -352,11 +353,11 @@ public class ConnectionProxy extends HikariProxyBase implements IHikariConnectio { try { - IHikariStatementProxy statementProxy = (IHikariStatementProxy) __prepareStatement(sql, autoGeneratedKeys); - statementProxy.setConnectionProxy((Connection) this); + PreparedStatement statementProxy = __prepareStatement(sql, autoGeneratedKeys); + ((IHikariStatementProxy) statementProxy).setConnectionProxy(this); _openStatements.add(statementProxy); - return (PreparedStatement) statementProxy; + return statementProxy; } catch (SQLException e) { @@ -369,11 +370,11 @@ public class ConnectionProxy extends HikariProxyBase implements IHikariConnectio { try { - IHikariStatementProxy statementProxy = (IHikariStatementProxy) __prepareStatement(sql, resultSetType, resultSetConcurrency); - statementProxy.setConnectionProxy((Connection) this); + PreparedStatement statementProxy = __prepareStatement(sql, resultSetType, resultSetConcurrency); + ((IHikariStatementProxy) statementProxy).setConnectionProxy(this); _openStatements.add(statementProxy); - return (PreparedStatement) statementProxy; + return statementProxy; } catch (SQLException e) { @@ -386,10 +387,11 @@ public class ConnectionProxy extends HikariProxyBase implements IHikariConnectio { try { - IHikariStatementProxy statementProxy = (IHikariStatementProxy) __prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability); + PreparedStatement statementProxy = __prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability); + ((IHikariStatementProxy) statementProxy).setConnectionProxy(this); _openStatements.add(statementProxy); - return (PreparedStatement) statementProxy; + return statementProxy; } catch (SQLException e) { @@ -402,11 +404,11 @@ public class ConnectionProxy extends HikariProxyBase implements IHikariConnectio { try { - IHikariStatementProxy statementProxy = (IHikariStatementProxy) __prepareStatement(sql, columnIndexes); - statementProxy.setConnectionProxy((Connection) this); + PreparedStatement statementProxy = __prepareStatement(sql, columnIndexes); + ((IHikariStatementProxy) statementProxy).setConnectionProxy(this); _openStatements.add(statementProxy); - return (PreparedStatement) statementProxy; + return statementProxy; } catch (SQLException e) { @@ -419,11 +421,11 @@ public class ConnectionProxy extends HikariProxyBase implements IHikariConnectio { try { - IHikariStatementProxy statementProxy = (IHikariStatementProxy) __prepareStatement(sql, columnNames); - statementProxy.setConnectionProxy((Connection) this); + PreparedStatement statementProxy = __prepareStatement(sql, columnNames); + ((IHikariStatementProxy) statementProxy).setConnectionProxy(this); _openStatements.add(statementProxy); - return (PreparedStatement) statementProxy; + return statementProxy; } catch (SQLException e) { diff --git a/src/main/java/com/zaxxer/hikari/proxy/IHikariStatementProxy.java b/src/main/java/com/zaxxer/hikari/proxy/IHikariStatementProxy.java index 7a4bc6ad..83a20f8e 100644 --- a/src/main/java/com/zaxxer/hikari/proxy/IHikariStatementProxy.java +++ b/src/main/java/com/zaxxer/hikari/proxy/IHikariStatementProxy.java @@ -1,13 +1,12 @@ package com.zaxxer.hikari.proxy; -import java.sql.Connection; import java.sql.SQLException; public interface IHikariStatementProxy { void close() throws SQLException; - void setConnectionProxy(Connection connectionProxy); + void setConnectionProxy(IHikariConnectionProxy connectionProxy); SQLException checkException(SQLException e); } diff --git a/src/main/java/com/zaxxer/hikari/proxy/StatementProxy.java b/src/main/java/com/zaxxer/hikari/proxy/StatementProxy.java index 5b8785b5..f83c1e21 100644 --- a/src/main/java/com/zaxxer/hikari/proxy/StatementProxy.java +++ b/src/main/java/com/zaxxer/hikari/proxy/StatementProxy.java @@ -16,7 +16,6 @@ package com.zaxxer.hikari.proxy; -import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; @@ -46,9 +45,9 @@ public class StatementProxy extends HikariProxyBase implements IHikariStatementP } @HikariInject - public void setConnectionProxy(Connection connection) + public void setConnectionProxy(IHikariConnectionProxy connection) { - this._connection = (IHikariConnectionProxy) connection; + this._connection = connection; } @HikariInject