From 88ca0c3f547569d174736783b3065d85e0202281 Mon Sep 17 00:00:00 2001 From: Cheena Malhotra Date: Tue, 12 Mar 2019 09:21:22 -0700 Subject: [PATCH 1/4] Fix | Fix SQLServerConnection.abort() API behavior --- .../microsoft/sqlserver/jdbc/SQLServerConnection.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java index 20cb35c99..5b896d483 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java @@ -3192,10 +3192,7 @@ public void abort(Executor executor) throws SQLException { } } - setState(State.Closed); - - if (null != tdsChannel && null != executor) - executor.execute(() -> tdsChannel.close()); + executor.execute(() -> closeInternal()); loggerExternal.exiting(getClassNameLogging(), "abort"); } @@ -3203,7 +3200,11 @@ public void abort(Executor executor) throws SQLException { @Override public void close() throws SQLServerException { loggerExternal.entering(getClassNameLogging(), "close"); + closeInternal(); + loggerExternal.exiting(getClassNameLogging(), "close"); + } + private void closeInternal() { // Always report the connection as closed for any further use, no matter // what happens when we try to clean up the physical resources associated // with the connection. @@ -3232,8 +3233,6 @@ public void close() throws SQLServerException { cleanupPreparedStatementDiscardActions(); ActivityCorrelator.cleanupActivityId(); - - loggerExternal.exiting(getClassNameLogging(), "close"); } // This function is used by the proxy for notifying the pool manager that this connection proxy is closed From 1264e176da59e077ca94528678a15310b7663da0 Mon Sep 17 00:00:00 2001 From: Cheena Malhotra Date: Tue, 12 Mar 2019 09:28:31 -0700 Subject: [PATCH 2/4] Method name changes --- .../sqlserver/jdbc/SQLServerConnection.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java index 5b896d483..6c0e4eba7 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java @@ -3192,7 +3192,12 @@ public void abort(Executor executor) throws SQLException { } } - executor.execute(() -> closeInternal()); + // Always report the connection as closed for any further use, no matter + // what happens when we try to clean up the physical resources associated + // with the connection using executor. + setState(State.Closed); + + executor.execute(() -> clearConnectionResources()); loggerExternal.exiting(getClassNameLogging(), "abort"); } @@ -3200,16 +3205,18 @@ public void abort(Executor executor) throws SQLException { @Override public void close() throws SQLServerException { loggerExternal.entering(getClassNameLogging(), "close"); - closeInternal(); - loggerExternal.exiting(getClassNameLogging(), "close"); - } - private void closeInternal() { // Always report the connection as closed for any further use, no matter // what happens when we try to clean up the physical resources associated // with the connection. setState(State.Closed); + + clearConnectionResources(); + + loggerExternal.exiting(getClassNameLogging(), "close"); + } + private void clearConnectionResources() { if (sharedTimer != null) { sharedTimer.removeRef(); sharedTimer = null; From 1007712d247add91f6ddd7a7136a91f695554041 Mon Sep 17 00:00:00 2001 From: Cheena Malhotra Date: Tue, 12 Mar 2019 10:38:57 -0700 Subject: [PATCH 3/4] Null Executor check --- .../sqlserver/jdbc/SQLServerConnection.java | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java index 6c0e4eba7..0faa627f2 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java @@ -3169,16 +3169,10 @@ public void rollback() throws SQLServerException { public void abort(Executor executor) throws SQLException { loggerExternal.entering(getClassNameLogging(), "abort", executor); - // nop if connection is closed + // no-op if connection is closed if (isClosed()) return; - if (null == executor) { - MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_invalidArgument")); - Object[] msgArgs = {"executor"}; - SQLServerException.makeFromDriverError(null, null, form.format(msgArgs), null, false); - } - // check for callAbort permission SecurityManager secMgr = System.getSecurityManager(); if (secMgr != null) { @@ -3191,13 +3185,19 @@ public void abort(Executor executor) throws SQLException { SQLServerException.makeFromDriverError(this, this, form.format(msgArgs), null, true); } } + if (null == executor) { + MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_invalidArgument")); + Object[] msgArgs = {"executor"}; + SQLServerException.makeFromDriverError(null, null, form.format(msgArgs), null, false); + } else { - // Always report the connection as closed for any further use, no matter - // what happens when we try to clean up the physical resources associated - // with the connection using executor. - setState(State.Closed); + // Always report the connection as closed for any further use, no matter + // what happens when we try to clean up the physical resources associated + // with the connection using executor. + setState(State.Closed); - executor.execute(() -> clearConnectionResources()); + executor.execute(() -> clearConnectionResources()); + } loggerExternal.exiting(getClassNameLogging(), "abort"); } @@ -3210,7 +3210,7 @@ public void close() throws SQLServerException { // what happens when we try to clean up the physical resources associated // with the connection. setState(State.Closed); - + clearConnectionResources(); loggerExternal.exiting(getClassNameLogging(), "close"); From 9dbda5f070143ca530cd253236e23d9fa1e5ac2f Mon Sep 17 00:00:00 2001 From: Cheena Malhotra Date: Wed, 13 Mar 2019 11:23:40 -0700 Subject: [PATCH 4/4] Multi-line warnings --- .../sqlserver/jdbc/SQLServerConnection.java | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java index 0faa627f2..9e54f067a 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java @@ -3191,9 +3191,10 @@ public void abort(Executor executor) throws SQLException { SQLServerException.makeFromDriverError(null, null, form.format(msgArgs), null, false); } else { - // Always report the connection as closed for any further use, no matter - // what happens when we try to clean up the physical resources associated - // with the connection using executor. + /* + * Always report the connection as closed for any further use, no matter what happens when we try to clean + * up the physical resources associated with the connection using executor. + */ setState(State.Closed); executor.execute(() -> clearConnectionResources()); @@ -3206,9 +3207,10 @@ public void abort(Executor executor) throws SQLException { public void close() throws SQLServerException { loggerExternal.entering(getClassNameLogging(), "close"); - // Always report the connection as closed for any further use, no matter - // what happens when we try to clean up the physical resources associated - // with the connection. + /* + * Always report the connection as closed for any further use, no matter what happens when we try to clean up + * the physical resources associated with the connection. + */ setState(State.Closed); clearConnectionResources(); @@ -3222,9 +3224,10 @@ private void clearConnectionResources() { sharedTimer = null; } - // Close the TDS channel. When the channel is closed, the server automatically - // rolls back any pending transactions and closes associated resources like - // prepared handles. + /* + * Close the TDS channel. When the channel is closed, the server automatically rolls back any pending + * transactions and closes associated resources like prepared handles. + */ if (null != tdsChannel) { tdsChannel.close(); }