Browse Source

Merge branch '3.4.x'

Closes gh-45992
pull/46001/head
Stéphane Nicoll 8 months ago
parent
commit
943fd348b4
  1. 6
      spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jdbc/DataSourceBuilder.java
  2. 10
      spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jdbc/DataSourceBuilderTests.java

6
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jdbc/DataSourceBuilder.java

@ -508,6 +508,9 @@ public final class DataSourceBuilder<T extends DataSource> { @@ -508,6 +508,9 @@ public final class DataSourceBuilder<T extends DataSource> {
}
private String convertToString(V value) {
if (value == null) {
return null;
}
if (String.class.equals(this.type)) {
return (String) value;
}
@ -712,7 +715,8 @@ public final class DataSourceBuilder<T extends DataSource> { @@ -712,7 +715,8 @@ public final class DataSourceBuilder<T extends DataSource> {
@SuppressWarnings("unchecked")
SimpleDataSourceProperties() {
add(DataSourceProperty.URL, SimpleDriverDataSource::getUrl, SimpleDriverDataSource::setUrl);
add(DataSourceProperty.DRIVER_CLASS_NAME, Class.class, (dataSource) -> dataSource.getDriver().getClass(),
add(DataSourceProperty.DRIVER_CLASS_NAME, Class.class,
(dataSource) -> (dataSource.getDriver() != null) ? dataSource.getDriver().getClass() : null,
SimpleDriverDataSource::setDriverClass);
add(DataSourceProperty.USERNAME, SimpleDriverDataSource::getUsername, SimpleDriverDataSource::setUsername);
add(DataSourceProperty.PASSWORD, SimpleDriverDataSource::getPassword, SimpleDriverDataSource::setPassword);

10
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jdbc/DataSourceBuilderTests.java

@ -358,6 +358,16 @@ class DataSourceBuilderTests { @@ -358,6 +358,16 @@ class DataSourceBuilderTests {
.isThrownBy(() -> DataSourceBuilder.derivedFrom(dataSource).url("example.org").build());
}
@Test
void buildWhenDerivedFromSimpleDriverDataSourceAndDriverNotSetBuilds() {
SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
dataSource.setUsername("test");
dataSource.setPassword("secret");
dataSource.setUrl("jdbc:postgresql://localhost:5432/postgres");
assertThatNoException()
.isThrownBy(() -> DataSourceBuilder.derivedFrom(dataSource).type(SimpleDriverDataSource.class).build());
}
@Test
void buildWhenDerivedFromOracleDataSourceWithPasswordSetReturnsDataSource() throws Exception {
oracle.jdbc.datasource.impl.OracleDataSource dataSource = new oracle.jdbc.datasource.impl.OracleDataSource();

Loading…
Cancel
Save