Skip to content

Commit

Permalink
Fix named datasource handling for dev-services
Browse files Browse the repository at this point in the history
Because of how the Quarkus Runtime Config objects are populated
for map fields (like the named datasources), it so happened
that when a user configured a jdbc property for a named datasource,
the DevServices provided URL for that datasource was not ending
up in DataSourceJdbcRuntimeConfig.

Fixes: quarkusio#21387
  • Loading branch information
geoand committed Dec 1, 2021
1 parent d6d3a91 commit 5494549
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,29 +51,39 @@ public Predicate<String> getCheckConfiguredFunction() {
public static DevServicesDatasourceConfigurationHandlerBuildItem jdbc(String dbKind) {
return new DevServicesDatasourceConfigurationHandlerBuildItem(dbKind,
new BiFunction<String, DevServicesDatasourceProvider.RunningDevServicesDatasource, Map<String, String>>() {

@Override
public Map<String, String> apply(String dsName,
DevServicesDatasourceProvider.RunningDevServicesDatasource runningDevDb) {
if (dsName == null) {
return Collections.singletonMap("quarkus.datasource.jdbc.url", runningDevDb.getUrl());
} else {
return Collections.singletonMap("quarkus.datasource.\"" + dsName + "\".jdbc.url",
runningDevDb.getUrl());
// we use quoted and unquoted versions because depending on whether a user configured other JDBC properties
// one of the URLs may be ignored
// see https://github.com/quarkusio/quarkus/issues/21387
return Map.of(
datasourceURLPropName(dsName), runningDevDb.getUrl(),
datasourceURLPropName("\"" + dsName + "\""), runningDevDb.getUrl());
}
}

}, new Predicate<String>() {
@Override
public boolean test(String dsName) {
if (dsName == null) {
return ConfigUtils.isPropertyPresent("quarkus.datasource.jdbc.url");
} else {
return ConfigUtils.isPropertyPresent("quarkus.datasource.\"" + dsName + "\".jdbc.url") ||
ConfigUtils.isPropertyPresent("quarkus.datasource." + dsName + ".jdbc.url");
return ConfigUtils.isPropertyPresent(datasourceURLPropName(dsName)) ||
ConfigUtils.isPropertyPresent(datasourceURLPropName("\"" + dsName + "\""));
}
}
});
}

private static String datasourceURLPropName(String dsName) {
return String.format("quarkus.datasource.%s.jdbc.url", dsName);
}

public static DevServicesDatasourceConfigurationHandlerBuildItem reactive(String dbKind) {
return new DevServicesDatasourceConfigurationHandlerBuildItem(dbKind,
new BiFunction<String, DevServicesDatasourceProvider.RunningDevServicesDatasource, Map<String, String>>() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
quarkus.datasource.db-kind=h2
quarkus.datasource.jdbc.url=jdbc:h2:mem:default
quarkus.datasource.jdbc.max-size=1

quarkus.datasource.users.db-kind=h2
quarkus.datasource.users.jdbc.url=jdbc:h2:mem:users
quarkus.datasource.users.jdbc.min-size=2

quarkus.datasource.inventory.db-kind=h2
quarkus.datasource.inventory.jdbc.url=jdbc:h2:mem:inventory

quarkus.hibernate-orm.dialect=org.hibernate.dialect.H2Dialect
quarkus.hibernate-orm.database.generation=drop-and-create
Expand Down

0 comments on commit 5494549

Please sign in to comment.