Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
fix: support query timeouts exceeding 2147483 seconds (~25 days) (#1224 )
Use long field for timeout to avoid unexpected
"Query timeout must be a value greater than or equals to 0" when query timeout exceeds 2147483
fixes #1223
Loading branch information
@@ -113,7 +113,7 @@
/**
* Timeout (in milliseconds) for a query
*/
protected int timeout = 0 ;
protected long timeout = 0 ;
protected boolean replaceProcessingEnabled = true ;
@@ -518,11 +518,16 @@ public void setEscapeProcessing(boolean enable) throws SQLException {
}
public int getQueryTimeout () throws SQLException {
return getQueryTimeoutMs() / 1000 ;
checkClosed();
long seconds = timeout / 1000 ;
if (seconds >= Integer . MAX_VALUE ) {
return Integer . MAX_VALUE ;
}
return (int ) seconds;
}
public void setQueryTimeout (int seconds ) throws SQLException {
setQueryTimeoutMs(seconds * 1000 );
setQueryTimeoutMs(seconds * 1000L );
}
/**
@@ -532,7 +537,7 @@ public void setQueryTimeout(int seconds) throws SQLException {
* @return the current query timeout limit in milliseconds; 0 = unlimited
* @throws SQLException if a database access error occurs
*/
public int getQueryTimeoutMs () throws SQLException {
public long getQueryTimeoutMs () throws SQLException {
checkClosed();
return timeout;
}
@@ -543,7 +548,7 @@ public int getQueryTimeoutMs() throws SQLException {
* @param millis - the new query timeout limit in milliseconds
* @throws SQLException if a database access error occurs
*/
public void setQueryTimeoutMs (int millis ) throws SQLException {
public void setQueryTimeoutMs (long millis ) throws SQLException {
checkClosed();
if (millis < 0 ) {
@@ -695,6 +695,17 @@ public void testSetQueryTimeout() throws SQLException {
}
}
@Test
public void testLongQueryTimeout () throws SQLException {
Statement stmt = con. createStatement();
stmt. setQueryTimeout(Integer . MAX_VALUE );
Assert . assertEquals(" setQueryTimeout(Integer.MAX_VALUE)" , Integer . MAX_VALUE ,
stmt. getQueryTimeout());
stmt. setQueryTimeout(Integer . MAX_VALUE - 1 );
Assert . assertEquals(" setQueryTimeout(Integer.MAX_VALUE-1)" , Integer . MAX_VALUE - 1 ,
stmt. getQueryTimeout());
}
/**
* Test executes two queries one after another. The first one has timeout of 1ms, and the second
* one does not. The timeout of the first query should not impact the second one.
Toggle all file notes
Toggle all file annotations