diff --git a/core/processor/src/main/java/io/quarkus/annotation/processor/generate_doc/ConfigDocItemFinder.java b/core/processor/src/main/java/io/quarkus/annotation/processor/generate_doc/ConfigDocItemFinder.java index 207574ad1ca441..589085573f4d5f 100644 --- a/core/processor/src/main/java/io/quarkus/annotation/processor/generate_doc/ConfigDocItemFinder.java +++ b/core/processor/src/main/java/io/quarkus/annotation/processor/generate_doc/ConfigDocItemFinder.java @@ -236,7 +236,8 @@ private List recursivelyFindConfigItems(Element element, String r } else if (annotationName.equals(ANNOTATION_CONFIG_DOC_DEFAULT)) { defaultValueDoc = annotationMirror.getElementValues().values().iterator().next().getValue().toString(); } else if (annotationName.equals(ANNOTATION_CONFIG_WITH_DEFAULT)) { - defaultValue = annotationMirror.getElementValues().values().iterator().next().getValue().toString(); + defaultValue = annotationMirror.getElementValues().values().isEmpty() ? null + : annotationMirror.getElementValues().values().iterator().next().getValue().toString(); } else if (annotationName.equals(ANNOTATION_CONFIG_WITH_UNNAMED_KEY)) { unnamedMapKey = true; } diff --git a/core/runtime/src/main/java/io/quarkus/runtime/configuration/ConfigUtils.java b/core/runtime/src/main/java/io/quarkus/runtime/configuration/ConfigUtils.java index 3e339a223a01d5..649a612ed84335 100644 --- a/core/runtime/src/main/java/io/quarkus/runtime/configuration/ConfigUtils.java +++ b/core/runtime/src/main/java/io/quarkus/runtime/configuration/ConfigUtils.java @@ -27,8 +27,6 @@ import org.eclipse.microprofile.config.spi.ConfigSourceProvider; import io.quarkus.runtime.LaunchMode; -import io.smallrye.config.ConfigMappingContext; -import io.smallrye.config.ConfigMappingContextCreator; import io.smallrye.config.ConfigSourceInterceptor; import io.smallrye.config.ConfigSourceInterceptorContext; import io.smallrye.config.ConfigSourceInterceptorFactory; @@ -313,16 +311,6 @@ public static Optional getFirstOptionalValue(List propertyNames, return Optional.empty(); } - /** - * Get a config group initialized with default values as specified in the config. - */ - public static T getInitializedConfigGroup(Class configGroup, String mapPath) { - SmallRyeConfig config = ConfigProvider.getConfig().unwrap(SmallRyeConfig.class); - ConfigMappingContext context = ConfigMappingContextCreator.createConfigMappingContext(config); - context.getStringBuilder().replace(0, context.getStringBuilder().length(), mapPath); - return context.constructGroup(configGroup); - } - private static class ConfigBuilderComparator implements Comparator { private static final ConfigBuilderComparator INSTANCE = new ConfigBuilderComparator(); diff --git a/core/runtime/src/main/java/io/smallrye/config/ConfigMappingContextCreator.java b/core/runtime/src/main/java/io/smallrye/config/ConfigMappingContextCreator.java deleted file mode 100644 index bee70f4ad81598..00000000000000 --- a/core/runtime/src/main/java/io/smallrye/config/ConfigMappingContextCreator.java +++ /dev/null @@ -1,16 +0,0 @@ -package io.smallrye.config; - -import io.smallrye.config.ConfigMappingInterface.KebabNamingStrategy; - -/** - * TODO: this is a temporary class, it needs to go away. - */ -@Deprecated(forRemoval = true) -public final class ConfigMappingContextCreator { - - public static ConfigMappingContext createConfigMappingContext(SmallRyeConfig config) { - ConfigMappingContext configMappingContext = new ConfigMappingContext(config); - configMappingContext.applyNamingStrategy(new KebabNamingStrategy()); - return configMappingContext; - } -} diff --git a/extensions/agroal/deployment/src/main/java/io/quarkus/agroal/deployment/AgroalProcessor.java b/extensions/agroal/deployment/src/main/java/io/quarkus/agroal/deployment/AgroalProcessor.java index db29bc1b31f23d..89d2bed8e5c205 100644 --- a/extensions/agroal/deployment/src/main/java/io/quarkus/agroal/deployment/AgroalProcessor.java +++ b/extensions/agroal/deployment/src/main/java/io/quarkus/agroal/deployment/AgroalProcessor.java @@ -312,40 +312,31 @@ private List getAggregatedConfigBu List defaultDbKinds) { List dataSources = new ArrayList<>(); - Optional effectiveDbKind = DefaultDataSourceDbKindBuildItem - .resolve(dataSourcesBuildTimeConfig.defaultDataSource().dbKind(), defaultDbKinds, - dataSourcesBuildTimeConfig.defaultDataSource().devservices().enabled() - .orElse(dataSourcesBuildTimeConfig.namedDataSources().isEmpty()), - curateOutcomeBuildItem); - - if (effectiveDbKind.isPresent()) { - if (dataSourcesJdbcBuildTimeConfig.jdbc().enabled()) { - dataSources.add(new AggregatedDataSourceBuildTimeConfigBuildItem(DataSourceUtil.DEFAULT_DATASOURCE_NAME, - dataSourcesBuildTimeConfig.defaultDataSource(), - dataSourcesJdbcBuildTimeConfig.jdbc(), - effectiveDbKind.get(), - resolveDriver(DataSourceUtil.DEFAULT_DATASOURCE_NAME, effectiveDbKind.get(), - dataSourcesJdbcBuildTimeConfig.jdbc(), jdbcDriverBuildItems))); - } - } - for (Entry entry : dataSourcesBuildTimeConfig.namedDataSources().entrySet()) { + for (Entry entry : dataSourcesBuildTimeConfig.dataSources().entrySet()) { DataSourceJdbcBuildTimeConfig jdbcBuildTimeConfig = dataSourcesJdbcBuildTimeConfig - .getDataSourceJdbcBuildTimeConfig(entry.getKey()); + .dataSources().get(entry.getKey()).jdbc(); if (!jdbcBuildTimeConfig.enabled()) { continue; } - Optional dbKind = DefaultDataSourceDbKindBuildItem + + boolean enableImplicitResolution = DataSourceUtil.isDefault(entry.getKey()) + ? entry.getValue().devservices().enabled().orElse(!dataSourcesBuildTimeConfig.hasNamedDataSources()) + : true; + + Optional effectiveDbKind = DefaultDataSourceDbKindBuildItem .resolve(entry.getValue().dbKind(), defaultDbKinds, - true, + enableImplicitResolution, curateOutcomeBuildItem); - if (!dbKind.isPresent()) { + + if (!effectiveDbKind.isPresent()) { continue; } + dataSources.add(new AggregatedDataSourceBuildTimeConfigBuildItem(entry.getKey(), entry.getValue(), jdbcBuildTimeConfig, - dbKind.get(), - resolveDriver(entry.getKey(), dbKind.get(), jdbcBuildTimeConfig, jdbcDriverBuildItems))); + effectiveDbKind.get(), + resolveDriver(entry.getKey(), effectiveDbKind.get(), jdbcBuildTimeConfig, jdbcDriverBuildItems))); } return dataSources; diff --git a/extensions/agroal/runtime/src/main/java/io/quarkus/agroal/runtime/DataSources.java b/extensions/agroal/runtime/src/main/java/io/quarkus/agroal/runtime/DataSources.java index e992b4dd1bae06..bff38eee02e678 100644 --- a/extensions/agroal/runtime/src/main/java/io/quarkus/agroal/runtime/DataSources.java +++ b/extensions/agroal/runtime/src/main/java/io/quarkus/agroal/runtime/DataSources.java @@ -135,8 +135,8 @@ public AgroalDataSource doCreateDataSource(String dataSourceName) { } DataSourceJdbcBuildTimeConfig dataSourceJdbcBuildTimeConfig = dataSourcesJdbcBuildTimeConfig - .getDataSourceJdbcBuildTimeConfig(dataSourceName); - DataSourceRuntimeConfig dataSourceRuntimeConfig = dataSourcesRuntimeConfig.getDataSourceRuntimeConfig(dataSourceName); + .dataSources().get(dataSourceName).jdbc(); + DataSourceRuntimeConfig dataSourceRuntimeConfig = dataSourcesRuntimeConfig.dataSources().get(dataSourceName); DataSourceJdbcRuntimeConfig dataSourceJdbcRuntimeConfig = dataSourcesJdbcRuntimeConfig .getDataSourceJdbcRuntimeConfig(dataSourceName); diff --git a/extensions/agroal/runtime/src/main/java/io/quarkus/agroal/runtime/DataSourcesJdbcBuildTimeConfig.java b/extensions/agroal/runtime/src/main/java/io/quarkus/agroal/runtime/DataSourcesJdbcBuildTimeConfig.java index b85d4265baa2a3..ed47c6fbff8885 100644 --- a/extensions/agroal/runtime/src/main/java/io/quarkus/agroal/runtime/DataSourcesJdbcBuildTimeConfig.java +++ b/extensions/agroal/runtime/src/main/java/io/quarkus/agroal/runtime/DataSourcesJdbcBuildTimeConfig.java @@ -8,26 +8,24 @@ import io.quarkus.runtime.annotations.ConfigGroup; import io.quarkus.runtime.annotations.ConfigPhase; import io.quarkus.runtime.annotations.ConfigRoot; -import io.quarkus.runtime.configuration.ConfigUtils; import io.smallrye.config.ConfigMapping; +import io.smallrye.config.WithDefaults; import io.smallrye.config.WithParentName; +import io.smallrye.config.WithUnnamedKey; @ConfigMapping(prefix = "quarkus.datasource") @ConfigRoot(phase = ConfigPhase.BUILD_AND_RUN_TIME_FIXED) public interface DataSourcesJdbcBuildTimeConfig { /** - * The default datasource. - */ - DataSourceJdbcBuildTimeConfig jdbc(); - - /** - * Additional named datasources. + * Datasources. */ @ConfigDocSection @ConfigDocMapKey("datasource-name") @WithParentName - Map namedDataSources(); + @WithDefaults + @WithUnnamedKey(DataSourceUtil.DEFAULT_DATASOURCE_NAME) + Map dataSources(); @ConfigGroup public interface DataSourceJdbcOuterNamedBuildTimeConfig { @@ -37,18 +35,4 @@ public interface DataSourceJdbcOuterNamedBuildTimeConfig { */ DataSourceJdbcBuildTimeConfig jdbc(); } - - default DataSourceJdbcBuildTimeConfig getDataSourceJdbcBuildTimeConfig(String dataSourceName) { - if (DataSourceUtil.isDefault(dataSourceName)) { - return jdbc(); - } - - DataSourceJdbcOuterNamedBuildTimeConfig dataSourceJdbcBuildTimeConfig = namedDataSources().get(dataSourceName); - - if (dataSourceJdbcBuildTimeConfig != null) { - return dataSourceJdbcBuildTimeConfig.jdbc(); - } - - return ConfigUtils.getInitializedConfigGroup(DataSourceJdbcBuildTimeConfig.class, "quarkus.datasource.*.jdbc"); - } } diff --git a/extensions/agroal/runtime/src/main/java/io/quarkus/agroal/runtime/DataSourcesJdbcRuntimeConfig.java b/extensions/agroal/runtime/src/main/java/io/quarkus/agroal/runtime/DataSourcesJdbcRuntimeConfig.java index 190f77a462ed4d..a2b406a2dc6ecb 100644 --- a/extensions/agroal/runtime/src/main/java/io/quarkus/agroal/runtime/DataSourcesJdbcRuntimeConfig.java +++ b/extensions/agroal/runtime/src/main/java/io/quarkus/agroal/runtime/DataSourcesJdbcRuntimeConfig.java @@ -2,15 +2,14 @@ import java.util.Map; -import io.quarkus.agroal.runtime.DataSourcesJdbcRuntimeConfig.DataSourceJdbcOuterNamedRuntimeConfig; import io.quarkus.datasource.common.runtime.DataSourceUtil; import io.quarkus.runtime.annotations.ConfigDocMapKey; import io.quarkus.runtime.annotations.ConfigDocSection; import io.quarkus.runtime.annotations.ConfigGroup; import io.quarkus.runtime.annotations.ConfigPhase; import io.quarkus.runtime.annotations.ConfigRoot; -import io.quarkus.runtime.configuration.ConfigUtils; import io.smallrye.config.ConfigMapping; +import io.smallrye.config.WithDefaults; import io.smallrye.config.WithParentName; @ConfigMapping(prefix = "quarkus.datasource") @@ -28,6 +27,7 @@ public interface DataSourcesJdbcRuntimeConfig { @ConfigDocSection @ConfigDocMapKey("datasource-name") @WithParentName + @WithDefaults Map namedDataSources(); @ConfigGroup @@ -44,12 +44,6 @@ default DataSourceJdbcRuntimeConfig getDataSourceJdbcRuntimeConfig(String dataSo return jdbc(); } - DataSourceJdbcOuterNamedRuntimeConfig dataSourceJdbcRuntimeConfig = namedDataSources().get(dataSourceName); - - if (dataSourceJdbcRuntimeConfig != null) { - return dataSourceJdbcRuntimeConfig.jdbc(); - } - - return ConfigUtils.getInitializedConfigGroup(DataSourceJdbcRuntimeConfig.class, "quarkus.datasource.*.jdbc"); + return namedDataSources().get(dataSourceName).jdbc(); } } diff --git a/extensions/datasource/deployment-spi/src/main/java/io/quarkus/datasource/deployment/spi/DevServicesDatasourceProvider.java b/extensions/datasource/deployment-spi/src/main/java/io/quarkus/datasource/deployment/spi/DevServicesDatasourceProvider.java index 3143f78636025f..acc38b97b74c40 100644 --- a/extensions/datasource/deployment-spi/src/main/java/io/quarkus/datasource/deployment/spi/DevServicesDatasourceProvider.java +++ b/extensions/datasource/deployment-spi/src/main/java/io/quarkus/datasource/deployment/spi/DevServicesDatasourceProvider.java @@ -9,7 +9,7 @@ public interface DevServicesDatasourceProvider { RunningDevServicesDatasource startDatabase(Optional username, Optional password, - Optional datasourceName, + String datasourceName, DevServicesDatasourceContainerConfig devServicesDatasourceContainerConfig, LaunchMode launchMode, Optional startupTimeout); diff --git a/extensions/datasource/deployment-spi/src/main/java/io/quarkus/datasource/deployment/spi/DevServicesDatasourceResultBuildItem.java b/extensions/datasource/deployment-spi/src/main/java/io/quarkus/datasource/deployment/spi/DevServicesDatasourceResultBuildItem.java index 2cbd92f923a5b9..cef216e2fa80fc 100644 --- a/extensions/datasource/deployment-spi/src/main/java/io/quarkus/datasource/deployment/spi/DevServicesDatasourceResultBuildItem.java +++ b/extensions/datasource/deployment-spi/src/main/java/io/quarkus/datasource/deployment/spi/DevServicesDatasourceResultBuildItem.java @@ -3,34 +3,36 @@ import java.util.Collections; import java.util.Map; import java.util.Optional; +import java.util.stream.Collectors; import io.quarkus.builder.item.SimpleBuildItem; import io.quarkus.datasource.common.runtime.DataSourceUtil; public final class DevServicesDatasourceResultBuildItem extends SimpleBuildItem { - final DbResult defaultDatasource; - final Map namedDatasources; + final Map dataSources; - public DevServicesDatasourceResultBuildItem(DbResult defaultDatasource, Map namedDatasources) { - this.defaultDatasource = defaultDatasource; - this.namedDatasources = Collections.unmodifiableMap(namedDatasources); + public DevServicesDatasourceResultBuildItem(Map namedDatasources) { + this.dataSources = Collections.unmodifiableMap(namedDatasources); } public DbResult getDefaultDatasource() { - return defaultDatasource; + return dataSources.get(DataSourceUtil.DEFAULT_DATASOURCE_NAME); } public Map getNamedDatasources() { - return namedDatasources; + return dataSources.entrySet().stream() + .filter(e -> !DataSourceUtil.isDefault(e.getKey())) + .collect(Collectors.toUnmodifiableMap(e -> e.getKey(), e -> e.getValue())); + } + + public Map getDatasources() { + return dataSources; } public static DbResult resolve(Optional devDbResultBuildItem, String dataSourceName) { if (devDbResultBuildItem.isPresent()) { - if (dataSourceName.equals(DataSourceUtil.DEFAULT_DATASOURCE_NAME)) { - return devDbResultBuildItem.get().defaultDatasource; - } - return devDbResultBuildItem.get().namedDatasources.get(dataSourceName); + return devDbResultBuildItem.get().dataSources.get(dataSourceName); } return null; } diff --git a/extensions/datasource/deployment/src/main/java/io/quarkus/datasource/deployment/DataSourceBindingProcessor.java b/extensions/datasource/deployment/src/main/java/io/quarkus/datasource/deployment/DataSourceBindingProcessor.java index 3f49ebf186c002..9c3ce3a07b9261 100644 --- a/extensions/datasource/deployment/src/main/java/io/quarkus/datasource/deployment/DataSourceBindingProcessor.java +++ b/extensions/datasource/deployment/src/main/java/io/quarkus/datasource/deployment/DataSourceBindingProcessor.java @@ -1,5 +1,6 @@ package io.quarkus.datasource.deployment; +import io.quarkus.datasource.common.runtime.DataSourceUtil; import io.quarkus.datasource.runtime.DataSourcesBuildTimeConfig; import io.quarkus.deployment.annotations.BuildProducer; import io.quarkus.deployment.annotations.BuildStep; @@ -11,13 +12,13 @@ public class DataSourceBindingProcessor { @BuildStep public void process(DataSourcesBuildTimeConfig config, BuildProducer bindings) { - config.defaultDataSource().dbKind().ifPresent(k -> { - bindings.produce(new ServiceBindingQualifierBuildItem(k, k, DEFAULT_DATASOURCE)); - }); - - config.namedDataSources().forEach((n, c) -> { + config.dataSources().forEach((name, c) -> { c.dbKind().ifPresent(dbKind -> { - bindings.produce(new ServiceBindingQualifierBuildItem(dbKind, n)); + if (DataSourceUtil.isDefault(name)) { + bindings.produce(new ServiceBindingQualifierBuildItem(dbKind, dbKind, DEFAULT_DATASOURCE)); + } else { + bindings.produce(new ServiceBindingQualifierBuildItem(dbKind, name)); + } }); }); } diff --git a/extensions/datasource/deployment/src/main/java/io/quarkus/datasource/deployment/devservices/DevServicesDatasourceProcessor.java b/extensions/datasource/deployment/src/main/java/io/quarkus/datasource/deployment/devservices/DevServicesDatasourceProcessor.java index e36bd5dfbe6dbe..b3d8fe8644e54b 100644 --- a/extensions/datasource/deployment/src/main/java/io/quarkus/datasource/deployment/devservices/DevServicesDatasourceProcessor.java +++ b/extensions/datasource/deployment/src/main/java/io/quarkus/datasource/deployment/devservices/DevServicesDatasourceProcessor.java @@ -65,7 +65,7 @@ DevServicesDatasourceResultBuildItem launchDatabases( DockerStatusBuildItem dockerStatusBuildItem, List installedDrivers, List devDBProviders, - DataSourcesBuildTimeConfig dataSourceBuildTimeConfig, + DataSourcesBuildTimeConfig dataSourcesBuildTimeConfig, LaunchModeBuildItem launchMode, List configurationHandlerBuildItems, BuildProducer devServicesResultBuildItemBuildProducer, @@ -113,8 +113,8 @@ DevServicesDatasourceResultBuildItem launchDatabases( databases = null; cachedProperties = null; } - DevServicesDatasourceResultBuildItem.DbResult defaultResult; - Map namedResults = new HashMap<>(); + + Map results = new HashMap<>(); //now we need to figure out if we need to launch some databases //note that because we run in dev and test mode only we know the runtime //config at build time, as they both execute in the same JVM @@ -137,26 +137,16 @@ DevServicesDatasourceResultBuildItem launchDatabases( Map devDBProviderMap = devDBProviders.stream() .collect(Collectors.toMap(DevServicesDatasourceProviderBuildItem::getDatabase, DevServicesDatasourceProviderBuildItem::getDevServicesProvider)); - RunningDevService defaultDevService = startDevDb(null, capabilities, curateOutcomeBuildItem, installedDrivers, - !dataSourceBuildTimeConfig.namedDataSources().isEmpty(), - devDBProviderMap, - dataSourceBuildTimeConfig.defaultDataSource(), - configHandlersByDbType, propertiesMap, - dockerStatusBuildItem, launchMode.getLaunchMode(), consoleInstalledBuildItem, - loggingSetupBuildItem, globalDevServicesConfig); - if (defaultDevService != null) { - runningDevServices.add(defaultDevService); - } - defaultResult = toDbResult(defaultDevService); - for (Map.Entry entry : dataSourceBuildTimeConfig.namedDataSources().entrySet()) { - RunningDevService namedDevService = startDevDb(entry.getKey(), capabilities, curateOutcomeBuildItem, - installedDrivers, true, + + for (Map.Entry entry : dataSourcesBuildTimeConfig.dataSources().entrySet()) { + RunningDevService devService = startDevDb(entry.getKey(), capabilities, curateOutcomeBuildItem, + installedDrivers, dataSourcesBuildTimeConfig.hasNamedDataSources(), devDBProviderMap, entry.getValue(), configHandlersByDbType, propertiesMap, dockerStatusBuildItem, launchMode.getLaunchMode(), consoleInstalledBuildItem, loggingSetupBuildItem, globalDevServicesConfig); - if (namedDevService != null) { - runningDevServices.add(namedDevService); - namedResults.put(entry.getKey(), toDbResult(namedDevService)); + if (devService != null) { + runningDevServices.add(devService); + results.put(entry.getKey(), toDbResult(devService)); } } @@ -186,7 +176,7 @@ public void run() { for (RunningDevService database : databases) { devServicesResultBuildItemBuildProducer.produce(database.toBuildItem()); } - return new DevServicesDatasourceResultBuildItem(defaultResult, namedResults); + return new DevServicesDatasourceResultBuildItem(results); } private String trim(String optional) { @@ -209,9 +199,11 @@ private RunningDevService startDevDb( LaunchMode launchMode, Optional consoleInstalledBuildItem, LoggingSetupBuildItem loggingSetupBuildItem, GlobalDevServicesConfig globalDevServicesConfig) { boolean explicitlyDisabled = !(dataSourceBuildTimeConfig.devservices().enabled().orElse(true)); + String dataSourcePrettyName = DataSourceUtil.isDefault(dbName) ? "default datasource" : "datasource" + dbName; + if (explicitlyDisabled) { //explicitly disabled - log.debug("Not starting Dev Services for " + (dbName == null ? "default datasource" : dbName) + log.debug("Not starting Dev Services for " + dataSourcePrettyName + " as it has been disabled in the configuration"); return null; } @@ -221,19 +213,19 @@ private RunningDevService startDevDb( Optional defaultDbKind = DefaultDataSourceDbKindBuildItem.resolve( dataSourceBuildTimeConfig.dbKind(), installedDrivers, - dbName != null || enabled, + (!DataSourceUtil.isDefault(dbName)) || enabled, curateOutcomeBuildItem); if (!defaultDbKind.isPresent()) { //nothing we can do - log.warn("Unable to determine a database type for " + (dbName == null ? "default datasource" : dbName)); + log.warn("Unable to determine a database type for " + dataSourcePrettyName); return null; } DevServicesDatasourceProvider devDbProvider = devDBProviders.get(defaultDbKind.get()); List configHandlers = configurationHandlerBuildItems .get(defaultDbKind.get()); if (devDbProvider == null || configHandlers == null) { - log.warn("Unable to start Dev Services for " + (dbName == null ? "default datasource" : dbName) + log.warn("Unable to start Dev Services for " + dataSourcePrettyName + " as this datasource type (" + defaultDbKind.get() + ") does not support Dev Services"); return null; } @@ -243,17 +235,16 @@ private RunningDevService startDevDb( if (i.getCheckConfiguredFunction().test(dbName)) { //this database has explicit configuration //we don't start the devservices - log.debug("Not starting Dev Services for " + (dbName == null ? "default datasource" : dbName) + log.debug("Not starting Dev Services for " + dataSourcePrettyName + " as it has explicit configuration"); return null; } } } - String prettyName = dbName == null ? "the default datasource" : " datasource '" + dbName + "'"; if (devDbProvider.isDockerRequired() && !dockerStatusBuildItem.isDockerAvailable()) { String message = "Please configure the datasource URL for " - + prettyName + + dataSourcePrettyName + " or ensure the Docker daemon is up and running."; if (launchMode == LaunchMode.TEST) { throw new IllegalStateException(message); @@ -268,7 +259,7 @@ private RunningDevService startDevDb( //ok, so we know we need to start one StartupLogCompressor compressor = new StartupLogCompressor( - (launchMode == LaunchMode.TEST ? "(test) " : "") + "Database for " + prettyName + (launchMode == LaunchMode.TEST ? "(test) " : "") + "Database for " + dataSourcePrettyName + " (" + defaultDbKind.get() + ") starting:", consoleInstalledBuildItem, loggingSetupBuildItem); @@ -293,7 +284,7 @@ private RunningDevService startDevDb( String.class), ConfigUtils.getFirstOptionalValue(DataSourceUtil.dataSourcePropertyKeys(dbName, "password"), String.class), - Optional.ofNullable(dbName), containerConfig, + dbName, containerConfig, launchMode, globalDevServicesConfig.timeout); for (String key : DataSourceUtil.dataSourcePropertyKeys(dbName, "db-kind")) { @@ -342,9 +333,9 @@ private RunningDevService startDevDb( } compressor.close(); if (datasource.getId() == null) { - log.infof("Dev Services for %s (%s) started", prettyName, defaultDbKind.get()); + log.infof("Dev Services for %s (%s) started", dataSourcePrettyName, defaultDbKind.get()); } else { - log.infof("Dev Services for %s (%s) started - container ID is %s", prettyName, defaultDbKind.get(), + log.infof("Dev Services for %s (%s) started - container ID is %s", dataSourcePrettyName, defaultDbKind.get(), datasource.getId().length() > DOCKER_PS_ID_LENGTH ? datasource.getId().substring(0, DOCKER_PS_ID_LENGTH) : datasource.getId()); } diff --git a/extensions/datasource/deployment/src/main/java/io/quarkus/datasource/deployment/devservices/DevUIDatasourceProcessor.java b/extensions/datasource/deployment/src/main/java/io/quarkus/datasource/deployment/devservices/DevUIDatasourceProcessor.java index ee84df4d3bdd6b..d57c45f204246a 100644 --- a/extensions/datasource/deployment/src/main/java/io/quarkus/datasource/deployment/devservices/DevUIDatasourceProcessor.java +++ b/extensions/datasource/deployment/src/main/java/io/quarkus/datasource/deployment/devservices/DevUIDatasourceProcessor.java @@ -25,7 +25,7 @@ public DevConsoleTemplateInfoBuildItem devConsoleInfo( DataSourcesBuildTimeConfig dataSourceBuildTimeConfig) { List names = new ArrayList<>(); names.add(""); - names.addAll(dataSourceBuildTimeConfig.namedDataSources().keySet()); + names.addAll(dataSourceBuildTimeConfig.dataSources().keySet()); Collections.sort(names); return new DevConsoleTemplateInfoBuildItem("dbs", names); } @@ -42,7 +42,7 @@ CardPageBuildItem create(DataSourcesBuildTimeConfig dataSourceBuildTimeConfig) { List names = new ArrayList<>(); names.add(""); - names.addAll(dataSourceBuildTimeConfig.namedDataSources().keySet()); + names.addAll(dataSourceBuildTimeConfig.dataSources().keySet()); Collections.sort(names); card.addBuildTimeData("datasources", names); diff --git a/extensions/datasource/runtime/src/main/java/io/quarkus/datasource/runtime/DataSourcesBuildTimeConfig.java b/extensions/datasource/runtime/src/main/java/io/quarkus/datasource/runtime/DataSourcesBuildTimeConfig.java index fa4ea81767a764..c649c4a085555c 100644 --- a/extensions/datasource/runtime/src/main/java/io/quarkus/datasource/runtime/DataSourcesBuildTimeConfig.java +++ b/extensions/datasource/runtime/src/main/java/io/quarkus/datasource/runtime/DataSourcesBuildTimeConfig.java @@ -1,38 +1,33 @@ package io.quarkus.datasource.runtime; import java.util.Map; -import java.util.Objects; import java.util.Optional; -import java.util.function.Supplier; import io.quarkus.datasource.common.runtime.DataSourceUtil; import io.quarkus.runtime.annotations.ConfigDocMapKey; import io.quarkus.runtime.annotations.ConfigDocSection; import io.quarkus.runtime.annotations.ConfigPhase; import io.quarkus.runtime.annotations.ConfigRoot; -import io.quarkus.runtime.configuration.ConfigUtils; import io.smallrye.config.ConfigMapping; import io.smallrye.config.WithDefault; +import io.smallrye.config.WithDefaults; import io.smallrye.config.WithName; import io.smallrye.config.WithParentName; +import io.smallrye.config.WithUnnamedKey; @ConfigMapping(prefix = "quarkus.datasource") @ConfigRoot(phase = ConfigPhase.BUILD_AND_RUN_TIME_FIXED) public interface DataSourcesBuildTimeConfig { /** - * The default datasource. - */ - @WithParentName - DataSourceBuildTimeConfig defaultDataSource(); - - /** - * Additional named datasources. + * Datasources. */ @ConfigDocSection @ConfigDocMapKey("datasource-name") @WithParentName - Map namedDataSources(); + @WithDefaults + @WithUnnamedKey(DataSourceUtil.DEFAULT_DATASOURCE_NAME) + Map dataSources(); /** * Whether or not an health check is published in case the smallrye-health extension is present. @@ -73,19 +68,7 @@ public interface DataSourcesBuildTimeConfig { @Deprecated Optional driver(); - default DataSourceBuildTimeConfig getDataSourceBuildTimeConfig(String dataSourceName) { - if (DataSourceUtil.isDefault(dataSourceName)) { - return defaultDataSource(); - } - - DataSourceBuildTimeConfig dataSourceBuildTimeConfig = namedDataSources().get(dataSourceName); - return Objects.requireNonNullElseGet(dataSourceBuildTimeConfig, new Supplier() { - - @Override - public DataSourceBuildTimeConfig get() { - return ConfigUtils.getInitializedConfigGroup(DataSourceBuildTimeConfig.class, "quarkus.datasource.*"); - } - }); + default boolean hasNamedDataSources() { + return dataSources().keySet().size() > 1 || !dataSources().containsKey(DataSourceUtil.DEFAULT_DATASOURCE_NAME); } - } diff --git a/extensions/datasource/runtime/src/main/java/io/quarkus/datasource/runtime/DataSourcesHealthSupportRecorder.java b/extensions/datasource/runtime/src/main/java/io/quarkus/datasource/runtime/DataSourcesHealthSupportRecorder.java index 04eb957e47b2b5..e39d700a6ed647 100644 --- a/extensions/datasource/runtime/src/main/java/io/quarkus/datasource/runtime/DataSourcesHealthSupportRecorder.java +++ b/extensions/datasource/runtime/src/main/java/io/quarkus/datasource/runtime/DataSourcesHealthSupportRecorder.java @@ -6,7 +6,6 @@ import java.util.Set; import java.util.stream.Stream; -import io.quarkus.datasource.common.runtime.DataSourceUtil; import io.quarkus.runtime.RuntimeValue; import io.quarkus.runtime.annotations.Recorder; @@ -17,14 +16,10 @@ public RuntimeValue configureDataSourcesHealthSupport( DataSourcesBuildTimeConfig config) { Stream.Builder configured = Stream.builder(); Stream.Builder excluded = Stream.builder(); - if (config.defaultDataSource().dbKind().isPresent()) { - configured.add(DataSourceUtil.DEFAULT_DATASOURCE_NAME); - } - if (config.defaultDataSource().healthExclude()) { - excluded.add(DataSourceUtil.DEFAULT_DATASOURCE_NAME); - } - for (Map.Entry dataSource : config.namedDataSources().entrySet()) { - configured.add(dataSource.getKey()); + for (Map.Entry dataSource : config.dataSources().entrySet()) { + if (dataSource.getValue().dbKind().isPresent()) { + configured.add(dataSource.getKey()); + } if (dataSource.getValue().healthExclude()) { excluded.add(dataSource.getKey()); } diff --git a/extensions/datasource/runtime/src/main/java/io/quarkus/datasource/runtime/DataSourcesRuntimeConfig.java b/extensions/datasource/runtime/src/main/java/io/quarkus/datasource/runtime/DataSourcesRuntimeConfig.java index eed5384614f72c..91e24d97721d7e 100644 --- a/extensions/datasource/runtime/src/main/java/io/quarkus/datasource/runtime/DataSourcesRuntimeConfig.java +++ b/extensions/datasource/runtime/src/main/java/io/quarkus/datasource/runtime/DataSourcesRuntimeConfig.java @@ -1,48 +1,28 @@ package io.quarkus.datasource.runtime; import java.util.Map; -import java.util.Objects; -import java.util.function.Supplier; import io.quarkus.datasource.common.runtime.DataSourceUtil; import io.quarkus.runtime.annotations.ConfigDocMapKey; import io.quarkus.runtime.annotations.ConfigDocSection; import io.quarkus.runtime.annotations.ConfigPhase; import io.quarkus.runtime.annotations.ConfigRoot; -import io.quarkus.runtime.configuration.ConfigUtils; import io.smallrye.config.ConfigMapping; +import io.smallrye.config.WithDefaults; import io.smallrye.config.WithParentName; +import io.smallrye.config.WithUnnamedKey; @ConfigMapping(prefix = "quarkus.datasource") @ConfigRoot(phase = ConfigPhase.RUN_TIME) public interface DataSourcesRuntimeConfig { /** - * The default datasource. - */ - @WithParentName - DataSourceRuntimeConfig defaultDataSource(); - - /** - * Additional named datasources. + * Datasources. */ @ConfigDocSection @ConfigDocMapKey("datasource-name") @WithParentName - Map namedDataSources(); - - default DataSourceRuntimeConfig getDataSourceRuntimeConfig(String dataSourceName) { - if (DataSourceUtil.isDefault(dataSourceName)) { - return defaultDataSource(); - } - - DataSourceRuntimeConfig dataSourceRuntimeConfig = namedDataSources().get(dataSourceName); - return Objects.requireNonNullElseGet(dataSourceRuntimeConfig, new Supplier() { - - @Override - public DataSourceRuntimeConfig get() { - return ConfigUtils.getInitializedConfigGroup(DataSourceRuntimeConfig.class, "quarkus.datasource.*"); - } - }); - } + @WithDefaults + @WithUnnamedKey(DataSourceUtil.DEFAULT_DATASOURCE_NAME) + Map dataSources(); } diff --git a/extensions/devservices/common/pom.xml b/extensions/devservices/common/pom.xml index 0bfc2c543a11de..ef138c2628b2ff 100644 --- a/extensions/devservices/common/pom.xml +++ b/extensions/devservices/common/pom.xml @@ -39,5 +39,9 @@ io.quarkus quarkus-core + + io.quarkus + quarkus-datasource-common + diff --git a/extensions/devservices/common/src/main/java/io/quarkus/devservices/common/Labels.java b/extensions/devservices/common/src/main/java/io/quarkus/devservices/common/Labels.java index 716140b81a7735..19d83ea1cee4c9 100644 --- a/extensions/devservices/common/src/main/java/io/quarkus/devservices/common/Labels.java +++ b/extensions/devservices/common/src/main/java/io/quarkus/devservices/common/Labels.java @@ -1,15 +1,15 @@ package io.quarkus.devservices.common; -import java.util.Optional; - import org.testcontainers.containers.GenericContainer; +import io.quarkus.datasource.common.runtime.DataSourceUtil; + public final class Labels { private static final String DATASOURCE = "datasource"; - public static void addDataSourceLabel(GenericContainer container, Optional datasourceName) { - container.withLabel(DATASOURCE, datasourceName.orElse("default")); + public static void addDataSourceLabel(GenericContainer container, String datasourceName) { + container.withLabel(DATASOURCE, DataSourceUtil.isDefault(datasourceName) ? "default" : datasourceName); } private Labels() { diff --git a/extensions/devservices/db2/src/main/java/io/quarkus/devservices/db2/deployment/DB2DevServicesProcessor.java b/extensions/devservices/db2/src/main/java/io/quarkus/devservices/db2/deployment/DB2DevServicesProcessor.java index d6431842fc7fa7..2cad0ed0641eda 100644 --- a/extensions/devservices/db2/src/main/java/io/quarkus/devservices/db2/deployment/DB2DevServicesProcessor.java +++ b/extensions/devservices/db2/src/main/java/io/quarkus/devservices/db2/deployment/DB2DevServicesProcessor.java @@ -13,6 +13,7 @@ import org.testcontainers.containers.Db2Container; import org.testcontainers.utility.DockerImageName; +import io.quarkus.datasource.common.runtime.DataSourceUtil; import io.quarkus.datasource.common.runtime.DatabaseKind; import io.quarkus.datasource.deployment.spi.DevServicesDatasourceContainerConfig; import io.quarkus.datasource.deployment.spi.DevServicesDatasourceProvider; @@ -35,7 +36,7 @@ DevServicesDatasourceProviderBuildItem setupDB2( return new DevServicesDatasourceProviderBuildItem(DatabaseKind.DB2, new DevServicesDatasourceProvider() { @Override public RunningDevServicesDatasource startDatabase(Optional username, Optional password, - Optional datasourceName, DevServicesDatasourceContainerConfig containerConfig, + String datasourceName, DevServicesDatasourceContainerConfig containerConfig, LaunchMode launchMode, Optional startupTimeout) { QuarkusDb2Container container = new QuarkusDb2Container(containerConfig.getImageName(), containerConfig.getFixedExposedPort(), @@ -44,7 +45,8 @@ public RunningDevServicesDatasource startDatabase(Optional username, Opt String effectiveUsername = containerConfig.getUsername().orElse(username.orElse(DEFAULT_DATABASE_USERNAME)); String effectivePassword = containerConfig.getPassword().orElse(password.orElse(DEFAULT_DATABASE_PASSWORD)); - String effectiveDbName = containerConfig.getDbName().orElse(datasourceName.orElse(DEFAULT_DATABASE_NAME)); + String effectiveDbName = containerConfig.getDbName().orElse( + DataSourceUtil.isDefault(datasourceName) ? DEFAULT_DATABASE_NAME : datasourceName); container.withUsername(effectiveUsername) .withPassword(effectivePassword) diff --git a/extensions/devservices/derby/src/main/java/io/quarkus/devservices/derby/deployment/DerbyDevServicesProcessor.java b/extensions/devservices/derby/src/main/java/io/quarkus/devservices/derby/deployment/DerbyDevServicesProcessor.java index 7690a051671d6b..2405dbfbc7430d 100644 --- a/extensions/devservices/derby/src/main/java/io/quarkus/devservices/derby/deployment/DerbyDevServicesProcessor.java +++ b/extensions/devservices/derby/src/main/java/io/quarkus/devservices/derby/deployment/DerbyDevServicesProcessor.java @@ -13,6 +13,7 @@ import org.apache.derby.drda.NetworkServerControl; import org.jboss.logging.Logger; +import io.quarkus.datasource.common.runtime.DataSourceUtil; import io.quarkus.datasource.common.runtime.DatabaseKind; import io.quarkus.datasource.deployment.spi.DevServicesDatasourceContainerConfig; import io.quarkus.datasource.deployment.spi.DevServicesDatasourceProvider; @@ -32,14 +33,15 @@ DevServicesDatasourceProviderBuildItem setupDerby() { return new DevServicesDatasourceProviderBuildItem(DatabaseKind.DERBY, new DevServicesDatasourceProvider() { @Override public RunningDevServicesDatasource startDatabase(Optional username, Optional password, - Optional datasourceName, DevServicesDatasourceContainerConfig containerConfig, + String datasourceName, DevServicesDatasourceContainerConfig containerConfig, LaunchMode launchMode, Optional startupTimeout) { try { int port = containerConfig.getFixedExposedPort().isPresent() ? containerConfig.getFixedExposedPort().getAsInt() : 1527 + (launchMode == LaunchMode.TEST ? 0 : 1); - String effectiveDbName = containerConfig.getDbName().orElse(datasourceName.orElse(DEFAULT_DATABASE_NAME)); + String effectiveDbName = containerConfig.getDbName().orElse( + DataSourceUtil.isDefault(datasourceName) ? DEFAULT_DATABASE_NAME : datasourceName); NetworkServerControl server = new NetworkServerControl(InetAddress.getByName("localhost"), port); server.start(new PrintWriter(System.out)); diff --git a/extensions/devservices/h2/src/main/java/io/quarkus/devservices/h2/deployment/H2DevServicesProcessor.java b/extensions/devservices/h2/src/main/java/io/quarkus/devservices/h2/deployment/H2DevServicesProcessor.java index 2ff28f76a5d72a..816befca62d331 100644 --- a/extensions/devservices/h2/src/main/java/io/quarkus/devservices/h2/deployment/H2DevServicesProcessor.java +++ b/extensions/devservices/h2/src/main/java/io/quarkus/devservices/h2/deployment/H2DevServicesProcessor.java @@ -17,6 +17,7 @@ import org.h2.tools.Server; import org.jboss.logging.Logger; +import io.quarkus.datasource.common.runtime.DataSourceUtil; import io.quarkus.datasource.common.runtime.DatabaseKind; import io.quarkus.datasource.deployment.spi.DevServicesDatasourceContainerConfig; import io.quarkus.datasource.deployment.spi.DevServicesDatasourceProvider; @@ -33,7 +34,7 @@ DevServicesDatasourceProviderBuildItem setupH2() { return new DevServicesDatasourceProviderBuildItem(DatabaseKind.H2, new DevServicesDatasourceProvider() { @Override public RunningDevServicesDatasource startDatabase(Optional username, Optional password, - Optional datasourceName, DevServicesDatasourceContainerConfig containerConfig, + String datasourceName, DevServicesDatasourceContainerConfig containerConfig, LaunchMode launchMode, Optional startupTimeout) { try { final Server tcpServer = Server.createTcpServer("-tcpPort", @@ -45,7 +46,8 @@ public RunningDevServicesDatasource startDatabase(Optional username, Opt String effectiveUsername = containerConfig.getUsername().orElse(username.orElse(DEFAULT_DATABASE_USERNAME)); String effectivePassword = containerConfig.getPassword().orElse(password.orElse(DEFAULT_DATABASE_PASSWORD)); - String effectiveDbName = containerConfig.getDbName().orElse(datasourceName.orElse(DEFAULT_DATABASE_NAME)); + String effectiveDbName = containerConfig.getDbName().orElse( + DataSourceUtil.isDefault(datasourceName) ? DEFAULT_DATABASE_NAME : datasourceName); StringBuilder additionalArgs = new StringBuilder(); for (Map.Entry i : containerConfig.getAdditionalJdbcUrlProperties().entrySet()) { diff --git a/extensions/devservices/mariadb/src/main/java/io/quarkus/devservices/mariadb/deployment/MariaDBDevServicesProcessor.java b/extensions/devservices/mariadb/src/main/java/io/quarkus/devservices/mariadb/deployment/MariaDBDevServicesProcessor.java index dfe710c68ae609..048906fdce73ed 100644 --- a/extensions/devservices/mariadb/src/main/java/io/quarkus/devservices/mariadb/deployment/MariaDBDevServicesProcessor.java +++ b/extensions/devservices/mariadb/src/main/java/io/quarkus/devservices/mariadb/deployment/MariaDBDevServicesProcessor.java @@ -13,6 +13,7 @@ import org.testcontainers.containers.MariaDBContainer; import org.testcontainers.utility.DockerImageName; +import io.quarkus.datasource.common.runtime.DataSourceUtil; import io.quarkus.datasource.common.runtime.DatabaseKind; import io.quarkus.datasource.deployment.spi.DevServicesDatasourceContainerConfig; import io.quarkus.datasource.deployment.spi.DevServicesDatasourceProvider; @@ -39,7 +40,7 @@ DevServicesDatasourceProviderBuildItem setupMariaDB( @SuppressWarnings("unchecked") @Override public RunningDevServicesDatasource startDatabase(Optional username, Optional password, - Optional datasourceName, DevServicesDatasourceContainerConfig containerConfig, + String datasourceName, DevServicesDatasourceContainerConfig containerConfig, LaunchMode launchMode, Optional startupTimeout) { QuarkusMariaDBContainer container = new QuarkusMariaDBContainer(containerConfig.getImageName(), containerConfig.getFixedExposedPort(), @@ -48,7 +49,8 @@ public RunningDevServicesDatasource startDatabase(Optional username, Opt String effectiveUsername = containerConfig.getUsername().orElse(username.orElse(DEFAULT_DATABASE_USERNAME)); String effectivePassword = containerConfig.getPassword().orElse(password.orElse(DEFAULT_DATABASE_PASSWORD)); - String effectiveDbName = containerConfig.getDbName().orElse(datasourceName.orElse(DEFAULT_DATABASE_NAME)); + String effectiveDbName = containerConfig.getDbName().orElse( + DataSourceUtil.isDefault(datasourceName) ? DEFAULT_DATABASE_NAME : datasourceName); container.withUsername(effectiveUsername) .withPassword(effectivePassword) diff --git a/extensions/devservices/mssql/src/main/java/io/quarkus/devservices/mssql/deployment/MSSQLDevServicesProcessor.java b/extensions/devservices/mssql/src/main/java/io/quarkus/devservices/mssql/deployment/MSSQLDevServicesProcessor.java index 9cc82062f702bd..7aa3c05e07d205 100644 --- a/extensions/devservices/mssql/src/main/java/io/quarkus/devservices/mssql/deployment/MSSQLDevServicesProcessor.java +++ b/extensions/devservices/mssql/src/main/java/io/quarkus/devservices/mssql/deployment/MSSQLDevServicesProcessor.java @@ -39,7 +39,7 @@ DevServicesDatasourceProviderBuildItem setupMSSQL( @SuppressWarnings("unchecked") @Override public RunningDevServicesDatasource startDatabase(Optional username, Optional password, - Optional datasourceName, DevServicesDatasourceContainerConfig containerConfig, + String datasourceName, DevServicesDatasourceContainerConfig containerConfig, LaunchMode launchMode, Optional startupTimeout) { QuarkusMSSQLServerContainer container = new QuarkusMSSQLServerContainer(containerConfig.getImageName(), containerConfig.getFixedExposedPort(), diff --git a/extensions/devservices/mysql/src/main/java/io/quarkus/devservices/mysql/deployment/MySQLDevServicesProcessor.java b/extensions/devservices/mysql/src/main/java/io/quarkus/devservices/mysql/deployment/MySQLDevServicesProcessor.java index cd884aa83b5200..6121a7b25a511b 100644 --- a/extensions/devservices/mysql/src/main/java/io/quarkus/devservices/mysql/deployment/MySQLDevServicesProcessor.java +++ b/extensions/devservices/mysql/src/main/java/io/quarkus/devservices/mysql/deployment/MySQLDevServicesProcessor.java @@ -13,6 +13,7 @@ import org.testcontainers.containers.MySQLContainer; import org.testcontainers.utility.DockerImageName; +import io.quarkus.datasource.common.runtime.DataSourceUtil; import io.quarkus.datasource.common.runtime.DatabaseKind; import io.quarkus.datasource.deployment.spi.DevServicesDatasourceContainerConfig; import io.quarkus.datasource.deployment.spi.DevServicesDatasourceProvider; @@ -38,7 +39,7 @@ DevServicesDatasourceProviderBuildItem setupMysql( @SuppressWarnings("unchecked") @Override public RunningDevServicesDatasource startDatabase(Optional username, Optional password, - Optional datasourceName, DevServicesDatasourceContainerConfig containerConfig, + String datasourceName, DevServicesDatasourceContainerConfig containerConfig, LaunchMode launchMode, Optional startupTimeout) { QuarkusMySQLContainer container = new QuarkusMySQLContainer(containerConfig.getImageName(), containerConfig.getFixedExposedPort(), @@ -47,7 +48,8 @@ public RunningDevServicesDatasource startDatabase(Optional username, Opt String effectiveUsername = containerConfig.getUsername().orElse(username.orElse(DEFAULT_DATABASE_USERNAME)); String effectivePassword = containerConfig.getPassword().orElse(password.orElse(DEFAULT_DATABASE_PASSWORD)); - String effectiveDbName = containerConfig.getDbName().orElse(datasourceName.orElse(DEFAULT_DATABASE_NAME)); + String effectiveDbName = containerConfig.getDbName().orElse( + DataSourceUtil.isDefault(datasourceName) ? DEFAULT_DATABASE_NAME : datasourceName); container.withUsername(effectiveUsername) .withPassword(effectivePassword) diff --git a/extensions/devservices/oracle/src/main/java/io/quarkus/devservices/oracle/deployment/OracleDevServicesProcessor.java b/extensions/devservices/oracle/src/main/java/io/quarkus/devservices/oracle/deployment/OracleDevServicesProcessor.java index aca0d9aef329fa..eba12b7cd1396e 100644 --- a/extensions/devservices/oracle/src/main/java/io/quarkus/devservices/oracle/deployment/OracleDevServicesProcessor.java +++ b/extensions/devservices/oracle/src/main/java/io/quarkus/devservices/oracle/deployment/OracleDevServicesProcessor.java @@ -13,6 +13,7 @@ import org.testcontainers.containers.OracleContainer; import org.testcontainers.utility.DockerImageName; +import io.quarkus.datasource.common.runtime.DataSourceUtil; import io.quarkus.datasource.common.runtime.DatabaseKind; import io.quarkus.datasource.deployment.spi.DevServicesDatasourceContainerConfig; import io.quarkus.datasource.deployment.spi.DevServicesDatasourceProvider; @@ -42,7 +43,7 @@ DevServicesDatasourceProviderBuildItem setupOracle( return new DevServicesDatasourceProviderBuildItem(DatabaseKind.ORACLE, new DevServicesDatasourceProvider() { @Override public RunningDevServicesDatasource startDatabase(Optional username, Optional password, - Optional datasourceName, DevServicesDatasourceContainerConfig containerConfig, + String datasourceName, DevServicesDatasourceContainerConfig containerConfig, LaunchMode launchMode, Optional startupTimeout) { QuarkusOracleServerContainer container = new QuarkusOracleServerContainer(containerConfig.getImageName(), containerConfig.getFixedExposedPort(), @@ -51,7 +52,8 @@ public RunningDevServicesDatasource startDatabase(Optional username, Opt String effectiveUsername = containerConfig.getUsername().orElse(username.orElse(DEFAULT_DATABASE_USERNAME)); String effectivePassword = containerConfig.getPassword().orElse(password.orElse(DEFAULT_DATABASE_PASSWORD)); - String effectiveDbName = containerConfig.getDbName().orElse(datasourceName.orElse(DEFAULT_DATABASE_NAME)); + String effectiveDbName = containerConfig.getDbName().orElse( + DataSourceUtil.isDefault(datasourceName) ? DEFAULT_DATABASE_NAME : datasourceName); container.withUsername(effectiveUsername) .withPassword(effectivePassword) diff --git a/extensions/devservices/postgresql/src/main/java/io/quarkus/devservices/postgresql/deployment/PostgresqlDevServicesProcessor.java b/extensions/devservices/postgresql/src/main/java/io/quarkus/devservices/postgresql/deployment/PostgresqlDevServicesProcessor.java index afaeb640fbfa8b..b52c95c67892af 100644 --- a/extensions/devservices/postgresql/src/main/java/io/quarkus/devservices/postgresql/deployment/PostgresqlDevServicesProcessor.java +++ b/extensions/devservices/postgresql/src/main/java/io/quarkus/devservices/postgresql/deployment/PostgresqlDevServicesProcessor.java @@ -15,6 +15,7 @@ import org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy; import org.testcontainers.utility.DockerImageName; +import io.quarkus.datasource.common.runtime.DataSourceUtil; import io.quarkus.datasource.common.runtime.DatabaseKind; import io.quarkus.datasource.deployment.spi.DevServicesDatasourceContainerConfig; import io.quarkus.datasource.deployment.spi.DevServicesDatasourceProvider; @@ -45,7 +46,7 @@ DevServicesDatasourceProviderBuildItem setupPostgres( @SuppressWarnings("unchecked") @Override public RunningDevServicesDatasource startDatabase(Optional username, Optional password, - Optional datasourceName, DevServicesDatasourceContainerConfig containerConfig, + String datasourceName, DevServicesDatasourceContainerConfig containerConfig, LaunchMode launchMode, Optional startupTimeout) { QuarkusPostgreSQLContainer container = new QuarkusPostgreSQLContainer(containerConfig.getImageName(), containerConfig.getFixedExposedPort(), @@ -54,7 +55,8 @@ public RunningDevServicesDatasource startDatabase(Optional username, Opt String effectiveUsername = containerConfig.getUsername().orElse(username.orElse(DEFAULT_DATABASE_USERNAME)); String effectivePassword = containerConfig.getPassword().orElse(password.orElse(DEFAULT_DATABASE_PASSWORD)); - String effectiveDbName = containerConfig.getDbName().orElse(datasourceName.orElse(DEFAULT_DATABASE_NAME)); + String effectiveDbName = containerConfig.getDbName().orElse( + DataSourceUtil.isDefault(datasourceName) ? DEFAULT_DATABASE_NAME : datasourceName); container.withUsername(effectiveUsername) .withPassword(effectivePassword) diff --git a/extensions/hibernate-reactive/deployment/src/main/java/io/quarkus/hibernate/reactive/deployment/HibernateReactiveProcessor.java b/extensions/hibernate-reactive/deployment/src/main/java/io/quarkus/hibernate/reactive/deployment/HibernateReactiveProcessor.java index 01e018b1dcfdce..a6ac9c7e452248 100644 --- a/extensions/hibernate-reactive/deployment/src/main/java/io/quarkus/hibernate/reactive/deployment/HibernateReactiveProcessor.java +++ b/extensions/hibernate-reactive/deployment/src/main/java/io/quarkus/hibernate/reactive/deployment/HibernateReactiveProcessor.java @@ -38,6 +38,7 @@ import io.quarkus.datasource.common.runtime.DataSourceUtil; import io.quarkus.datasource.common.runtime.DatabaseKind; import io.quarkus.datasource.deployment.spi.DefaultDataSourceDbKindBuildItem; +import io.quarkus.datasource.runtime.DataSourceBuildTimeConfig; import io.quarkus.datasource.runtime.DataSourcesBuildTimeConfig; import io.quarkus.deployment.annotations.BuildProducer; import io.quarkus.deployment.annotations.BuildStep; @@ -157,13 +158,16 @@ public void buildReactivePersistenceUnit( } // we only support the default pool for now + DataSourceBuildTimeConfig defaultDataSourceBuildTimeConfig = dataSourcesBuildTimeConfig.dataSources() + .get(DataSourceUtil.DEFAULT_DATASOURCE_NAME); + Optional explicitDialect = hibernateOrmConfig.defaultPersistenceUnit.dialect.dialect; - Optional explicitDbMinVersion = dataSourcesBuildTimeConfig.defaultDataSource().dbVersion(); + Optional explicitDbMinVersion = defaultDataSourceBuildTimeConfig.dbVersion(); Optional dbKindOptional = DefaultDataSourceDbKindBuildItem.resolve( - dataSourcesBuildTimeConfig.defaultDataSource().dbKind(), + defaultDataSourceBuildTimeConfig.dbKind(), defaultDataSourceDbKindBuildItems, - dataSourcesBuildTimeConfig.defaultDataSource().devservices().enabled() - .orElse(dataSourcesBuildTimeConfig.namedDataSources().isEmpty()), + defaultDataSourceBuildTimeConfig.devservices().enabled() + .orElse(!dataSourcesBuildTimeConfig.hasNamedDataSources()), curateOutcomeBuildItem); if (dbKindOptional.isPresent()) { diff --git a/extensions/reactive-datasource/runtime/src/main/java/io/quarkus/reactive/datasource/runtime/DataSourcesReactiveBuildTimeConfig.java b/extensions/reactive-datasource/runtime/src/main/java/io/quarkus/reactive/datasource/runtime/DataSourcesReactiveBuildTimeConfig.java index 3a6bab9877cb06..177b156266559e 100644 --- a/extensions/reactive-datasource/runtime/src/main/java/io/quarkus/reactive/datasource/runtime/DataSourcesReactiveBuildTimeConfig.java +++ b/extensions/reactive-datasource/runtime/src/main/java/io/quarkus/reactive/datasource/runtime/DataSourcesReactiveBuildTimeConfig.java @@ -8,8 +8,8 @@ import io.quarkus.runtime.annotations.ConfigGroup; import io.quarkus.runtime.annotations.ConfigPhase; import io.quarkus.runtime.annotations.ConfigRoot; -import io.quarkus.runtime.configuration.ConfigUtils; import io.smallrye.config.ConfigMapping; +import io.smallrye.config.WithDefaults; import io.smallrye.config.WithName; import io.smallrye.config.WithParentName; @@ -29,6 +29,7 @@ public interface DataSourcesReactiveBuildTimeConfig { @ConfigDocSection @ConfigDocMapKey("datasource-name") @WithParentName + @WithDefaults Map namedDataSources(); default DataSourceReactiveBuildTimeConfig getDataSourceReactiveBuildTimeConfig(String dataSourceName) { @@ -36,13 +37,7 @@ default DataSourceReactiveBuildTimeConfig getDataSourceReactiveBuildTimeConfig(S return defaultDataSource(); } - DataSourceReactiveOuterNamedBuildTimeConfig dataSourceReactiveBuildTimeConfig = namedDataSources().get(dataSourceName); - - if (dataSourceReactiveBuildTimeConfig != null) { - return dataSourceReactiveBuildTimeConfig.reactive(); - } - - return ConfigUtils.getInitializedConfigGroup(DataSourceReactiveBuildTimeConfig.class, "quarkus.datasource.*.reactive"); + return namedDataSources().get(dataSourceName).reactive(); } @ConfigGroup diff --git a/extensions/reactive-datasource/runtime/src/main/java/io/quarkus/reactive/datasource/runtime/DataSourcesReactiveRuntimeConfig.java b/extensions/reactive-datasource/runtime/src/main/java/io/quarkus/reactive/datasource/runtime/DataSourcesReactiveRuntimeConfig.java index 465e7bd42ead47..4d2243e74fc30e 100644 --- a/extensions/reactive-datasource/runtime/src/main/java/io/quarkus/reactive/datasource/runtime/DataSourcesReactiveRuntimeConfig.java +++ b/extensions/reactive-datasource/runtime/src/main/java/io/quarkus/reactive/datasource/runtime/DataSourcesReactiveRuntimeConfig.java @@ -8,8 +8,8 @@ import io.quarkus.runtime.annotations.ConfigGroup; import io.quarkus.runtime.annotations.ConfigPhase; import io.quarkus.runtime.annotations.ConfigRoot; -import io.quarkus.runtime.configuration.ConfigUtils; import io.smallrye.config.ConfigMapping; +import io.smallrye.config.WithDefaults; import io.smallrye.config.WithName; import io.smallrye.config.WithParentName; @@ -29,6 +29,7 @@ public interface DataSourcesReactiveRuntimeConfig { @ConfigDocSection @ConfigDocMapKey("datasource-name") @WithParentName + @WithDefaults Map namedDataSources(); default DataSourceReactiveRuntimeConfig getDataSourceReactiveRuntimeConfig(String dataSourceName) { @@ -36,13 +37,7 @@ default DataSourceReactiveRuntimeConfig getDataSourceReactiveRuntimeConfig(Strin return defaultDataSource(); } - DataSourceReactiveOuterNamedRuntimeConfig dataSourceReactiveRuntimeConfig = namedDataSources().get(dataSourceName); - - if (dataSourceReactiveRuntimeConfig != null) { - return dataSourceReactiveRuntimeConfig.reactive(); - } - - return ConfigUtils.getInitializedConfigGroup(DataSourceReactiveRuntimeConfig.class, "quarkus.datasource.*.reactive"); + return namedDataSources().get(dataSourceName).reactive(); } @ConfigGroup diff --git a/extensions/reactive-db2-client/deployment/src/main/java/io/quarkus/reactive/db2/client/deployment/ReactiveDB2ClientProcessor.java b/extensions/reactive-db2-client/deployment/src/main/java/io/quarkus/reactive/db2/client/deployment/ReactiveDB2ClientProcessor.java index a84883a5c67c23..4fef9763a80fd8 100644 --- a/extensions/reactive-db2-client/deployment/src/main/java/io/quarkus/reactive/db2/client/deployment/ReactiveDB2ClientProcessor.java +++ b/extensions/reactive-db2-client/deployment/src/main/java/io/quarkus/reactive/db2/client/deployment/ReactiveDB2ClientProcessor.java @@ -80,12 +80,7 @@ ServiceStartBuildItem build(BuildProducer feature, feature.produce(new FeatureBuildItem(Feature.REACTIVE_DB2_CLIENT)); - createPoolIfDefined(recorder, vertx, eventLoopCount, shutdown, db2Pool, vertxPool, syntheticBeans, - DataSourceUtil.DEFAULT_DATASOURCE_NAME, dataSourcesBuildTimeConfig, - dataSourcesRuntimeConfig, dataSourcesReactiveBuildTimeConfig, dataSourcesReactiveRuntimeConfig, - dataSourcesReactiveDB2Config, defaultDataSourceDbKindBuildItems, curateOutcomeBuildItem); - - for (String dataSourceName : dataSourcesBuildTimeConfig.namedDataSources().keySet()) { + for (String dataSourceName : dataSourcesBuildTimeConfig.dataSources().keySet()) { createPoolIfDefined(recorder, vertx, eventLoopCount, shutdown, db2Pool, vertxPool, syntheticBeans, dataSourceName, dataSourcesBuildTimeConfig, dataSourcesRuntimeConfig, dataSourcesReactiveBuildTimeConfig, dataSourcesReactiveRuntimeConfig, dataSourcesReactiveDB2Config, defaultDataSourceDbKindBuildItems, @@ -229,14 +224,14 @@ private static boolean isReactiveDB2PoolDefined(DataSourcesBuildTimeConfig dataS List defaultDataSourceDbKindBuildItems, CurateOutcomeBuildItem curateOutcomeBuildItem) { DataSourceBuildTimeConfig dataSourceBuildTimeConfig = dataSourcesBuildTimeConfig - .getDataSourceBuildTimeConfig(dataSourceName); + .dataSources().get(dataSourceName); DataSourceReactiveBuildTimeConfig dataSourceReactiveBuildTimeConfig = dataSourcesReactiveBuildTimeConfig .getDataSourceReactiveBuildTimeConfig(dataSourceName); Optional dbKind = DefaultDataSourceDbKindBuildItem.resolve(dataSourceBuildTimeConfig.dbKind(), defaultDataSourceDbKindBuildItems, !DataSourceUtil.isDefault(dataSourceName) || dataSourceBuildTimeConfig.devservices().enabled() - .orElse(dataSourcesBuildTimeConfig.namedDataSources().isEmpty()), + .orElse(!dataSourcesBuildTimeConfig.hasNamedDataSources()), curateOutcomeBuildItem); if (!dbKind.isPresent()) { @@ -260,7 +255,7 @@ private boolean hasPools(DataSourcesBuildTimeConfig dataSourcesBuildTimeConfig, return true; } - for (String dataSourceName : dataSourcesBuildTimeConfig.namedDataSources().keySet()) { + for (String dataSourceName : dataSourcesBuildTimeConfig.dataSources().keySet()) { if (isReactiveDB2PoolDefined(dataSourcesBuildTimeConfig, dataSourcesReactiveBuildTimeConfig, dataSourceName, defaultDataSourceDbKindBuildItems, curateOutcomeBuildItem)) { return true; diff --git a/extensions/reactive-db2-client/runtime/src/main/java/io/quarkus/reactive/db2/client/runtime/DB2PoolRecorder.java b/extensions/reactive-db2-client/runtime/src/main/java/io/quarkus/reactive/db2/client/runtime/DB2PoolRecorder.java index 01676eeef30841..55e13995babb15 100644 --- a/extensions/reactive-db2-client/runtime/src/main/java/io/quarkus/reactive/db2/client/runtime/DB2PoolRecorder.java +++ b/extensions/reactive-db2-client/runtime/src/main/java/io/quarkus/reactive/db2/client/runtime/DB2PoolRecorder.java @@ -56,9 +56,9 @@ public RuntimeValue configureDB2Pool(RuntimeValue vertx, DB2Pool db2Pool = initialize((VertxInternal) vertx.getValue(), eventLoopCount.get(), dataSourceName, - dataSourcesRuntimeConfig.getDataSourceRuntimeConfig(dataSourceName), + dataSourcesRuntimeConfig.dataSources().get(dataSourceName), dataSourcesReactiveRuntimeConfig.getDataSourceReactiveRuntimeConfig(dataSourceName), - dataSourcesReactiveDB2Config.getDataSourceReactiveRuntimeConfig(dataSourceName)); + dataSourcesReactiveDB2Config.dataSources().get(dataSourceName).reactive().db2()); shutdown.addShutdownTask(db2Pool::close); return new RuntimeValue<>(db2Pool); @@ -175,7 +175,7 @@ private DB2ConnectOptions toConnectOptions(String dataSourceName, DataSourceRunt connectOptions.setCachePreparedStatements(dataSourceReactiveRuntimeConfig.cachePreparedStatements()); - connectOptions.setSsl(dataSourceReactiveDB2Config.ssl); + connectOptions.setSsl(dataSourceReactiveDB2Config.ssl()); connectOptions.setTrustAll(dataSourceReactiveRuntimeConfig.trustAll()); diff --git a/extensions/reactive-db2-client/runtime/src/main/java/io/quarkus/reactive/db2/client/runtime/DataSourceReactiveDB2Config.java b/extensions/reactive-db2-client/runtime/src/main/java/io/quarkus/reactive/db2/client/runtime/DataSourceReactiveDB2Config.java index bb0ac8a9e82c7e..b0e31b203fefa9 100644 --- a/extensions/reactive-db2-client/runtime/src/main/java/io/quarkus/reactive/db2/client/runtime/DataSourceReactiveDB2Config.java +++ b/extensions/reactive-db2-client/runtime/src/main/java/io/quarkus/reactive/db2/client/runtime/DataSourceReactiveDB2Config.java @@ -1,15 +1,15 @@ package io.quarkus.reactive.db2.client.runtime; import io.quarkus.runtime.annotations.ConfigGroup; -import io.quarkus.runtime.annotations.ConfigItem; +import io.smallrye.config.WithDefault; @ConfigGroup -public class DataSourceReactiveDB2Config { +public interface DataSourceReactiveDB2Config { /** * Whether SSL/TLS is enabled. */ - @ConfigItem(defaultValue = "false") - public boolean ssl = false; + @WithDefault("false") + public boolean ssl(); } diff --git a/extensions/reactive-db2-client/runtime/src/main/java/io/quarkus/reactive/db2/client/runtime/DataSourcesReactiveDB2Config.java b/extensions/reactive-db2-client/runtime/src/main/java/io/quarkus/reactive/db2/client/runtime/DataSourcesReactiveDB2Config.java index 669b1f2047ccb5..b9dbd97c8d2205 100644 --- a/extensions/reactive-db2-client/runtime/src/main/java/io/quarkus/reactive/db2/client/runtime/DataSourcesReactiveDB2Config.java +++ b/extensions/reactive-db2-client/runtime/src/main/java/io/quarkus/reactive/db2/client/runtime/DataSourcesReactiveDB2Config.java @@ -6,57 +6,43 @@ import io.quarkus.runtime.annotations.ConfigDocMapKey; import io.quarkus.runtime.annotations.ConfigDocSection; import io.quarkus.runtime.annotations.ConfigGroup; -import io.quarkus.runtime.annotations.ConfigItem; import io.quarkus.runtime.annotations.ConfigPhase; import io.quarkus.runtime.annotations.ConfigRoot; +import io.smallrye.config.ConfigMapping; +import io.smallrye.config.WithDefaults; +import io.smallrye.config.WithParentName; +import io.smallrye.config.WithUnnamedKey; -@ConfigRoot(name = "datasource", phase = ConfigPhase.RUN_TIME) -public class DataSourcesReactiveDB2Config { +@ConfigMapping(prefix = "quarkus.datasource") +@ConfigRoot(phase = ConfigPhase.RUN_TIME) +public interface DataSourcesReactiveDB2Config { /** - * The default datasource. - */ - @ConfigItem(name = "reactive.db2") - public DataSourceReactiveDB2Config defaultDataSource; - - /** - * Additional named datasources. + * Datasources. */ @ConfigDocSection @ConfigDocMapKey("datasource-name") - @ConfigItem(name = ConfigItem.PARENT) - public Map namedDataSources; - - public DataSourceReactiveDB2Config getDataSourceReactiveRuntimeConfig(String dataSourceName) { - if (DataSourceUtil.isDefault(dataSourceName)) { - return defaultDataSource; - } - - DataSourceReactiveDB2OuterNamedConfig dataSourceReactiveDB2OuterNamedConfig = namedDataSources - .get(dataSourceName); - if (dataSourceReactiveDB2OuterNamedConfig == null) { - return new DataSourceReactiveDB2Config(); - } - - return dataSourceReactiveDB2OuterNamedConfig.reactive.db2; - } + @WithParentName + @WithDefaults + @WithUnnamedKey(DataSourceUtil.DEFAULT_DATASOURCE_NAME) + Map dataSources(); @ConfigGroup - public static class DataSourceReactiveDB2OuterNamedConfig { + public interface DataSourceReactiveDB2OuterNamedConfig { /** * The DB2-specific configuration. */ - public DataSourceReactiveDB2OuterNestedNamedConfig reactive; + DataSourceReactiveDB2OuterNestedNamedConfig reactive(); } @ConfigGroup - public static class DataSourceReactiveDB2OuterNestedNamedConfig { + public interface DataSourceReactiveDB2OuterNestedNamedConfig { /** * The DB2-specific configuration. */ - public DataSourceReactiveDB2Config db2; + DataSourceReactiveDB2Config db2(); } } diff --git a/extensions/reactive-mssql-client/deployment/src/main/java/io/quarkus/reactive/mssql/client/deployment/ReactiveMSSQLClientProcessor.java b/extensions/reactive-mssql-client/deployment/src/main/java/io/quarkus/reactive/mssql/client/deployment/ReactiveMSSQLClientProcessor.java index af0e8f320e5978..ff740e9276ed24 100644 --- a/extensions/reactive-mssql-client/deployment/src/main/java/io/quarkus/reactive/mssql/client/deployment/ReactiveMSSQLClientProcessor.java +++ b/extensions/reactive-mssql-client/deployment/src/main/java/io/quarkus/reactive/mssql/client/deployment/ReactiveMSSQLClientProcessor.java @@ -80,12 +80,7 @@ ServiceStartBuildItem build(BuildProducer feature, feature.produce(new FeatureBuildItem(Feature.REACTIVE_MSSQL_CLIENT)); - createPoolIfDefined(recorder, vertx, eventLoopCount, shutdown, msSQLPool, vertxPool, syntheticBeans, - DataSourceUtil.DEFAULT_DATASOURCE_NAME, dataSourcesBuildTimeConfig, - dataSourcesRuntimeConfig, dataSourcesReactiveBuildTimeConfig, dataSourcesReactiveRuntimeConfig, - dataSourcesReactiveMSSQLConfig, defaultDataSourceDbKindBuildItems, curateOutcomeBuildItem); - - for (String dataSourceName : dataSourcesBuildTimeConfig.namedDataSources().keySet()) { + for (String dataSourceName : dataSourcesBuildTimeConfig.dataSources().keySet()) { createPoolIfDefined(recorder, vertx, eventLoopCount, shutdown, msSQLPool, vertxPool, syntheticBeans, dataSourceName, dataSourcesBuildTimeConfig, dataSourcesRuntimeConfig, dataSourcesReactiveBuildTimeConfig, dataSourcesReactiveRuntimeConfig, dataSourcesReactiveMSSQLConfig, defaultDataSourceDbKindBuildItems, @@ -229,14 +224,14 @@ private static boolean isReactiveMSSQLPoolDefined(DataSourcesBuildTimeConfig dat List defaultDataSourceDbKindBuildItems, CurateOutcomeBuildItem curateOutcomeBuildItem) { DataSourceBuildTimeConfig dataSourceBuildTimeConfig = dataSourcesBuildTimeConfig - .getDataSourceBuildTimeConfig(dataSourceName); + .dataSources().get(dataSourceName); DataSourceReactiveBuildTimeConfig dataSourceReactiveBuildTimeConfig = dataSourcesReactiveBuildTimeConfig .getDataSourceReactiveBuildTimeConfig(dataSourceName); Optional dbKind = DefaultDataSourceDbKindBuildItem.resolve(dataSourceBuildTimeConfig.dbKind(), defaultDataSourceDbKindBuildItems, !DataSourceUtil.isDefault(dataSourceName) || dataSourceBuildTimeConfig.devservices().enabled() - .orElse(dataSourcesBuildTimeConfig.namedDataSources().isEmpty()), + .orElse(!dataSourcesBuildTimeConfig.hasNamedDataSources()), curateOutcomeBuildItem); if (!dbKind.isPresent()) { return false; @@ -259,7 +254,7 @@ private boolean hasPools(DataSourcesBuildTimeConfig dataSourcesBuildTimeConfig, return true; } - for (String dataSourceName : dataSourcesBuildTimeConfig.namedDataSources().keySet()) { + for (String dataSourceName : dataSourcesBuildTimeConfig.dataSources().keySet()) { if (isReactiveMSSQLPoolDefined(dataSourcesBuildTimeConfig, dataSourcesReactiveBuildTimeConfig, dataSourceName, defaultDataSourceDbKindBuildItems, curateOutcomeBuildItem)) { return true; diff --git a/extensions/reactive-mssql-client/pom.xml b/extensions/reactive-mssql-client/pom.xml index 4dc267f9144324..446792c43806f2 100644 --- a/extensions/reactive-mssql-client/pom.xml +++ b/extensions/reactive-mssql-client/pom.xml @@ -14,7 +14,7 @@ quarkus-reactive-mssql-client-parent pom - Quarkus - Reactive MS SQL Client + Quarkus - Reactive Microsoft SQL Server Client deployment diff --git a/extensions/reactive-mssql-client/runtime/src/main/java/io/quarkus/reactive/mssql/client/runtime/DataSourceReactiveMSSQLConfig.java b/extensions/reactive-mssql-client/runtime/src/main/java/io/quarkus/reactive/mssql/client/runtime/DataSourceReactiveMSSQLConfig.java index d682728b6c6672..68ae7a7d0bc587 100644 --- a/extensions/reactive-mssql-client/runtime/src/main/java/io/quarkus/reactive/mssql/client/runtime/DataSourceReactiveMSSQLConfig.java +++ b/extensions/reactive-mssql-client/runtime/src/main/java/io/quarkus/reactive/mssql/client/runtime/DataSourceReactiveMSSQLConfig.java @@ -3,21 +3,20 @@ import java.util.OptionalInt; import io.quarkus.runtime.annotations.ConfigGroup; -import io.quarkus.runtime.annotations.ConfigItem; +import io.smallrye.config.WithDefault; @ConfigGroup -public class DataSourceReactiveMSSQLConfig { +public interface DataSourceReactiveMSSQLConfig { /** * The desired size (in bytes) for TDS packets. */ - @ConfigItem - public OptionalInt packetSize = OptionalInt.empty(); + OptionalInt packetSize(); /** * Whether SSL/TLS is enabled. */ - @ConfigItem(defaultValue = "false") - public boolean ssl = false; + @WithDefault("false") + public boolean ssl(); } diff --git a/extensions/reactive-mssql-client/runtime/src/main/java/io/quarkus/reactive/mssql/client/runtime/DataSourcesReactiveMSSQLConfig.java b/extensions/reactive-mssql-client/runtime/src/main/java/io/quarkus/reactive/mssql/client/runtime/DataSourcesReactiveMSSQLConfig.java index 3b40b2d3d76e73..c7c16fb92d7008 100644 --- a/extensions/reactive-mssql-client/runtime/src/main/java/io/quarkus/reactive/mssql/client/runtime/DataSourcesReactiveMSSQLConfig.java +++ b/extensions/reactive-mssql-client/runtime/src/main/java/io/quarkus/reactive/mssql/client/runtime/DataSourcesReactiveMSSQLConfig.java @@ -6,57 +6,43 @@ import io.quarkus.runtime.annotations.ConfigDocMapKey; import io.quarkus.runtime.annotations.ConfigDocSection; import io.quarkus.runtime.annotations.ConfigGroup; -import io.quarkus.runtime.annotations.ConfigItem; import io.quarkus.runtime.annotations.ConfigPhase; import io.quarkus.runtime.annotations.ConfigRoot; +import io.smallrye.config.ConfigMapping; +import io.smallrye.config.WithDefaults; +import io.smallrye.config.WithParentName; +import io.smallrye.config.WithUnnamedKey; -@ConfigRoot(name = "datasource", phase = ConfigPhase.RUN_TIME) -public class DataSourcesReactiveMSSQLConfig { +@ConfigMapping(prefix = "quarkus.datasource") +@ConfigRoot(phase = ConfigPhase.RUN_TIME) +public interface DataSourcesReactiveMSSQLConfig { /** - * The default datasource. - */ - @ConfigItem(name = "reactive.mssql") - public DataSourceReactiveMSSQLConfig defaultDataSource; - - /** - * Additional named datasources. + * Datasources. */ @ConfigDocSection @ConfigDocMapKey("datasource-name") - @ConfigItem(name = ConfigItem.PARENT) - public Map namedDataSources; - - public DataSourceReactiveMSSQLConfig getDataSourceReactiveRuntimeConfig(String dataSourceName) { - if (DataSourceUtil.isDefault(dataSourceName)) { - return defaultDataSource; - } - - DataSourceReactiveMSSQLOuterNamedConfig dataSourceReactiveMSSQLOuterNamedConfig = namedDataSources - .get(dataSourceName); - if (dataSourceReactiveMSSQLOuterNamedConfig == null) { - return new DataSourceReactiveMSSQLConfig(); - } - - return dataSourceReactiveMSSQLOuterNamedConfig.reactive.mssql; - } + @WithParentName + @WithDefaults + @WithUnnamedKey(DataSourceUtil.DEFAULT_DATASOURCE_NAME) + Map dataSources(); @ConfigGroup - public static class DataSourceReactiveMSSQLOuterNamedConfig { + public interface DataSourceReactiveMSSQLOuterNamedConfig { /** * The MSSQL-specific configuration. */ - public DataSourceReactiveMSSQLOuterNestedNamedConfig reactive; + DataSourceReactiveMSSQLOuterNestedNamedConfig reactive(); } @ConfigGroup - public static class DataSourceReactiveMSSQLOuterNestedNamedConfig { + public interface DataSourceReactiveMSSQLOuterNestedNamedConfig { /** * The MSSQL-specific configuration. */ - public DataSourceReactiveMSSQLConfig mssql; + DataSourceReactiveMSSQLConfig mssql(); } } diff --git a/extensions/reactive-mssql-client/runtime/src/main/java/io/quarkus/reactive/mssql/client/runtime/MSSQLPoolRecorder.java b/extensions/reactive-mssql-client/runtime/src/main/java/io/quarkus/reactive/mssql/client/runtime/MSSQLPoolRecorder.java index 7ec76ee2ae92a6..8f8832035617ae 100644 --- a/extensions/reactive-mssql-client/runtime/src/main/java/io/quarkus/reactive/mssql/client/runtime/MSSQLPoolRecorder.java +++ b/extensions/reactive-mssql-client/runtime/src/main/java/io/quarkus/reactive/mssql/client/runtime/MSSQLPoolRecorder.java @@ -56,9 +56,9 @@ public RuntimeValue configureMSSQLPool(RuntimeValue vertx, MSSQLPool mssqlPool = initialize((VertxInternal) vertx.getValue(), eventLoopCount.get(), dataSourceName, - dataSourcesRuntimeConfig.getDataSourceRuntimeConfig(dataSourceName), + dataSourcesRuntimeConfig.dataSources().get(dataSourceName), dataSourcesReactiveRuntimeConfig.getDataSourceReactiveRuntimeConfig(dataSourceName), - dataSourcesReactiveMSSQLConfig.getDataSourceReactiveRuntimeConfig(dataSourceName)); + dataSourcesReactiveMSSQLConfig.dataSources().get(dataSourceName).reactive().mssql()); shutdown.addShutdownTask(mssqlPool::close); return new RuntimeValue<>(mssqlPool); @@ -148,8 +148,8 @@ private MSSQLConnectOptions toMSSQLConnectOptions(String dataSourceName, DataSou mssqlConnectOptions = new MSSQLConnectOptions(); } - if (dataSourceReactiveMSSQLConfig.packetSize.isPresent()) { - mssqlConnectOptions.setPacketSize(dataSourceReactiveMSSQLConfig.packetSize.getAsInt()); + if (dataSourceReactiveMSSQLConfig.packetSize().isPresent()) { + mssqlConnectOptions.setPacketSize(dataSourceReactiveMSSQLConfig.packetSize().getAsInt()); } if (dataSourceRuntimeConfig.username().isPresent()) { @@ -180,7 +180,7 @@ private MSSQLConnectOptions toMSSQLConnectOptions(String dataSourceName, DataSou mssqlConnectOptions.setReconnectInterval(dataSourceReactiveRuntimeConfig.reconnectInterval().toMillis()); - mssqlConnectOptions.setSsl(dataSourceReactiveMSSQLConfig.ssl); + mssqlConnectOptions.setSsl(dataSourceReactiveMSSQLConfig.ssl()); mssqlConnectOptions.setTrustAll(dataSourceReactiveRuntimeConfig.trustAll()); diff --git a/extensions/reactive-mysql-client/deployment/src/main/java/io/quarkus/reactive/mysql/client/deployment/ReactiveMySQLClientProcessor.java b/extensions/reactive-mysql-client/deployment/src/main/java/io/quarkus/reactive/mysql/client/deployment/ReactiveMySQLClientProcessor.java index 133803b3e4e49d..7a31ef9cc19270 100644 --- a/extensions/reactive-mysql-client/deployment/src/main/java/io/quarkus/reactive/mysql/client/deployment/ReactiveMySQLClientProcessor.java +++ b/extensions/reactive-mysql-client/deployment/src/main/java/io/quarkus/reactive/mysql/client/deployment/ReactiveMySQLClientProcessor.java @@ -80,12 +80,7 @@ ServiceStartBuildItem build(BuildProducer feature, feature.produce(new FeatureBuildItem(Feature.REACTIVE_MYSQL_CLIENT)); - createPoolIfDefined(recorder, vertx, eventLoopCount, shutdown, mySQLPool, vertxPool, syntheticBeans, - DataSourceUtil.DEFAULT_DATASOURCE_NAME, dataSourcesBuildTimeConfig, - dataSourcesRuntimeConfig, dataSourcesReactiveBuildTimeConfig, dataSourcesReactiveRuntimeConfig, - dataSourcesReactiveMySQLConfig, defaultDataSourceDbKindBuildItems, curateOutcomeBuildItem); - - for (String dataSourceName : dataSourcesBuildTimeConfig.namedDataSources().keySet()) { + for (String dataSourceName : dataSourcesBuildTimeConfig.dataSources().keySet()) { createPoolIfDefined(recorder, vertx, eventLoopCount, shutdown, mySQLPool, vertxPool, syntheticBeans, dataSourceName, dataSourcesBuildTimeConfig, dataSourcesRuntimeConfig, dataSourcesReactiveBuildTimeConfig, dataSourcesReactiveRuntimeConfig, dataSourcesReactiveMySQLConfig, defaultDataSourceDbKindBuildItems, @@ -230,14 +225,14 @@ private static boolean isReactiveMySQLPoolDefined(DataSourcesBuildTimeConfig dat List defaultDataSourceDbKindBuildItems, CurateOutcomeBuildItem curateOutcomeBuildItem) { DataSourceBuildTimeConfig dataSourceBuildTimeConfig = dataSourcesBuildTimeConfig - .getDataSourceBuildTimeConfig(dataSourceName); + .dataSources().get(dataSourceName); DataSourceReactiveBuildTimeConfig dataSourceReactiveBuildTimeConfig = dataSourcesReactiveBuildTimeConfig .getDataSourceReactiveBuildTimeConfig(dataSourceName); Optional dbKind = DefaultDataSourceDbKindBuildItem.resolve(dataSourceBuildTimeConfig.dbKind(), defaultDataSourceDbKindBuildItems, !DataSourceUtil.isDefault(dataSourceName) || dataSourceBuildTimeConfig.devservices().enabled() - .orElse(dataSourcesBuildTimeConfig.namedDataSources().isEmpty()), + .orElse(!dataSourcesBuildTimeConfig.hasNamedDataSources()), curateOutcomeBuildItem); if (!dbKind.isPresent()) { return false; @@ -261,7 +256,7 @@ private boolean hasPools(DataSourcesBuildTimeConfig dataSourcesBuildTimeConfig, return true; } - for (String dataSourceName : dataSourcesBuildTimeConfig.namedDataSources().keySet()) { + for (String dataSourceName : dataSourcesBuildTimeConfig.dataSources().keySet()) { if (isReactiveMySQLPoolDefined(dataSourcesBuildTimeConfig, dataSourcesReactiveBuildTimeConfig, dataSourceName, defaultDataSourceDbKindBuildItems, curateOutcomeBuildItem)) { return true; diff --git a/extensions/reactive-mysql-client/runtime/src/main/java/io/quarkus/reactive/mysql/client/runtime/DataSourceReactiveMySQLConfig.java b/extensions/reactive-mysql-client/runtime/src/main/java/io/quarkus/reactive/mysql/client/runtime/DataSourceReactiveMySQLConfig.java index c4d2219f919aee..6d23674133b6b2 100644 --- a/extensions/reactive-mysql-client/runtime/src/main/java/io/quarkus/reactive/mysql/client/runtime/DataSourceReactiveMySQLConfig.java +++ b/extensions/reactive-mysql-client/runtime/src/main/java/io/quarkus/reactive/mysql/client/runtime/DataSourceReactiveMySQLConfig.java @@ -3,25 +3,23 @@ import java.util.Optional; import java.util.OptionalInt; +import io.quarkus.runtime.annotations.ConfigDocDefault; import io.quarkus.runtime.annotations.ConfigGroup; -import io.quarkus.runtime.annotations.ConfigItem; import io.vertx.mysqlclient.MySQLAuthenticationPlugin; import io.vertx.mysqlclient.SslMode; @ConfigGroup -public class DataSourceReactiveMySQLConfig { +public interface DataSourceReactiveMySQLConfig { /** * Charset for connections. */ - @ConfigItem - public Optional charset = Optional.empty(); + Optional charset(); /** * Collation for connections. */ - @ConfigItem - public Optional collation = Optional.empty(); + Optional collation(); /** * Desired security state of the connection to the server. @@ -29,33 +27,31 @@ public class DataSourceReactiveMySQLConfig { * See MySQL Reference * Manual. */ - @ConfigItem(defaultValueDocumentation = "disabled") - public Optional sslMode = Optional.empty(); + @ConfigDocDefault("disabled") + Optional sslMode(); /** * Connection timeout in seconds */ - @ConfigItem() - public OptionalInt connectionTimeout = OptionalInt.empty(); + OptionalInt connectionTimeout(); /** * The authentication plugin the client should use. * By default, it uses the plugin name specified by the server in the initial handshake packet. */ - @ConfigItem(defaultValueDocumentation = "default") - public Optional authenticationPlugin = Optional.empty(); + @ConfigDocDefault("default") + Optional authenticationPlugin(); /** * The maximum number of inflight database commands that can be pipelined. * By default, pipelining is disabled. */ - @ConfigItem - public OptionalInt pipeliningLimit = OptionalInt.empty(); + OptionalInt pipeliningLimit(); /** * Whether to return the number of rows matched by the WHERE clause in UPDATE statements, instead of the * number of rows actually changed. */ - @ConfigItem(defaultValueDocumentation = "false") - public Optional useAffectedRows = Optional.empty(); + @ConfigDocDefault("false") + Optional useAffectedRows(); } diff --git a/extensions/reactive-mysql-client/runtime/src/main/java/io/quarkus/reactive/mysql/client/runtime/DataSourcesReactiveMySQLConfig.java b/extensions/reactive-mysql-client/runtime/src/main/java/io/quarkus/reactive/mysql/client/runtime/DataSourcesReactiveMySQLConfig.java index 1e6be7b48abda9..fee52e5c31dd33 100644 --- a/extensions/reactive-mysql-client/runtime/src/main/java/io/quarkus/reactive/mysql/client/runtime/DataSourcesReactiveMySQLConfig.java +++ b/extensions/reactive-mysql-client/runtime/src/main/java/io/quarkus/reactive/mysql/client/runtime/DataSourcesReactiveMySQLConfig.java @@ -6,57 +6,43 @@ import io.quarkus.runtime.annotations.ConfigDocMapKey; import io.quarkus.runtime.annotations.ConfigDocSection; import io.quarkus.runtime.annotations.ConfigGroup; -import io.quarkus.runtime.annotations.ConfigItem; import io.quarkus.runtime.annotations.ConfigPhase; import io.quarkus.runtime.annotations.ConfigRoot; +import io.smallrye.config.ConfigMapping; +import io.smallrye.config.WithDefaults; +import io.smallrye.config.WithParentName; +import io.smallrye.config.WithUnnamedKey; -@ConfigRoot(name = "datasource", phase = ConfigPhase.RUN_TIME) -public class DataSourcesReactiveMySQLConfig { - - /** - * The default datasource. - */ - @ConfigItem(name = "reactive.mysql") - public DataSourceReactiveMySQLConfig defaultDataSource; +@ConfigMapping(prefix = "quarkus.datasource") +@ConfigRoot(phase = ConfigPhase.RUN_TIME) +public interface DataSourcesReactiveMySQLConfig { /** * Additional named datasources. */ @ConfigDocSection @ConfigDocMapKey("datasource-name") - @ConfigItem(name = ConfigItem.PARENT) - public Map namedDataSources; - - public DataSourceReactiveMySQLConfig getDataSourceReactiveRuntimeConfig(String dataSourceName) { - if (DataSourceUtil.isDefault(dataSourceName)) { - return defaultDataSource; - } - - DataSourceReactiveMySQLOuterNamedConfig dataSourceReactiveMySQLOuterNamedConfig = namedDataSources - .get(dataSourceName); - if (dataSourceReactiveMySQLOuterNamedConfig == null) { - return new DataSourceReactiveMySQLConfig(); - } - - return dataSourceReactiveMySQLOuterNamedConfig.reactive.mysql; - } + @WithParentName + @WithDefaults + @WithUnnamedKey(DataSourceUtil.DEFAULT_DATASOURCE_NAME) + Map dataSources(); @ConfigGroup - public static class DataSourceReactiveMySQLOuterNamedConfig { + public interface DataSourceReactiveMySQLOuterNamedConfig { /** * The MySQL-specific configuration. */ - public DataSourceReactiveMySQLOuterNestedNamedConfig reactive; + DataSourceReactiveMySQLOuterNestedNamedConfig reactive(); } @ConfigGroup - public static class DataSourceReactiveMySQLOuterNestedNamedConfig { + public interface DataSourceReactiveMySQLOuterNestedNamedConfig { /** * The MySQL-specific configuration. */ - public DataSourceReactiveMySQLConfig mysql; + DataSourceReactiveMySQLConfig mysql(); } } diff --git a/extensions/reactive-mysql-client/runtime/src/main/java/io/quarkus/reactive/mysql/client/runtime/MySQLPoolRecorder.java b/extensions/reactive-mysql-client/runtime/src/main/java/io/quarkus/reactive/mysql/client/runtime/MySQLPoolRecorder.java index 6e378f83acd473..fa692890e8a11e 100644 --- a/extensions/reactive-mysql-client/runtime/src/main/java/io/quarkus/reactive/mysql/client/runtime/MySQLPoolRecorder.java +++ b/extensions/reactive-mysql-client/runtime/src/main/java/io/quarkus/reactive/mysql/client/runtime/MySQLPoolRecorder.java @@ -54,9 +54,9 @@ public RuntimeValue configureMySQLPool(RuntimeValue vertx, MySQLPool mysqlPool = initialize((VertxInternal) vertx.getValue(), eventLoopCount.get(), dataSourceName, - dataSourcesRuntimeConfig.getDataSourceRuntimeConfig(dataSourceName), + dataSourcesRuntimeConfig.dataSources().get(dataSourceName), dataSourcesReactiveRuntimeConfig.getDataSourceReactiveRuntimeConfig(dataSourceName), - dataSourcesReactiveMySQLConfig.getDataSourceReactiveRuntimeConfig(dataSourceName)); + dataSourcesReactiveMySQLConfig.dataSources().get(dataSourceName).reactive().mysql()); shutdown.addShutdownTask(mysqlPool::close); return new RuntimeValue<>(mysqlPool); @@ -124,8 +124,8 @@ private PoolOptions toPoolOptions(Integer eventLoopCount, poolOptions.setEventLoopSize(Math.max(0, eventLoopCount)); } - if (dataSourceReactiveMySQLConfig.connectionTimeout.isPresent()) { - poolOptions.setConnectionTimeout(dataSourceReactiveMySQLConfig.connectionTimeout.getAsInt()); + if (dataSourceReactiveMySQLConfig.connectionTimeout().isPresent()) { + poolOptions.setConnectionTimeout(dataSourceReactiveMySQLConfig.connectionTimeout().getAsInt()); poolOptions.setConnectionTimeoutUnit(TimeUnit.SECONDS); } @@ -173,17 +173,17 @@ private List toMySQLConnectOptions(String dataSourceName, mysqlConnectOptions.setCachePreparedStatements(dataSourceReactiveRuntimeConfig.cachePreparedStatements()); - dataSourceReactiveMySQLConfig.charset.ifPresent(mysqlConnectOptions::setCharset); - dataSourceReactiveMySQLConfig.collation.ifPresent(mysqlConnectOptions::setCollation); + dataSourceReactiveMySQLConfig.charset().ifPresent(mysqlConnectOptions::setCharset); + dataSourceReactiveMySQLConfig.collation().ifPresent(mysqlConnectOptions::setCollation); - if (dataSourceReactiveMySQLConfig.pipeliningLimit.isPresent()) { - mysqlConnectOptions.setPipeliningLimit(dataSourceReactiveMySQLConfig.pipeliningLimit.getAsInt()); + if (dataSourceReactiveMySQLConfig.pipeliningLimit().isPresent()) { + mysqlConnectOptions.setPipeliningLimit(dataSourceReactiveMySQLConfig.pipeliningLimit().getAsInt()); } - dataSourceReactiveMySQLConfig.useAffectedRows.ifPresent(mysqlConnectOptions::setUseAffectedRows); + dataSourceReactiveMySQLConfig.useAffectedRows().ifPresent(mysqlConnectOptions::setUseAffectedRows); - if (dataSourceReactiveMySQLConfig.sslMode.isPresent()) { - final SslMode sslMode = dataSourceReactiveMySQLConfig.sslMode.get(); + if (dataSourceReactiveMySQLConfig.sslMode().isPresent()) { + final SslMode sslMode = dataSourceReactiveMySQLConfig.sslMode().get(); mysqlConnectOptions.setSslMode(sslMode); // If sslMode is verify-identity, we also need a hostname verification algorithm @@ -211,7 +211,7 @@ private List toMySQLConnectOptions(String dataSourceName, dataSourceReactiveRuntimeConfig.hostnameVerificationAlgorithm().ifPresent( mysqlConnectOptions::setHostnameVerificationAlgorithm); - dataSourceReactiveMySQLConfig.authenticationPlugin.ifPresent(mysqlConnectOptions::setAuthenticationPlugin); + dataSourceReactiveMySQLConfig.authenticationPlugin().ifPresent(mysqlConnectOptions::setAuthenticationPlugin); dataSourceReactiveRuntimeConfig.additionalProperties().forEach(mysqlConnectOptions::addProperty); diff --git a/extensions/reactive-oracle-client/deployment/src/main/java/io/quarkus/reactive/oracle/client/deployment/ReactiveOracleClientProcessor.java b/extensions/reactive-oracle-client/deployment/src/main/java/io/quarkus/reactive/oracle/client/deployment/ReactiveOracleClientProcessor.java index 84b203417863c5..ec3d61852f3810 100644 --- a/extensions/reactive-oracle-client/deployment/src/main/java/io/quarkus/reactive/oracle/client/deployment/ReactiveOracleClientProcessor.java +++ b/extensions/reactive-oracle-client/deployment/src/main/java/io/quarkus/reactive/oracle/client/deployment/ReactiveOracleClientProcessor.java @@ -80,12 +80,7 @@ ServiceStartBuildItem build(BuildProducer feature, feature.produce(new FeatureBuildItem(Feature.REACTIVE_ORACLE_CLIENT)); - createPoolIfDefined(recorder, vertx, eventLoopCount, shutdown, oraclePool, vertxPool, syntheticBeans, - DataSourceUtil.DEFAULT_DATASOURCE_NAME, dataSourcesBuildTimeConfig, - dataSourcesRuntimeConfig, dataSourcesReactiveBuildTimeConfig, dataSourcesReactiveRuntimeConfig, - dataSourcesReactiveOracleConfig, defaultDataSourceDbKindBuildItems, curateOutcomeBuildItem); - - for (String dataSourceName : dataSourcesBuildTimeConfig.namedDataSources().keySet()) { + for (String dataSourceName : dataSourcesBuildTimeConfig.dataSources().keySet()) { createPoolIfDefined(recorder, vertx, eventLoopCount, shutdown, oraclePool, vertxPool, syntheticBeans, dataSourceName, dataSourcesBuildTimeConfig, dataSourcesRuntimeConfig, dataSourcesReactiveBuildTimeConfig, @@ -230,14 +225,14 @@ private static boolean isReactiveOraclePoolDefined(DataSourcesBuildTimeConfig da List defaultDataSourceDbKindBuildItems, CurateOutcomeBuildItem curateOutcomeBuildItem) { DataSourceBuildTimeConfig dataSourceBuildTimeConfig = dataSourcesBuildTimeConfig - .getDataSourceBuildTimeConfig(dataSourceName); + .dataSources().get(dataSourceName); DataSourceReactiveBuildTimeConfig dataSourceReactiveBuildTimeConfig = dataSourcesReactiveBuildTimeConfig .getDataSourceReactiveBuildTimeConfig(dataSourceName); Optional dbKind = DefaultDataSourceDbKindBuildItem.resolve(dataSourceBuildTimeConfig.dbKind(), defaultDataSourceDbKindBuildItems, !DataSourceUtil.isDefault(dataSourceName) || dataSourceBuildTimeConfig.devservices().enabled() - .orElse(dataSourcesBuildTimeConfig.namedDataSources().isEmpty()), + .orElse(!dataSourcesBuildTimeConfig.hasNamedDataSources()), curateOutcomeBuildItem); if (!dbKind.isPresent()) { return false; @@ -260,7 +255,7 @@ private boolean hasPools(DataSourcesBuildTimeConfig dataSourcesBuildTimeConfig, return true; } - for (String dataSourceName : dataSourcesBuildTimeConfig.namedDataSources().keySet()) { + for (String dataSourceName : dataSourcesBuildTimeConfig.dataSources().keySet()) { if (isReactiveOraclePoolDefined(dataSourcesBuildTimeConfig, dataSourcesReactiveBuildTimeConfig, dataSourceName, defaultDataSourceDbKindBuildItems, curateOutcomeBuildItem)) { return true; diff --git a/extensions/reactive-oracle-client/runtime/src/main/java/io/quarkus/reactive/oracle/client/runtime/DataSourceReactiveOracleConfig.java b/extensions/reactive-oracle-client/runtime/src/main/java/io/quarkus/reactive/oracle/client/runtime/DataSourceReactiveOracleConfig.java index 3b9f03afc29c1f..778e30be8ac137 100644 --- a/extensions/reactive-oracle-client/runtime/src/main/java/io/quarkus/reactive/oracle/client/runtime/DataSourceReactiveOracleConfig.java +++ b/extensions/reactive-oracle-client/runtime/src/main/java/io/quarkus/reactive/oracle/client/runtime/DataSourceReactiveOracleConfig.java @@ -3,6 +3,6 @@ import io.quarkus.runtime.annotations.ConfigGroup; @ConfigGroup -public class DataSourceReactiveOracleConfig { +public interface DataSourceReactiveOracleConfig { } diff --git a/extensions/reactive-oracle-client/runtime/src/main/java/io/quarkus/reactive/oracle/client/runtime/DataSourcesReactiveOracleConfig.java b/extensions/reactive-oracle-client/runtime/src/main/java/io/quarkus/reactive/oracle/client/runtime/DataSourcesReactiveOracleConfig.java index 73c146a9c5b90f..8067bcdcffa745 100644 --- a/extensions/reactive-oracle-client/runtime/src/main/java/io/quarkus/reactive/oracle/client/runtime/DataSourcesReactiveOracleConfig.java +++ b/extensions/reactive-oracle-client/runtime/src/main/java/io/quarkus/reactive/oracle/client/runtime/DataSourcesReactiveOracleConfig.java @@ -6,57 +6,43 @@ import io.quarkus.runtime.annotations.ConfigDocMapKey; import io.quarkus.runtime.annotations.ConfigDocSection; import io.quarkus.runtime.annotations.ConfigGroup; -import io.quarkus.runtime.annotations.ConfigItem; import io.quarkus.runtime.annotations.ConfigPhase; import io.quarkus.runtime.annotations.ConfigRoot; +import io.smallrye.config.ConfigMapping; +import io.smallrye.config.WithDefaults; +import io.smallrye.config.WithParentName; +import io.smallrye.config.WithUnnamedKey; -@ConfigRoot(name = "datasource", phase = ConfigPhase.RUN_TIME) -public class DataSourcesReactiveOracleConfig { +@ConfigMapping(prefix = "quarkus.datasource") +@ConfigRoot(phase = ConfigPhase.RUN_TIME) +public interface DataSourcesReactiveOracleConfig { /** - * The default datasource. - */ - @ConfigItem(name = "reactive.oracle") - public DataSourceReactiveOracleConfig defaultDataSource; - - /** - * Additional named datasources. + * Datasources. */ @ConfigDocSection @ConfigDocMapKey("datasource-name") - @ConfigItem(name = ConfigItem.PARENT) - public Map namedDataSources; - - public DataSourceReactiveOracleConfig getDataSourceReactiveRuntimeConfig(String dataSourceName) { - if (DataSourceUtil.isDefault(dataSourceName)) { - return defaultDataSource; - } - - DataSourceReactiveOracleOuterNamedConfig dataSourceReactiveOracleOuterNamedConfig = namedDataSources - .get(dataSourceName); - if (dataSourceReactiveOracleOuterNamedConfig == null) { - return new DataSourceReactiveOracleConfig(); - } - - return dataSourceReactiveOracleOuterNamedConfig.reactive.oracle; - } + @WithParentName + @WithDefaults + @WithUnnamedKey(DataSourceUtil.DEFAULT_DATASOURCE_NAME) + Map dataSources(); @ConfigGroup - public static class DataSourceReactiveOracleOuterNamedConfig { + public interface DataSourceReactiveOracleOuterNamedConfig { /** * The Oracle-specific configuration. */ - public DataSourceReactiveOracleOuterNestedNamedConfig reactive; + DataSourceReactiveOracleOuterNestedNamedConfig reactive(); } @ConfigGroup - public static class DataSourceReactiveOracleOuterNestedNamedConfig { + public interface DataSourceReactiveOracleOuterNestedNamedConfig { /** * The Oracle-specific configuration. */ - public DataSourceReactiveOracleConfig oracle; + DataSourceReactiveOracleConfig oracle(); } } diff --git a/extensions/reactive-oracle-client/runtime/src/main/java/io/quarkus/reactive/oracle/client/runtime/OraclePoolRecorder.java b/extensions/reactive-oracle-client/runtime/src/main/java/io/quarkus/reactive/oracle/client/runtime/OraclePoolRecorder.java index d254db08af9d18..e2e9a2d101d3d6 100644 --- a/extensions/reactive-oracle-client/runtime/src/main/java/io/quarkus/reactive/oracle/client/runtime/OraclePoolRecorder.java +++ b/extensions/reactive-oracle-client/runtime/src/main/java/io/quarkus/reactive/oracle/client/runtime/OraclePoolRecorder.java @@ -51,9 +51,9 @@ public RuntimeValue configureOraclePool(RuntimeValue vertx, OraclePool oraclePool = initialize((VertxInternal) vertx.getValue(), eventLoopCount.get(), dataSourceName, - dataSourcesRuntimeConfig.getDataSourceRuntimeConfig(dataSourceName), + dataSourcesRuntimeConfig.dataSources().get(dataSourceName), dataSourcesReactiveRuntimeConfig.getDataSourceReactiveRuntimeConfig(dataSourceName), - dataSourcesReactiveOracleConfig.getDataSourceReactiveRuntimeConfig(dataSourceName)); + dataSourcesReactiveOracleConfig.dataSources().get(dataSourceName).reactive().oracle()); shutdown.addShutdownTask(oraclePool::close); return new RuntimeValue<>(oraclePool); diff --git a/extensions/reactive-pg-client/deployment/src/main/java/io/quarkus/reactive/pg/client/deployment/ReactivePgClientProcessor.java b/extensions/reactive-pg-client/deployment/src/main/java/io/quarkus/reactive/pg/client/deployment/ReactivePgClientProcessor.java index be0fb39e3dc652..6470b439610e4c 100644 --- a/extensions/reactive-pg-client/deployment/src/main/java/io/quarkus/reactive/pg/client/deployment/ReactivePgClientProcessor.java +++ b/extensions/reactive-pg-client/deployment/src/main/java/io/quarkus/reactive/pg/client/deployment/ReactivePgClientProcessor.java @@ -92,12 +92,7 @@ ServiceStartBuildItem build(BuildProducer feature, feature.produce(new FeatureBuildItem(Feature.REACTIVE_PG_CLIENT)); - createPoolIfDefined(recorder, vertx, eventLoopCount, shutdown, pgPool, vertxPool, syntheticBeans, - DataSourceUtil.DEFAULT_DATASOURCE_NAME, dataSourcesBuildTimeConfig, - dataSourcesRuntimeConfig, dataSourcesReactiveBuildTimeConfig, dataSourcesReactiveRuntimeConfig, - dataSourcesReactivePostgreSQLConfig, defaultDataSourceDbKindBuildItems, curateOutcomeBuildItem); - - for (String dataSourceName : dataSourcesBuildTimeConfig.namedDataSources().keySet()) { + for (String dataSourceName : dataSourcesBuildTimeConfig.dataSources().keySet()) { createPoolIfDefined(recorder, vertx, eventLoopCount, shutdown, pgPool, vertxPool, syntheticBeans, dataSourceName, dataSourcesBuildTimeConfig, dataSourcesRuntimeConfig, dataSourcesReactiveBuildTimeConfig, dataSourcesReactiveRuntimeConfig, dataSourcesReactivePostgreSQLConfig, defaultDataSourceDbKindBuildItems, @@ -235,14 +230,14 @@ private static boolean isReactivePostgreSQLPoolDefined(DataSourcesBuildTimeConfi List defaultDataSourceDbKindBuildItems, CurateOutcomeBuildItem curateOutcomeBuildItem) { DataSourceBuildTimeConfig dataSourceBuildTimeConfig = dataSourcesBuildTimeConfig - .getDataSourceBuildTimeConfig(dataSourceName); + .dataSources().get(dataSourceName); DataSourceReactiveBuildTimeConfig dataSourceReactiveBuildTimeConfig = dataSourcesReactiveBuildTimeConfig .getDataSourceReactiveBuildTimeConfig(dataSourceName); Optional dbKind = DefaultDataSourceDbKindBuildItem.resolve(dataSourceBuildTimeConfig.dbKind(), defaultDataSourceDbKindBuildItems, !DataSourceUtil.isDefault(dataSourceName) || dataSourceBuildTimeConfig.devservices().enabled() - .orElse(dataSourcesBuildTimeConfig.namedDataSources().isEmpty()), + .orElse(!dataSourcesBuildTimeConfig.hasNamedDataSources()), curateOutcomeBuildItem); if (!dbKind.isPresent()) { @@ -266,7 +261,7 @@ private boolean hasPools(DataSourcesBuildTimeConfig dataSourcesBuildTimeConfig, return true; } - for (String dataSourceName : dataSourcesBuildTimeConfig.namedDataSources().keySet()) { + for (String dataSourceName : dataSourcesBuildTimeConfig.dataSources().keySet()) { if (isReactivePostgreSQLPoolDefined(dataSourcesBuildTimeConfig, dataSourcesReactiveBuildTimeConfig, dataSourceName, defaultDataSourceDbKindBuildItems, curateOutcomeBuildItem)) { return true; diff --git a/extensions/reactive-pg-client/runtime/src/main/java/io/quarkus/reactive/pg/client/runtime/DataSourceReactivePostgreSQLConfig.java b/extensions/reactive-pg-client/runtime/src/main/java/io/quarkus/reactive/pg/client/runtime/DataSourceReactivePostgreSQLConfig.java index 47607c9074dec2..681e4d0e6b3af5 100644 --- a/extensions/reactive-pg-client/runtime/src/main/java/io/quarkus/reactive/pg/client/runtime/DataSourceReactivePostgreSQLConfig.java +++ b/extensions/reactive-pg-client/runtime/src/main/java/io/quarkus/reactive/pg/client/runtime/DataSourceReactivePostgreSQLConfig.java @@ -3,18 +3,17 @@ import java.util.Optional; import java.util.OptionalInt; +import io.quarkus.runtime.annotations.ConfigDocDefault; import io.quarkus.runtime.annotations.ConfigGroup; -import io.quarkus.runtime.annotations.ConfigItem; import io.vertx.pgclient.SslMode; @ConfigGroup -public class DataSourceReactivePostgreSQLConfig { +public interface DataSourceReactivePostgreSQLConfig { /** * The maximum number of inflight database commands that can be pipelined. */ - @ConfigItem - public OptionalInt pipeliningLimit = OptionalInt.empty(); + OptionalInt pipeliningLimit(); /** * SSL operating mode of the client. @@ -22,6 +21,6 @@ public class DataSourceReactivePostgreSQLConfig { * See Protection Provided in * Different Modes. */ - @ConfigItem(defaultValueDocumentation = "disable") - public Optional sslMode = Optional.empty(); + @ConfigDocDefault("disable") + Optional sslMode(); } diff --git a/extensions/reactive-pg-client/runtime/src/main/java/io/quarkus/reactive/pg/client/runtime/DataSourcesReactivePostgreSQLConfig.java b/extensions/reactive-pg-client/runtime/src/main/java/io/quarkus/reactive/pg/client/runtime/DataSourcesReactivePostgreSQLConfig.java index d79f46c6c2fb43..6ab7b9c5c6a7df 100644 --- a/extensions/reactive-pg-client/runtime/src/main/java/io/quarkus/reactive/pg/client/runtime/DataSourcesReactivePostgreSQLConfig.java +++ b/extensions/reactive-pg-client/runtime/src/main/java/io/quarkus/reactive/pg/client/runtime/DataSourcesReactivePostgreSQLConfig.java @@ -6,57 +6,43 @@ import io.quarkus.runtime.annotations.ConfigDocMapKey; import io.quarkus.runtime.annotations.ConfigDocSection; import io.quarkus.runtime.annotations.ConfigGroup; -import io.quarkus.runtime.annotations.ConfigItem; import io.quarkus.runtime.annotations.ConfigPhase; import io.quarkus.runtime.annotations.ConfigRoot; +import io.smallrye.config.ConfigMapping; +import io.smallrye.config.WithDefaults; +import io.smallrye.config.WithParentName; +import io.smallrye.config.WithUnnamedKey; -@ConfigRoot(name = "datasource", phase = ConfigPhase.RUN_TIME) -public class DataSourcesReactivePostgreSQLConfig { +@ConfigMapping(prefix = "quarkus.datasource") +@ConfigRoot(phase = ConfigPhase.RUN_TIME) +public interface DataSourcesReactivePostgreSQLConfig { /** - * The default datasource. - */ - @ConfigItem(name = "reactive.postgresql") - public DataSourceReactivePostgreSQLConfig defaultDataSource; - - /** - * Additional named datasources. + * Datasources. */ @ConfigDocSection @ConfigDocMapKey("datasource-name") - @ConfigItem(name = ConfigItem.PARENT) - public Map namedDataSources; - - public DataSourceReactivePostgreSQLConfig getDataSourceReactiveRuntimeConfig(String dataSourceName) { - if (DataSourceUtil.isDefault(dataSourceName)) { - return defaultDataSource; - } - - DataSourceReactivePostgreSQLOuterNamedConfig dataSourceReactivePostgreSQLOuterNamedConfig = namedDataSources - .get(dataSourceName); - if (dataSourceReactivePostgreSQLOuterNamedConfig == null) { - return new DataSourceReactivePostgreSQLConfig(); - } - - return dataSourceReactivePostgreSQLOuterNamedConfig.reactive.postgresql; - } + @WithParentName + @WithDefaults + @WithUnnamedKey(DataSourceUtil.DEFAULT_DATASOURCE_NAME) + Map dataSources(); @ConfigGroup - public static class DataSourceReactivePostgreSQLOuterNamedConfig { + public interface DataSourceReactivePostgreSQLOuterNamedConfig { /** * The PostgreSQL-specific configuration. */ - public DataSourceReactivePostgreSQLOuterNestedNamedConfig reactive; + DataSourceReactivePostgreSQLOuterNestedNamedConfig reactive(); } @ConfigGroup - public static class DataSourceReactivePostgreSQLOuterNestedNamedConfig { + public interface DataSourceReactivePostgreSQLOuterNestedNamedConfig { /** * The PostgreSQL-specific configuration. */ - public DataSourceReactivePostgreSQLConfig postgresql; + DataSourceReactivePostgreSQLConfig postgresql(); } } diff --git a/extensions/reactive-pg-client/runtime/src/main/java/io/quarkus/reactive/pg/client/runtime/PgPoolRecorder.java b/extensions/reactive-pg-client/runtime/src/main/java/io/quarkus/reactive/pg/client/runtime/PgPoolRecorder.java index 0073001b816e35..27836f376dad18 100644 --- a/extensions/reactive-pg-client/runtime/src/main/java/io/quarkus/reactive/pg/client/runtime/PgPoolRecorder.java +++ b/extensions/reactive-pg-client/runtime/src/main/java/io/quarkus/reactive/pg/client/runtime/PgPoolRecorder.java @@ -54,9 +54,9 @@ public RuntimeValue configurePgPool(RuntimeValue vertx, PgPool pgPool = initialize((VertxInternal) vertx.getValue(), eventLoopCount.get(), dataSourceName, - dataSourcesRuntimeConfig.getDataSourceRuntimeConfig(dataSourceName), + dataSourcesRuntimeConfig.dataSources().get(dataSourceName), dataSourcesReactiveRuntimeConfig.getDataSourceReactiveRuntimeConfig(dataSourceName), - dataSourcesReactivePostgreSQLConfig.getDataSourceReactiveRuntimeConfig(dataSourceName)); + dataSourcesReactivePostgreSQLConfig.dataSources().get(dataSourceName).reactive().postgresql()); shutdown.addShutdownTask(pgPool::close); return new RuntimeValue<>(pgPool); @@ -167,12 +167,12 @@ private List toPgConnectOptions(String dataSourceName, DataSou pgConnectOptions.setCachePreparedStatements(dataSourceReactiveRuntimeConfig.cachePreparedStatements()); - if (dataSourceReactivePostgreSQLConfig.pipeliningLimit.isPresent()) { - pgConnectOptions.setPipeliningLimit(dataSourceReactivePostgreSQLConfig.pipeliningLimit.getAsInt()); + if (dataSourceReactivePostgreSQLConfig.pipeliningLimit().isPresent()) { + pgConnectOptions.setPipeliningLimit(dataSourceReactivePostgreSQLConfig.pipeliningLimit().getAsInt()); } - if (dataSourceReactivePostgreSQLConfig.sslMode.isPresent()) { - final SslMode sslMode = dataSourceReactivePostgreSQLConfig.sslMode.get(); + if (dataSourceReactivePostgreSQLConfig.sslMode().isPresent()) { + final SslMode sslMode = dataSourceReactivePostgreSQLConfig.sslMode().get(); pgConnectOptions.setSslMode(sslMode); // If sslMode is verify-full, we also need a hostname verification algorithm