From c04f59f3b88852b42f9e69d3acfb712f62391e31 Mon Sep 17 00:00:00 2001 From: Brett Wooldridge Date: Thu, 9 Oct 2014 17:41:33 +0900 Subject: [PATCH] Minor performance tweaks and readability changes. --- .../zaxxer/hikari/proxy/ConnectionProxy.java | 60 +++++++++---------- .../zaxxer/hikari/proxy/ConnectionProxy.java | 60 +++++++++---------- 2 files changed, 54 insertions(+), 66 deletions(-) diff --git a/hikaricp-java6/src/main/java/com/zaxxer/hikari/proxy/ConnectionProxy.java b/hikaricp-java6/src/main/java/com/zaxxer/hikari/proxy/ConnectionProxy.java index ffe28b37..eef395eb 100644 --- a/hikaricp-java6/src/main/java/com/zaxxer/hikari/proxy/ConnectionProxy.java +++ b/hikaricp-java6/src/main/java/com/zaxxer/hikari/proxy/ConnectionProxy.java @@ -46,8 +46,8 @@ public abstract class ConnectionProxy implements IHikariConnectionProxy private final HikariPool parentPool; private final PoolBagEntry bagEntry; - private final FastList openStatements; private final LeakTask leakTask; + private FastList openStatements; private boolean forceClose; private boolean isAnythingDirty; @@ -187,21 +187,19 @@ public abstract class ConnectionProxy implements IHikariConnectionProxy leakTask.cancel(); - try { - final int size = openStatements.size(); - if (size > 0) { - for (int i = 0; i < size; i++) { - try { - openStatements.get(i).close(); - } - catch (SQLException e) { - checkException(e); - } + final int size = openStatements.size(); + if (size > 0) { + for (int i = 0; i < size; i++) { + try { + openStatements.get(i).close(); + } + catch (SQLException e) { + checkException(e); } - - openStatements.clear(); } + } + try { if (isAnythingDirty) { resetConnectionState(); } @@ -240,11 +238,11 @@ public abstract class ConnectionProxy implements IHikariConnectionProxy /** {@inheritDoc} */ @Override - public final Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException + public final Statement createStatement(int resultSetType, int concurrency) throws SQLException { checkClosed(); try { - Statement proxyStatement = ProxyFactory.getProxyStatement(this, delegate.createStatement(resultSetType, resultSetConcurrency)); + Statement proxyStatement = ProxyFactory.getProxyStatement(this, delegate.createStatement(resultSetType, concurrency)); return trackStatement(proxyStatement); } catch (SQLException e) { @@ -254,11 +252,11 @@ public abstract class ConnectionProxy implements IHikariConnectionProxy /** {@inheritDoc} */ @Override - public final Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException + public final Statement createStatement(int resultSetType, int concurrency, int holdability) throws SQLException { checkClosed(); try { - Statement proxyStatement = ProxyFactory.getProxyStatement(this, delegate.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability)); + Statement proxyStatement = ProxyFactory.getProxyStatement(this, delegate.createStatement(resultSetType, concurrency, holdability)); return trackStatement(proxyStatement); } catch (SQLException e) { @@ -272,8 +270,8 @@ public abstract class ConnectionProxy implements IHikariConnectionProxy { checkClosed(); try { - CallableStatement proxyCallableStatement = ProxyFactory.getProxyCallableStatement(this, delegate.prepareCall(sql)); - return trackStatement(proxyCallableStatement); + CallableStatement pcs = ProxyFactory.getProxyCallableStatement(this, delegate.prepareCall(sql)); + return trackStatement(pcs); } catch (SQLException e) { throw checkException(e); @@ -282,12 +280,12 @@ public abstract class ConnectionProxy implements IHikariConnectionProxy /** {@inheritDoc} */ @Override - public final CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException + public final CallableStatement prepareCall(String sql, int resultSetType, int concurrency) throws SQLException { checkClosed(); try { - CallableStatement proxyCallableStatement = ProxyFactory.getProxyCallableStatement(this, delegate.prepareCall(sql, resultSetType, resultSetConcurrency)); - return trackStatement(proxyCallableStatement); + CallableStatement pcs = ProxyFactory.getProxyCallableStatement(this, delegate.prepareCall(sql, resultSetType, concurrency)); + return trackStatement(pcs); } catch (SQLException e) { throw checkException(e); @@ -296,13 +294,12 @@ public abstract class ConnectionProxy implements IHikariConnectionProxy /** {@inheritDoc} */ @Override - public final CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException + public final CallableStatement prepareCall(String sql, int resultSetType, int concurrency, int holdability) throws SQLException { checkClosed(); try { - CallableStatement proxyCallableStatement = ProxyFactory.getProxyCallableStatement(this, delegate.prepareCall(sql, resultSetType, resultSetConcurrency, - resultSetHoldability)); - return trackStatement(proxyCallableStatement); + CallableStatement pcs = ProxyFactory.getProxyCallableStatement(this, delegate.prepareCall(sql, resultSetType, concurrency, holdability)); + return trackStatement(pcs); } catch (SQLException e) { throw checkException(e); @@ -339,12 +336,11 @@ public abstract class ConnectionProxy implements IHikariConnectionProxy /** {@inheritDoc} */ @Override - public final PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException + public final PreparedStatement prepareStatement(String sql, int resultSetType, int concurrency) throws SQLException { checkClosed(); try { - PreparedStatement proxyPreparedStatement = ProxyFactory.getProxyPreparedStatement(this, - delegate.prepareStatement(sql, resultSetType, resultSetConcurrency)); + PreparedStatement proxyPreparedStatement = ProxyFactory.getProxyPreparedStatement(this, delegate.prepareStatement(sql, resultSetType, concurrency)); return trackStatement(proxyPreparedStatement); } catch (SQLException e) { @@ -354,13 +350,11 @@ public abstract class ConnectionProxy implements IHikariConnectionProxy /** {@inheritDoc} */ @Override - public final PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException + public final PreparedStatement prepareStatement(String sql, int resultSetType, int concurrency, int holdability) throws SQLException { checkClosed(); try { - PreparedStatement proxyPreparedStatement = ProxyFactory.getProxyPreparedStatement(this, delegate.prepareStatement(sql, resultSetType, - resultSetConcurrency, - resultSetHoldability)); + PreparedStatement proxyPreparedStatement = ProxyFactory.getProxyPreparedStatement(this, delegate.prepareStatement(sql, resultSetType, concurrency, holdability)); return trackStatement(proxyPreparedStatement); } catch (SQLException e) { diff --git a/hikaricp/src/main/java/com/zaxxer/hikari/proxy/ConnectionProxy.java b/hikaricp/src/main/java/com/zaxxer/hikari/proxy/ConnectionProxy.java index ffe28b37..eef395eb 100644 --- a/hikaricp/src/main/java/com/zaxxer/hikari/proxy/ConnectionProxy.java +++ b/hikaricp/src/main/java/com/zaxxer/hikari/proxy/ConnectionProxy.java @@ -46,8 +46,8 @@ public abstract class ConnectionProxy implements IHikariConnectionProxy private final HikariPool parentPool; private final PoolBagEntry bagEntry; - private final FastList openStatements; private final LeakTask leakTask; + private FastList openStatements; private boolean forceClose; private boolean isAnythingDirty; @@ -187,21 +187,19 @@ public abstract class ConnectionProxy implements IHikariConnectionProxy leakTask.cancel(); - try { - final int size = openStatements.size(); - if (size > 0) { - for (int i = 0; i < size; i++) { - try { - openStatements.get(i).close(); - } - catch (SQLException e) { - checkException(e); - } + final int size = openStatements.size(); + if (size > 0) { + for (int i = 0; i < size; i++) { + try { + openStatements.get(i).close(); + } + catch (SQLException e) { + checkException(e); } - - openStatements.clear(); } + } + try { if (isAnythingDirty) { resetConnectionState(); } @@ -240,11 +238,11 @@ public abstract class ConnectionProxy implements IHikariConnectionProxy /** {@inheritDoc} */ @Override - public final Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException + public final Statement createStatement(int resultSetType, int concurrency) throws SQLException { checkClosed(); try { - Statement proxyStatement = ProxyFactory.getProxyStatement(this, delegate.createStatement(resultSetType, resultSetConcurrency)); + Statement proxyStatement = ProxyFactory.getProxyStatement(this, delegate.createStatement(resultSetType, concurrency)); return trackStatement(proxyStatement); } catch (SQLException e) { @@ -254,11 +252,11 @@ public abstract class ConnectionProxy implements IHikariConnectionProxy /** {@inheritDoc} */ @Override - public final Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException + public final Statement createStatement(int resultSetType, int concurrency, int holdability) throws SQLException { checkClosed(); try { - Statement proxyStatement = ProxyFactory.getProxyStatement(this, delegate.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability)); + Statement proxyStatement = ProxyFactory.getProxyStatement(this, delegate.createStatement(resultSetType, concurrency, holdability)); return trackStatement(proxyStatement); } catch (SQLException e) { @@ -272,8 +270,8 @@ public abstract class ConnectionProxy implements IHikariConnectionProxy { checkClosed(); try { - CallableStatement proxyCallableStatement = ProxyFactory.getProxyCallableStatement(this, delegate.prepareCall(sql)); - return trackStatement(proxyCallableStatement); + CallableStatement pcs = ProxyFactory.getProxyCallableStatement(this, delegate.prepareCall(sql)); + return trackStatement(pcs); } catch (SQLException e) { throw checkException(e); @@ -282,12 +280,12 @@ public abstract class ConnectionProxy implements IHikariConnectionProxy /** {@inheritDoc} */ @Override - public final CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException + public final CallableStatement prepareCall(String sql, int resultSetType, int concurrency) throws SQLException { checkClosed(); try { - CallableStatement proxyCallableStatement = ProxyFactory.getProxyCallableStatement(this, delegate.prepareCall(sql, resultSetType, resultSetConcurrency)); - return trackStatement(proxyCallableStatement); + CallableStatement pcs = ProxyFactory.getProxyCallableStatement(this, delegate.prepareCall(sql, resultSetType, concurrency)); + return trackStatement(pcs); } catch (SQLException e) { throw checkException(e); @@ -296,13 +294,12 @@ public abstract class ConnectionProxy implements IHikariConnectionProxy /** {@inheritDoc} */ @Override - public final CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException + public final CallableStatement prepareCall(String sql, int resultSetType, int concurrency, int holdability) throws SQLException { checkClosed(); try { - CallableStatement proxyCallableStatement = ProxyFactory.getProxyCallableStatement(this, delegate.prepareCall(sql, resultSetType, resultSetConcurrency, - resultSetHoldability)); - return trackStatement(proxyCallableStatement); + CallableStatement pcs = ProxyFactory.getProxyCallableStatement(this, delegate.prepareCall(sql, resultSetType, concurrency, holdability)); + return trackStatement(pcs); } catch (SQLException e) { throw checkException(e); @@ -339,12 +336,11 @@ public abstract class ConnectionProxy implements IHikariConnectionProxy /** {@inheritDoc} */ @Override - public final PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException + public final PreparedStatement prepareStatement(String sql, int resultSetType, int concurrency) throws SQLException { checkClosed(); try { - PreparedStatement proxyPreparedStatement = ProxyFactory.getProxyPreparedStatement(this, - delegate.prepareStatement(sql, resultSetType, resultSetConcurrency)); + PreparedStatement proxyPreparedStatement = ProxyFactory.getProxyPreparedStatement(this, delegate.prepareStatement(sql, resultSetType, concurrency)); return trackStatement(proxyPreparedStatement); } catch (SQLException e) { @@ -354,13 +350,11 @@ public abstract class ConnectionProxy implements IHikariConnectionProxy /** {@inheritDoc} */ @Override - public final PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException + public final PreparedStatement prepareStatement(String sql, int resultSetType, int concurrency, int holdability) throws SQLException { checkClosed(); try { - PreparedStatement proxyPreparedStatement = ProxyFactory.getProxyPreparedStatement(this, delegate.prepareStatement(sql, resultSetType, - resultSetConcurrency, - resultSetHoldability)); + PreparedStatement proxyPreparedStatement = ProxyFactory.getProxyPreparedStatement(this, delegate.prepareStatement(sql, resultSetType, concurrency, holdability)); return trackStatement(proxyPreparedStatement); } catch (SQLException e) {