From 0ece2ec18ae6938c646be05989bec50d2707f0ee Mon Sep 17 00:00:00 2001 From: Brett Wooldridge Date: Sun, 12 Jan 2014 18:50:16 +0900 Subject: [PATCH] Restore rollback(), change ThreadLocal isClosed back to volatile boolean. --- .../zaxxer/hikari/proxy/ConnectionProxy.java | 38 ++++++++----------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/core/src/main/java/com/zaxxer/hikari/proxy/ConnectionProxy.java b/core/src/main/java/com/zaxxer/hikari/proxy/ConnectionProxy.java index 37a36aa3..a69daada 100644 --- a/core/src/main/java/com/zaxxer/hikari/proxy/ConnectionProxy.java +++ b/core/src/main/java/com/zaxxer/hikari/proxy/ConnectionProxy.java @@ -45,7 +45,7 @@ public abstract class ConnectionProxy implements IHikariConnectionProxy private final ArrayList openStatements; private final HikariPool parentPool; - private final ThreadLocal isClosed; + private volatile boolean isClosed; private final long creationTime; private boolean forceClose; @@ -74,12 +74,6 @@ public abstract class ConnectionProxy implements IHikariConnectionProxy creationTime = lastAccess = System.currentTimeMillis(); openStatements = new ArrayList(64); - isClosed = new ThreadLocal() { - protected Boolean initialValue() - { - return Boolean.FALSE; - } - }; } public final void unregisterStatement(Object statement) @@ -87,7 +81,7 @@ public abstract class ConnectionProxy implements IHikariConnectionProxy // If the connection is not closed. If it is closed, it means this is being // called back as a result of the close() method below in which case we // will clear the openStatements collection en mass. - if (!isClosed.get()) + if (!isClosed) { openStatements.remove(statement); } @@ -110,7 +104,7 @@ public abstract class ConnectionProxy implements IHikariConnectionProxy public final void unclose() { - isClosed.set(false); + isClosed = false; } public final void realClose() throws SQLException @@ -144,7 +138,7 @@ public abstract class ConnectionProxy implements IHikariConnectionProxy protected final void checkClosed() throws SQLException { - if (isClosed.get()) + if (isClosed) { throw new SQLException("Connection is closed"); } @@ -188,19 +182,19 @@ public abstract class ConnectionProxy implements IHikariConnectionProxy } } -// if (!getAutoCommit()) -// { -// rollback(); -// } + if (!getAutoCommit()) + { + rollback(); + } + } + catch (SQLException e) + { + checkException(e); + throw e; } -// catch (SQLException e) -// { -// checkException(e); -// throw e; -// } finally { - isClosed.set(true); + isClosed = true; openStatements.clear(); parentPool.releaseConnection(this); } @@ -210,7 +204,7 @@ public abstract class ConnectionProxy implements IHikariConnectionProxy /** {@inheritDoc} */ public boolean isClosed() throws SQLException { - return isClosed.get(); + return isClosed; } /** {@inheritDoc} */ @@ -396,7 +390,7 @@ public abstract class ConnectionProxy implements IHikariConnectionProxy /** {@inheritDoc} */ public boolean isValid(int timeout) throws SQLException { - if (isClosed.get()) + if (isClosed) { return false; }