ARTEMIS-2823 Apply default datasource configs if not overridden

This commit is contained in:
franz1981 2020-10-30 17:27:50 +01:00
parent 10debc3478
commit b39c9c9221
1 changed files with 24 additions and 11 deletions

View File

@ -152,20 +152,33 @@ public class DatabaseStorageConfiguration implements StoreConfiguration {
private DataSource getDataSource() { private DataSource getDataSource() {
if (dataSource == null) { if (dataSource == null) {
// the next settings are going to be applied only if the datasource is the default one // the next settings are going to be applied only if the datasource is the default one
if (dataSourceProperties.isEmpty() && ActiveMQDefaultConfiguration.getDefaultDataSourceClassName().equals(dataSourceClassName)) { 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); addDataSourceProperty("driverClassName", jdbcDriverClassName);
}
if (!dataSourceProperties.containsKey("url")) {
addDataSourceProperty("url", jdbcConnectionUrl); addDataSourceProperty("url", jdbcConnectionUrl);
}
if (!dataSourceProperties.containsKey("username")) {
if (jdbcUser != null) { if (jdbcUser != null) {
addDataSourceProperty("username", jdbcUser); addDataSourceProperty("username", jdbcUser);
} }
}
if (!dataSourceProperties.containsKey("password")) {
if (jdbcPassword != null) { if (jdbcPassword != null) {
addDataSourceProperty("password", jdbcPassword); addDataSourceProperty("password", jdbcPassword);
} }
}
if (!dataSourceProperties.containsKey("maxTotal")) {
// Let the pool to have unbounded number of connections by default to prevent connection starvation // Let the pool to have unbounded number of connections by default to prevent connection starvation
addDataSourceProperty("maxTotal", "-1"); addDataSourceProperty("maxTotal", "-1");
}
if (!dataSourceProperties.containsKey("poolPreparedStatements")) {
// Let the pool to have unbounded number of cached prepared statements to save the initialization cost // Let the pool to have unbounded number of cached prepared statements to save the initialization cost
addDataSourceProperty("poolPreparedStatements", "true"); addDataSourceProperty("poolPreparedStatements", "true");
} }
}
dataSource = JDBCDataSourceUtils.getDataSource(dataSourceClassName, dataSourceProperties); dataSource = JDBCDataSourceUtils.getDataSource(dataSourceClassName, dataSourceProperties);
} }
return dataSource; return dataSource;