GUACAMOLE-919: make defaultStatementTimeout an int

More consistent with how socketTimeout.

MyBatis documentation says only positive integers are valid,
and property should not be set otherwise.
So in the case of 0 the property will not be set.
This commit is contained in:
Douglas Heriot
2020-04-02 12:08:00 +11:00
parent 306e1ad3ab
commit 0528ca0564
3 changed files with 13 additions and 7 deletions

View File

@@ -69,7 +69,12 @@ public class PostgreSQLAuthenticationProviderModule implements Module {
myBatisProperties.setProperty("JDBC.autoCommit", "false");
myBatisProperties.setProperty("mybatis.pooled.pingEnabled", "true");
myBatisProperties.setProperty("mybatis.pooled.pingQuery", "SELECT 1");
myBatisProperties.setProperty("mybatis.configuration.defaultStatementTimeout", environment.getPostgreSQLDefaultStatementTimeout());
// Only set if > 0. Underlying backend does not take 0 as not-set.
int defaultStatementTimeout = environment.getPostgreSQLDefaultStatementTimeout();
if(defaultStatementTimeout > 0) {
myBatisProperties.setProperty("mybatis.configuration.defaultStatementTimeout", String.valueOf(defaultStatementTimeout));
}
// Use UTF-8 in database
driverProperties.setProperty("characterEncoding", "UTF-8");

View File

@@ -51,10 +51,10 @@ public class PostgreSQLEnvironment extends JDBCEnvironment {
/**
* The default defaultStatementTimeout (in seconds),
* if POSTGRESQL_DEFAULT_STATEMENT_TIMEOUT is not specified.
* Default to null (no timeout)
* Default to 0 (no timeout, property won't be set)
* https://mybatis.org/mybatis-3/configuration.html
*/
private static final String DEFAULT_DEFAULT_STATEMENT_TIMEOUT = "null";
private static final int DEFAULT_DEFAULT_STATEMENT_TIMEOUT = 0;
/**
* The default socketTimeout (in seconds), if POSTGRESQL_SOCKET_TIMEOUT is not specified.
@@ -267,7 +267,8 @@ public class PostgreSQLEnvironment extends JDBCEnvironment {
/**
* Returns the defaultStatementTimeout set for PostgreSQL connections.
* If unspecified, this will be the default "null" (no timeout)
* If unspecified, this will be the default 0,
* and should not be passed through to the backend.
*
* @return
* The statement timeout (in seconds)
@@ -275,7 +276,7 @@ public class PostgreSQLEnvironment extends JDBCEnvironment {
* @throws GuacamoleException
* If an error occurs while retrieving the property value.
*/
public String getPostgreSQLDefaultStatementTimeout() throws GuacamoleException {
public int getPostgreSQLDefaultStatementTimeout() throws GuacamoleException {
return getProperty(
PostgreSQLGuacamoleProperties.POSTGRESQL_DEFAULT_STATEMENT_TIMEOUT,
DEFAULT_DEFAULT_STATEMENT_TIMEOUT

View File

@@ -98,8 +98,8 @@ public class PostgreSQLGuacamoleProperties {
* Sets the number of seconds the driver will wait for
* a response from the database.
*/
public static final StringGuacamoleProperty
POSTGRESQL_DEFAULT_STATEMENT_TIMEOUT = new StringGuacamoleProperty(){
public static final IntegerGuacamoleProperty
POSTGRESQL_DEFAULT_STATEMENT_TIMEOUT = new IntegerGuacamoleProperty(){
@Override
public String getName() { return "postgresql-default-statement-timeout"; }