Mercurial > hg > monetdb-java
comparison 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 |
comparison
equal
deleted
inserted
replaced
344:8985d2409c10 | 345:45155894aece |
---|---|
1295 | 1295 |
1296 // ping monetdb server using query: select 1; | 1296 // ping monetdb server using query: select 1; |
1297 Statement stmt = null; | 1297 Statement stmt = null; |
1298 ResultSet rs = null; | 1298 ResultSet rs = null; |
1299 boolean isValid = false; | 1299 boolean isValid = false; |
1300 int original_timeout = 0; | 1300 final int original_timeout = this.lastSetQueryTimeout; |
1301 try { | 1301 try { |
1302 stmt = createStatement(); | 1302 stmt = createStatement(); |
1303 if (stmt != null) { | 1303 if (stmt != null) { |
1304 original_timeout = stmt.getQueryTimeout(); | |
1305 if (timeout > 0 && original_timeout != timeout) { | 1304 if (timeout > 0 && original_timeout != timeout) { |
1306 // we need to change the requested timeout for this test query | 1305 // we need to change the requested timeout for this test query |
1307 stmt.setQueryTimeout(timeout); | 1306 stmt.setQueryTimeout(timeout); |
1308 } | 1307 } |
1309 rs = stmt.executeQuery("SELECT 1"); | 1308 rs = stmt.executeQuery("SELECT 1"); |
1320 // SQLState = 25005 | 1319 // SQLState = 25005 |
1321 isValid = true; | 1320 isValid = true; |
1322 } | 1321 } |
1323 /* ignore stmt errors/exceptions, we are only testing if the connection is still alive and usable */ | 1322 /* ignore stmt errors/exceptions, we are only testing if the connection is still alive and usable */ |
1324 } finally { | 1323 } finally { |
1325 /* restore the original server timeout value, whenever an Exception has occurred or not */ | 1324 /* when changed, reset the original server timeout value on the server */ |
1326 if (timeout > 0 && original_timeout != timeout) { | 1325 if (timeout > 0 && original_timeout != this.lastSetQueryTimeout) { |
1326 this.lastSetQueryTimeout = original_timeout; | |
1327 Statement stmt2 = null; | 1327 Statement stmt2 = null; |
1328 this.lastSetQueryTimeout = original_timeout; | |
1329 try { | 1328 try { |
1330 /* we have to set in the server explicitly, because the test 'queryTimeout != connection.lastSetQueryTimeout' | 1329 /* we have to set in the server explicitly, because the test 'queryTimeout != connection.lastSetQueryTimeout' |
1331 on 'internalExecute' won't pass and the server won't be set back */ | 1330 on MonetStatement.internalExecute(sql) won't pass and the server won't be set back */ |
1332 stmt2 = this.createStatement(); | 1331 stmt2 = this.createStatement(); |
1333 stmt2.execute("CALL \"sys\".\"settimeout\"(" + this.lastSetQueryTimeout + ")"); | 1332 stmt2.execute("CALL \"sys\".\"settimeout\"(" + this.lastSetQueryTimeout + ")"); |
1334 } catch (SQLException se) { | 1333 } catch (SQLException se) { |
1335 String msg = se.getMessage(); | 1334 /* ignore stmt errors/exceptions, we are only testing if the connection is still alive and usable */ |
1336 if (msg != null && msg.equalsIgnoreCase("Current transaction is aborted (please ROLLBACK)")) { | |
1337 isValid = true; | |
1338 } | |
1339 } finally { | 1335 } finally { |
1340 closeResultsetStatement(null, stmt2); | 1336 closeResultsetStatement(null, stmt2); |
1341 } | 1337 } |
1342 } | 1338 } |
1343 closeResultsetStatement(rs, stmt); | 1339 closeResultsetStatement(rs, stmt); |