From 3dd96fb049280b0827641e15235b4c6ef858fe4b Mon Sep 17 00:00:00 2001 From: Christophe Roudet Date: Wed, 22 Jan 2020 13:53:31 -0500 Subject: [PATCH] Add method so that `dataSourceProperties`'s keys are not rewritten to kebab-case. --- .../jdbc/hikari/DatasourceConfiguration.java | 8 ++++++ .../hikari/DatasourceConfigurationSpec.groovy | 26 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/jdbc-hikari/src/main/java/io/micronaut/configuration/jdbc/hikari/DatasourceConfiguration.java b/jdbc-hikari/src/main/java/io/micronaut/configuration/jdbc/hikari/DatasourceConfiguration.java index 1b488068c..68e17c9b2 100644 --- a/jdbc-hikari/src/main/java/io/micronaut/configuration/jdbc/hikari/DatasourceConfiguration.java +++ b/jdbc-hikari/src/main/java/io/micronaut/configuration/jdbc/hikari/DatasourceConfiguration.java @@ -19,9 +19,13 @@ import com.zaxxer.hikari.HikariConfig; import io.micronaut.context.annotation.EachProperty; import io.micronaut.context.annotation.Parameter; +import io.micronaut.core.convert.format.MapFormat; +import io.micronaut.core.naming.conventions.StringConvention; import io.micronaut.jdbc.BasicJdbcConfiguration; import io.micronaut.jdbc.CalculatedSettings; +import java.util.Map; + import javax.annotation.PostConstruct; /** @@ -164,4 +168,8 @@ public String getJndiName() { public void setJndiName(String jndiName) { setDataSourceJNDI(jndiName); } + + public void setDataSourceProperties(@MapFormat(transformation = MapFormat.MapTransformation.FLAT, keyFormat = StringConvention.RAW) Map dsProperties) { + super.getDataSourceProperties().putAll(dsProperties); + } } diff --git a/jdbc-hikari/src/test/groovy/io/micronaut/configuration/jdbc/hikari/DatasourceConfigurationSpec.groovy b/jdbc-hikari/src/test/groovy/io/micronaut/configuration/jdbc/hikari/DatasourceConfigurationSpec.groovy index 67a9bdcea..da38077c6 100644 --- a/jdbc-hikari/src/test/groovy/io/micronaut/configuration/jdbc/hikari/DatasourceConfigurationSpec.groovy +++ b/jdbc-hikari/src/test/groovy/io/micronaut/configuration/jdbc/hikari/DatasourceConfigurationSpec.groovy @@ -251,4 +251,30 @@ class DatasourceConfigurationSpec extends Specification { applicationContext.stop() } + void "test data source properties"() { + given: + ApplicationContext applicationContext = new DefaultApplicationContext("test") + applicationContext.environment.addPropertySource(MapPropertySource.of( + 'test', + ['datasources.default.data-source-properties' : ['reWriteBatchInserts' : true, 'anotherOne' : 'value']] + )) + applicationContext.start() + + expect: + applicationContext.containsBean(DataSource) + applicationContext.containsBean(DatasourceConfiguration) + + when: + HikariDataSource dataSource = applicationContext.getBean(DataSource).targetDataSource + + then: + !dataSource.dataSourceProperties.isEmpty() + dataSource.dataSourceProperties.size() == 2 + dataSource.dataSourceProperties.get('reWriteBatchInserts') == true + dataSource.dataSourceProperties.get('anotherOne') == 'value' + + cleanup: + applicationContext.close() + } + }