From b39c9c9221718cda4a0d3689c9e739e690ec5c5e Mon Sep 17 00:00:00 2001 From: franz1981 Date: Fri, 30 Oct 2020 17:27:50 +0100 Subject: [PATCH] ARTEMIS-2823 Apply default datasource configs if not overridden --- .../storage/DatabaseStorageConfiguration.java | 35 +++++++++++++------ 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/storage/DatabaseStorageConfiguration.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/storage/DatabaseStorageConfiguration.java index 8ea933e7ce..ebd824d921 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/storage/DatabaseStorageConfiguration.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/storage/DatabaseStorageConfiguration.java @@ -152,19 +152,32 @@ public class DatabaseStorageConfiguration implements StoreConfiguration { private DataSource getDataSource() { if (dataSource == null) { // the next settings are going to be applied only if the datasource is the default one - if (dataSourceProperties.isEmpty() && ActiveMQDefaultConfiguration.getDefaultDataSourceClassName().equals(dataSourceClassName)) { - addDataSourceProperty("driverClassName", jdbcDriverClassName); - addDataSourceProperty("url", jdbcConnectionUrl); - if (jdbcUser != null) { - addDataSourceProperty("username", jdbcUser); + if (ActiveMQDefaultConfiguration.getDefaultDataSourceClassName().equals(dataSourceClassName)) { + // these default settings will be applied only if a custom configuration won't override them + if (!dataSourceProperties.containsKey("driverClassName")) { + addDataSourceProperty("driverClassName", jdbcDriverClassName); } - if (jdbcPassword != null) { - addDataSourceProperty("password", jdbcPassword); + if (!dataSourceProperties.containsKey("url")) { + addDataSourceProperty("url", jdbcConnectionUrl); + } + if (!dataSourceProperties.containsKey("username")) { + if (jdbcUser != null) { + addDataSourceProperty("username", jdbcUser); + } + } + if (!dataSourceProperties.containsKey("password")) { + if (jdbcPassword != null) { + addDataSourceProperty("password", jdbcPassword); + } + } + if (!dataSourceProperties.containsKey("maxTotal")) { + // Let the pool to have unbounded number of connections by default to prevent connection starvation + addDataSourceProperty("maxTotal", "-1"); + } + if (!dataSourceProperties.containsKey("poolPreparedStatements")) { + // Let the pool to have unbounded number of cached prepared statements to save the initialization cost + addDataSourceProperty("poolPreparedStatements", "true"); } - // Let the pool to have unbounded number of connections by default to prevent connection starvation - addDataSourceProperty("maxTotal", "-1"); - // Let the pool to have unbounded number of cached prepared statements to save the initialization cost - addDataSourceProperty("poolPreparedStatements", "true"); } dataSource = JDBCDataSourceUtils.getDataSource(dataSourceClassName, dataSourceProperties); }