Skip to content

Commit

Permalink
Add method so that dataSourceProperties's keys are not rewritten to…
Browse files Browse the repository at this point in the history
… kebab-case.
  • Loading branch information
Christophe Roudet committed Jan 22, 2020
1 parent 29a2848 commit f034238
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@
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 java.util.Properties;

import javax.annotation.PostConstruct;

/**
Expand Down Expand Up @@ -164,4 +169,13 @@ public String getJndiName() {
public void setJndiName(String jndiName) {
setDataSourceJNDI(jndiName);
}

public void setDataSourceProperties(@MapFormat(transformation = MapFormat.MapTransformation.FLAT, keyFormat = StringConvention.RAW) Map<String, ?> dsProperties) {
super.getDataSourceProperties().putAll(dsProperties);
}

@Override
public void setDataSourceProperties(Properties dsProperties) {
// otherwise properties will be added twice
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

}

0 comments on commit f034238

Please sign in to comment.