GUACAMOLE-926: Disable batch executor for SQL Server JDBC extension - it doesn't work.

This commit is contained in:
James Muehlner
2023-05-11 00:12:43 +00:00
parent e91d5a99ee
commit c4e6b046ae
3 changed files with 38 additions and 4 deletions

View File

@@ -127,10 +127,11 @@ 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
bindConfigurationSetting(configuration -> { if (environment.shouldUseBatchExecutor())
configuration.setDefaultExecutorType(ExecutorType.BATCH); bindConfigurationSetting(configuration -> {
}); configuration.setDefaultExecutorType(ExecutorType.BATCH);
});
// Add MyBatis mappers // Add MyBatis mappers
addMapperClass(ConnectionMapper.class); addMapperClass(ConnectionMapper.class);

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

@@ -295,6 +295,21 @@ 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 * Returns true if all server certificates should be trusted, including
* those signed by an unknown certificate authority, such as self-signed * those signed by an unknown certificate authority, such as self-signed