Merge branch '3.4.x'

Closes gh-44996
This commit is contained in:
Andy Wilkinson
2025-04-04 08:53:42 +01:00
2 changed files with 13 additions and 1 deletions

View File

@@ -191,7 +191,10 @@ public final class DataSourceBuilder<T extends DataSource> {
&& 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());
String driverClassName = driver.getDriverClassName();
if (driverClassName != null) {
properties.set(dataSource, DataSourceProperty.DRIVER_CLASS_NAME, driver.getDriverClassName());
}
}
return dataSource;
}

View File

@@ -522,6 +522,15 @@ class DataSourceBuilderTests {
assertThat(viburDataSource.getDriverClassName()).isEqualTo("com.example.Driver");
}
@Test
void buildWhenJdbcUrlIsFromUnknownDriverLeavesDriverClassNameUnset() {
this.dataSource = DataSourceBuilder.create()
.url("jdbc:example://localhost:1234/example")
.type(HikariDataSource.class)
.build();
assertThat(((HikariDataSource) this.dataSource).getDriverClassName()).isNull();
}
private DataSource wrap(DataSource target) {
return new DataSourceWrapper(target);
}