提交 b1edabaa authored 作者: Thomas Mueller's avatar Thomas Mueller

Statement.getQueryTimeout(): only the first call to this method will query the database.

上级 74b86ad8
...@@ -18,7 +18,11 @@ Change Log ...@@ -18,7 +18,11 @@ Change Log
<h1>Change Log</h1> <h1>Change Log</h1>
<h2>Next Version (unreleased)</h2> <h2>Next Version (unreleased)</h2>
<ul><li>Issue 416: PreparedStatement.setNString throws AbstractMethodError. <ul><li>Statement.getQueryTimeout(): only the first call to this method will query the database.
If the query timeout was changed in another way than calling setQueryTimeout,
this method will always return the last value. This was changed because Hibernate
calls getQueryTimeout() a lot.
</li><li>Issue 416: PreparedStatement.setNString throws AbstractMethodError.
All implemented JDBC 4 methods that don't break compatiblity with Java 5 All implemented JDBC 4 methods that don't break compatiblity with Java 5
are now included in the default jar file. are now included in the default jar file.
</li><li>Issue 414: for some functions, the parameters were evaluated twice </li><li>Issue 414: for some functions, the parameters were evaluated twice
......
...@@ -84,6 +84,7 @@ public class JdbcConnection extends TraceObject implements Connection { ...@@ -84,6 +84,7 @@ public class JdbcConnection extends TraceObject implements Connection {
private Statement executingStatement; private Statement executingStatement;
private CompareMode compareMode = CompareMode.getInstance(null, 0); private CompareMode compareMode = CompareMode.getInstance(null, 0);
private CloseWatcher watcher; private CloseWatcher watcher;
private int queryTimeoutCache = -1;
/** /**
* INTERNAL * INTERNAL
...@@ -702,18 +703,21 @@ public class JdbcConnection extends TraceObject implements Connection { ...@@ -702,18 +703,21 @@ public class JdbcConnection extends TraceObject implements Connection {
public int getQueryTimeout() throws SQLException { public int getQueryTimeout() throws SQLException {
try { try {
debugCodeCall("getQueryTimeout"); debugCodeCall("getQueryTimeout");
checkClosed(); if (queryTimeoutCache == -1) {
getQueryTimeout = prepareCommand("SELECT VALUE FROM INFORMATION_SCHEMA.SETTINGS WHERE NAME=?", getQueryTimeout); checkClosed();
getQueryTimeout.getParameters().get(0).setValue(ValueString.get("QUERY_TIMEOUT"), false); getQueryTimeout = prepareCommand("SELECT VALUE FROM INFORMATION_SCHEMA.SETTINGS WHERE NAME=?", getQueryTimeout);
ResultInterface result = getQueryTimeout.executeQuery(0, false); getQueryTimeout.getParameters().get(0).setValue(ValueString.get("QUERY_TIMEOUT"), false);
result.next(); ResultInterface result = getQueryTimeout.executeQuery(0, false);
int queryTimeout = result.currentRow()[0].getInt(); result.next();
result.close(); int queryTimeout = result.currentRow()[0].getInt();
if (queryTimeout == 0) { result.close();
return 0; if (queryTimeout != 0) {
// round to the next second, otherwise 999 millis would return 0 seconds
queryTimeout = (queryTimeout + 999) / 1000;
}
queryTimeoutCache = queryTimeout;
} }
// round to the next second, otherwise 999 millis would return 0 seconds return queryTimeoutCache;
return (queryTimeout + 999) / 1000;
} catch (Exception e) { } catch (Exception e) {
throw logAndConvert(e); throw logAndConvert(e);
} }
......
...@@ -521,6 +521,10 @@ public class JdbcStatement extends TraceObject implements Statement { ...@@ -521,6 +521,10 @@ public class JdbcStatement extends TraceObject implements Statement {
* Gets the current query timeout in seconds. * Gets the current query timeout in seconds.
* This method will return 0 if no query timeout is set. * This method will return 0 if no query timeout is set.
* The result is rounded to the next second. * The result is rounded to the next second.
* For performance reasons, only the first call to this method
* will query the database. If the query timeout was changed in another
* way than calling setQueryTimeout, this method will always return
* the last value.
* *
* @return the timeout in seconds * @return the timeout in seconds
* @throws SQLException if this object is closed * @throws SQLException if this object is closed
...@@ -536,14 +540,13 @@ public class JdbcStatement extends TraceObject implements Statement { ...@@ -536,14 +540,13 @@ public class JdbcStatement extends TraceObject implements Statement {
} }
/** /**
* Sets the current query timeout in seconds. Calling this method will * Sets the current query timeout in seconds.
* commit an open transaction, even if the value is the same as before. * Changing the value will affect all statements of this connection.
* Changing the value will affect all statements of this connection. This * This method does not commit a transaction,
* method does not commit a transaction, and rolling back a transaction does * and rolling back a transaction does not affect this setting.
* not affect this setting.
* *
* @param seconds the timeout in seconds - 0 means no timeout, values * @param seconds the timeout in seconds - 0 means no timeout, values
* smaller 0 will throw an exception * smaller 0 will throw an exception
* @throws SQLException if this object is closed * @throws SQLException if this object is closed
*/ */
public void setQueryTimeout(int seconds) throws SQLException { public void setQueryTimeout(int seconds) throws SQLException {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论