Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ public T build() {
}
if (!applied.contains(DataSourceProperty.DRIVER_CLASS_NAME)
&& properties.canSet(DataSourceProperty.DRIVER_CLASS_NAME)
&& this.values.containsKey(DataSourceProperty.URL)) {
String url = this.values.get(DataSourceProperty.URL);
&& applied.contains(DataSourceProperty.URL)) {
String url = properties.get(dataSource, DataSourceProperty.URL);
DatabaseDriver driver = DatabaseDriver.fromJdbcUrl(url);
properties.set(dataSource, DataSourceProperty.DRIVER_CLASS_NAME, driver.getDriverClassName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,20 @@ void buildWhenDerivedFromCustomTypeWithTypeChange() {
assertThat(testSource.getPassword()).isEqualTo("secret");
}

@Test
void buildWhenDerivedFromCustomTypeDeriveDriverClassNameFromDerivedUrl() {
UrlCapableLimitedCustomDataSource dataSource = new UrlCapableLimitedCustomDataSource();
dataSource.setUsername("test");
dataSource.setPassword("secret");
dataSource.setUrl("jdbc:postgresql://localhost:5432/postgres");
DataSourceBuilder<?> builder = DataSourceBuilder.derivedFrom(dataSource).type(SimpleDriverDataSource.class);
SimpleDriverDataSource testSource = (SimpleDriverDataSource) builder.build();
assertThat(testSource.getUsername()).isEqualTo("test");
assertThat(testSource.getUrl()).isEqualTo("jdbc:postgresql://localhost:5432/postgres");
assertThat(testSource.getPassword()).isEqualTo("secret");
assertThat(testSource.getDriver()).isInstanceOf(org.postgresql.Driver.class);
}

@Test // gh-31920
void buildWhenC3P0TypeSpecifiedReturnsExpectedDataSource() {
this.dataSource = DataSourceBuilder.create()
Expand Down Expand Up @@ -620,12 +634,10 @@ void setPassword(String password) {

}

static class CustomDataSource extends LimitedCustomDataSource {
static class UrlCapableLimitedCustomDataSource extends LimitedCustomDataSource {

private String url;

private String driverClassName;

String getUrl() {
return this.url;
}
Expand All @@ -634,6 +646,13 @@ void setUrl(String url) {
this.url = url;
}

}

static class CustomDataSource extends UrlCapableLimitedCustomDataSource {

private String driverClassName;


String getDriverClassName() {
return this.driverClassName;
}
Expand Down