提交 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
<h1>Change Log</h1>
<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
are now included in the default jar file.
</li><li>Issue 414: for some functions, the parameters were evaluated twice
......
......@@ -84,6 +84,7 @@ public class JdbcConnection extends TraceObject implements Connection {
private Statement executingStatement;
private CompareMode compareMode = CompareMode.getInstance(null, 0);
private CloseWatcher watcher;
private int queryTimeoutCache = -1;
/**
* INTERNAL
......@@ -702,18 +703,21 @@ public class JdbcConnection extends TraceObject implements Connection {
public int getQueryTimeout() throws SQLException {
try {
debugCodeCall("getQueryTimeout");
checkClosed();
getQueryTimeout = prepareCommand("SELECT VALUE FROM INFORMATION_SCHEMA.SETTINGS WHERE NAME=?", getQueryTimeout);
getQueryTimeout.getParameters().get(0).setValue(ValueString.get("QUERY_TIMEOUT"), false);
ResultInterface result = getQueryTimeout.executeQuery(0, false);
result.next();
int queryTimeout = result.currentRow()[0].getInt();
result.close();
if (queryTimeout == 0) {
return 0;
if (queryTimeoutCache == -1) {
checkClosed();
getQueryTimeout = prepareCommand("SELECT VALUE FROM INFORMATION_SCHEMA.SETTINGS WHERE NAME=?", getQueryTimeout);
getQueryTimeout.getParameters().get(0).setValue(ValueString.get("QUERY_TIMEOUT"), false);
ResultInterface result = getQueryTimeout.executeQuery(0, false);
result.next();
int queryTimeout = result.currentRow()[0].getInt();
result.close();
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 (queryTimeout + 999) / 1000;
return queryTimeoutCache;
} catch (Exception e) {
throw logAndConvert(e);
}
......
......@@ -521,6 +521,10 @@ public class JdbcStatement extends TraceObject implements Statement {
* Gets the current query timeout in seconds.
* This method will return 0 if no query timeout is set.
* 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
* @throws SQLException if this object is closed
......@@ -536,14 +540,13 @@ public class JdbcStatement extends TraceObject implements Statement {
}
/**
* Sets the current query timeout in seconds. Calling this method will
* commit an open transaction, even if the value is the same as before.
* Changing the value will affect all statements of this connection. This
* method does not commit a transaction, and rolling back a transaction does
* not affect this setting.
* Sets the current query timeout in seconds.
* Changing the value will affect all statements of this connection.
* This method does not commit a transaction,
* and rolling back a transaction does not affect this setting.
*
* @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
*/
public void setQueryTimeout(int seconds) throws SQLException {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论