diff src/main/java/nl/cwi/monetdb/jdbc/MonetConnection.java @ 345:45155894aece

Remove catch code from finally part where original timeout is reset on server. Simplify code: stmt.getQueryTimeout() always returns this.lastSetQueryTimeout so use it directly.
author Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
date Wed, 06 Nov 2019 15:09:40 +0100 (2019-11-06)
parents 48ee2ca98975
children bcb9a99d399d
line wrap: on
line diff
--- a/src/main/java/nl/cwi/monetdb/jdbc/MonetConnection.java
+++ b/src/main/java/nl/cwi/monetdb/jdbc/MonetConnection.java
@@ -1297,11 +1297,10 @@ public class MonetConnection
 		Statement stmt = null;
 		ResultSet rs = null;
 		boolean isValid = false;
-		int original_timeout = 0;
+		final int original_timeout = this.lastSetQueryTimeout;
 		try {
 			stmt = createStatement();
 			if (stmt != null) {
-				original_timeout = stmt.getQueryTimeout();
 				if (timeout > 0 && original_timeout != timeout) {
 					// we need to change the requested timeout for this test query
 					stmt.setQueryTimeout(timeout);
@@ -1322,20 +1321,17 @@ public class MonetConnection
 			}
 			/* ignore stmt errors/exceptions, we are only testing if the connection is still alive and usable */
 		} finally {
-			/* restore the original server timeout value, whenever an Exception has occurred or not */
-			if (timeout > 0 && original_timeout != timeout) {
+			/* when changed, reset the original server timeout value on the server */
+			if (timeout > 0 && original_timeout != this.lastSetQueryTimeout) {
+				this.lastSetQueryTimeout = original_timeout;
 				Statement stmt2 = null;
-				this.lastSetQueryTimeout = original_timeout;
 				try {
 					/* we have to set in the server explicitly, because the test 'queryTimeout != connection.lastSetQueryTimeout' 
-					   on 'internalExecute' won't pass and the server won't be set back */
+					   on MonetStatement.internalExecute(sql) won't pass and the server won't be set back */
 					stmt2 = this.createStatement();
 					stmt2.execute("CALL \"sys\".\"settimeout\"(" + this.lastSetQueryTimeout + ")");
 				} catch (SQLException se) {
-					String msg = se.getMessage();
-					if (msg != null && msg.equalsIgnoreCase("Current transaction is aborted (please ROLLBACK)")) {
-						isValid = true;
-					}
+					/* ignore stmt errors/exceptions, we are only testing if the connection is still alive and usable */
 				} finally {
 					closeResultsetStatement(null, stmt2);
 				}