GUACAMOLE-926: Merge disabling of batch executor for SQL Server.

This commit is contained in:
Mike Jumper
2023-05-11 08:36:43 -07:00
committed by GitHub
5 changed files with 72 additions and 4 deletions

View File

@@ -127,7 +127,8 @@ public class JDBCAuthenticationProviderModule extends MyBatisModule {
// Transaction factory // Transaction factory
bindTransactionFactoryType(JdbcTransactionFactory.class); bindTransactionFactoryType(JdbcTransactionFactory.class);
// Set the JDBC Auth provider to use batch execution when possible // Set the JDBC Auth provider to use batch execution if enabled
if (environment.shouldUseBatchExecutor())
bindConfigurationSetting(configuration -> { bindConfigurationSetting(configuration -> {
configuration.setDefaultExecutorType(ExecutorType.BATCH); configuration.setDefaultExecutorType(ExecutorType.BATCH);
}); });

View File

@@ -254,4 +254,22 @@ public abstract class JDBCEnvironment extends DelegatingEnvironment {
*/ */
public abstract boolean enforceAccessWindowsForActiveSessions() throws GuacamoleException; public abstract boolean enforceAccessWindowsForActiveSessions() throws GuacamoleException;
/**
* Returns true if the JDBC batch executor should be used by default, false
* otherwise. The batch executor allows repeated updates to be batched
* together for improved performance.
* See https://mybatis.org/mybatis-3/java-api.html#sqlSessions
*
* @return
* true if the batch executor should be used by default, false otherwise.
*/
public boolean shouldUseBatchExecutor() {
// Unless otherwise overwritten due to implementation-specific problems,
// all JDBC extensions should use the batch executor if possible to
// ensure the best performance for repetitive queries
return true;
}
} }

View File

@@ -77,6 +77,10 @@ public class SQLServerAuthenticationProviderModule implements Module {
// Use UTF-8 in database // Use UTF-8 in database
driverProperties.setProperty("characterEncoding", "UTF-8"); driverProperties.setProperty("characterEncoding", "UTF-8");
// Trust unknown server certificates if configured to do so
if (environment.trustAllServerCertificates())
driverProperties.setProperty("trustServerCertificate", "true");
// Retrieve instance name and set it // Retrieve instance name and set it
String instance = environment.getSQLServerInstance(); String instance = environment.getSQLServerInstance();
if (instance != null) if (instance != null)

View File

@@ -295,4 +295,36 @@ public class SQLServerEnvironment extends JDBCEnvironment {
true); true);
} }
@Override
public boolean shouldUseBatchExecutor() {
// The SQL Server driver does not work when batch execution is enabled.
// Specifically, inserts fail with com.microsoft.sqlserver.jdbc.SQLServerException:
// The statement must be executed before any results can be obtained.
// See https://github.com/microsoft/mssql-jdbc/issues/358 for more.
logger.warn(
"JDBC batch executor is disabled for SQL Server Connections. "
+ "Large batched updates may run slower."
);
return false;
}
/**
* Returns true if all server certificates should be trusted, including
* those signed by an unknown certificate authority, such as self-signed
* certificates, or false otherwise.
*
* @throws GuacamoleException
* If an error occurs while retrieving the property value, or if the
* value was not set, as this property is required.
*/
public boolean trustAllServerCertificates() throws GuacamoleException {
// Do not trust unknown certificates unless explicitly enabled
return getProperty(
SQLServerGuacamoleProperties.SQLSERVER_TRUST_ALL_SERVER_CERTIFICATES,
false);
}
} }

View File

@@ -245,4 +245,17 @@ public class SQLServerGuacamoleProperties {
}; };
/**
* Whether or not all server certificates should be trusted, including those
* signed by an unknown certificate authority, such as self-signed
* certificates.
*/
public static final BooleanGuacamoleProperty SQLSERVER_TRUST_ALL_SERVER_CERTIFICATES =
new BooleanGuacamoleProperty() {
@Override
public String getName() { return "sqlserver-trust-all-server-certificates"; }
};
} }