Skip to content

Commit

Permalink
Merge pull request quarkusio#43564 from yrodiere/reactive-with-unnamed
Browse files Browse the repository at this point in the history
Use SmallRye Config @WithDefaults/@WithUnnamedKey for reactive datasource config
  • Loading branch information
yrodiere authored Sep 27, 2024
2 parents ceb7e30 + 4786257 commit 60a9780
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,37 +1,59 @@
package io.quarkus.reactive.datasource.runtime;

import java.util.HashMap;
import java.util.Map;

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.smallrye.config.ConfigMapping;
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 DataSourcesReactiveBuildTimeConfig {

/**
* Datasources.
*/
@ConfigDocMapKey("datasource-name")
@WithParentName
@WithDefaults
@WithUnnamedKey(DataSourceUtil.DEFAULT_DATASOURCE_NAME)
Map<String, DataSourceReactiveOuterNamedBuildTimeConfig> dataSources();

/**
* The default datasource.
*
* @deprecated Use {@code dataSources().get(DataSourceUtil.DEFAULT_DATASOURCE_NAME).reactive()} instead.
*/
@WithName("reactive")
DataSourceReactiveBuildTimeConfig defaultDataSource();
@Deprecated
default DataSourceReactiveBuildTimeConfig defaultDataSource() {
return dataSources().get(DataSourceUtil.DEFAULT_DATASOURCE_NAME).reactive();
}

/**
* Additional named datasources.
*
* @deprecated Use {@code dataSources()} instead -- this will include the default datasource.
*/
@ConfigDocSection
@ConfigDocMapKey("datasource-name")
@WithParentName
@WithDefaults
Map<String, DataSourceReactiveOuterNamedBuildTimeConfig> namedDataSources();
@Deprecated
default Map<String, DataSourceReactiveOuterNamedBuildTimeConfig> namedDataSources() {
Map<String, DataSourceReactiveOuterNamedBuildTimeConfig> withoutDefault = new HashMap<>(dataSources());
withoutDefault.remove(DataSourceUtil.DEFAULT_DATASOURCE_NAME);
return withoutDefault;
}

/**
* Additional named datasources.
*
* @deprecated Use {@code dataSources().get(dataSourceName).reactive()} instead.
*/
@Deprecated
default DataSourceReactiveBuildTimeConfig getDataSourceReactiveBuildTimeConfig(String dataSourceName) {
if (DataSourceUtil.isDefault(dataSourceName)) {
return defaultDataSource();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,59 @@
package io.quarkus.reactive.datasource.runtime;

import java.util.HashMap;
import java.util.Map;

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.smallrye.config.ConfigMapping;
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.RUN_TIME)
public interface DataSourcesReactiveRuntimeConfig {

/**
* Datasources.
*/
@ConfigDocMapKey("datasource-name")
@WithParentName
@WithDefaults
@WithUnnamedKey(DataSourceUtil.DEFAULT_DATASOURCE_NAME)
Map<String, DataSourceReactiveOuterNamedRuntimeConfig> dataSources();

/**
* The default datasource.
*
* @deprecated Use {@code dataSources().get(DataSourceUtil.DEFAULT_DATASOURCE_NAME).reactive()} instead.
*/
@WithName("reactive")
DataSourceReactiveRuntimeConfig defaultDataSource();
@Deprecated
default DataSourceReactiveRuntimeConfig defaultDataSource() {
return dataSources().get(DataSourceUtil.DEFAULT_DATASOURCE_NAME).reactive();
}

/**
* Additional named datasources.
*
* @deprecated Use {@code dataSources()} instead -- this will include the default datasource.
*/
@ConfigDocSection
@ConfigDocMapKey("datasource-name")
@WithParentName
@WithDefaults
Map<String, DataSourceReactiveOuterNamedRuntimeConfig> namedDataSources();
@Deprecated
default Map<String, DataSourceReactiveOuterNamedRuntimeConfig> namedDataSources() {
Map<String, DataSourceReactiveOuterNamedRuntimeConfig> withoutDefault = new HashMap<>(dataSources());
withoutDefault.remove(DataSourceUtil.DEFAULT_DATASOURCE_NAME);
return withoutDefault;
}

/**
* Additional named datasources.
*
* @deprecated Use {@code dataSources().get(dataSourceName).reactive()} instead.
*/
@Deprecated
default DataSourceReactiveRuntimeConfig getDataSourceReactiveRuntimeConfig(String dataSourceName) {
if (DataSourceUtil.isDefault(dataSourceName)) {
return defaultDataSource();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ private static boolean isReactiveDB2PoolDefined(DataSourcesBuildTimeConfig dataS
DataSourceBuildTimeConfig dataSourceBuildTimeConfig = dataSourcesBuildTimeConfig
.dataSources().get(dataSourceName);
DataSourceReactiveBuildTimeConfig dataSourceReactiveBuildTimeConfig = dataSourcesReactiveBuildTimeConfig
.getDataSourceReactiveBuildTimeConfig(dataSourceName);
.dataSources().get(dataSourceName).reactive();

Optional<String> dbKind = DefaultDataSourceDbKindBuildItem.resolve(dataSourceBuildTimeConfig.dbKind(),
defaultDataSourceDbKindBuildItems,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public DB2Pool apply(SyntheticCreationalContext<DB2Pool> context) {
eventLoopCount.get(),
dataSourceName,
dataSourcesRuntimeConfig.dataSources().get(dataSourceName),
dataSourcesReactiveRuntimeConfig.getDataSourceReactiveRuntimeConfig(dataSourceName),
dataSourcesReactiveRuntimeConfig.dataSources().get(dataSourceName).reactive(),
dataSourcesReactiveDB2Config.dataSources().get(dataSourceName).reactive().db2(),
context);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ private static boolean isReactiveMSSQLPoolDefined(DataSourcesBuildTimeConfig dat
DataSourceBuildTimeConfig dataSourceBuildTimeConfig = dataSourcesBuildTimeConfig
.dataSources().get(dataSourceName);
DataSourceReactiveBuildTimeConfig dataSourceReactiveBuildTimeConfig = dataSourcesReactiveBuildTimeConfig
.getDataSourceReactiveBuildTimeConfig(dataSourceName);
.dataSources().get(dataSourceName).reactive();

Optional<String> dbKind = DefaultDataSourceDbKindBuildItem.resolve(dataSourceBuildTimeConfig.dbKind(),
defaultDataSourceDbKindBuildItems,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public MSSQLPool apply(SyntheticCreationalContext<MSSQLPool> context) {
eventLoopCount.get(),
dataSourceName,
dataSourcesRuntimeConfig.dataSources().get(dataSourceName),
dataSourcesReactiveRuntimeConfig.getDataSourceReactiveRuntimeConfig(dataSourceName),
dataSourcesReactiveRuntimeConfig.dataSources().get(dataSourceName).reactive(),
dataSourcesReactiveMSSQLConfig.dataSources().get(dataSourceName).reactive().mssql(),
context);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ private static boolean isReactiveMySQLPoolDefined(DataSourcesBuildTimeConfig dat
DataSourceBuildTimeConfig dataSourceBuildTimeConfig = dataSourcesBuildTimeConfig
.dataSources().get(dataSourceName);
DataSourceReactiveBuildTimeConfig dataSourceReactiveBuildTimeConfig = dataSourcesReactiveBuildTimeConfig
.getDataSourceReactiveBuildTimeConfig(dataSourceName);
.dataSources().get(dataSourceName).reactive();

Optional<String> dbKind = DefaultDataSourceDbKindBuildItem.resolve(dataSourceBuildTimeConfig.dbKind(),
defaultDataSourceDbKindBuildItems,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public MySQLPool apply(SyntheticCreationalContext<MySQLPool> context) {
eventLoopCount.get(),
dataSourceName,
dataSourcesRuntimeConfig.dataSources().get(dataSourceName),
dataSourcesReactiveRuntimeConfig.getDataSourceReactiveRuntimeConfig(dataSourceName),
dataSourcesReactiveRuntimeConfig.dataSources().get(dataSourceName).reactive(),
dataSourcesReactiveMySQLConfig.dataSources().get(dataSourceName).reactive().mysql(),
context);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ private static boolean isReactiveOraclePoolDefined(DataSourcesBuildTimeConfig da
DataSourceBuildTimeConfig dataSourceBuildTimeConfig = dataSourcesBuildTimeConfig
.dataSources().get(dataSourceName);
DataSourceReactiveBuildTimeConfig dataSourceReactiveBuildTimeConfig = dataSourcesReactiveBuildTimeConfig
.getDataSourceReactiveBuildTimeConfig(dataSourceName);
.dataSources().get(dataSourceName).reactive();

Optional<String> dbKind = DefaultDataSourceDbKindBuildItem.resolve(dataSourceBuildTimeConfig.dbKind(),
defaultDataSourceDbKindBuildItems,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public OraclePool apply(SyntheticCreationalContext<OraclePool> context) {
eventLoopCount.get(),
dataSourceName,
dataSourcesRuntimeConfig.dataSources().get(dataSourceName),
dataSourcesReactiveRuntimeConfig.getDataSourceReactiveRuntimeConfig(dataSourceName),
dataSourcesReactiveRuntimeConfig.dataSources().get(dataSourceName).reactive(),
dataSourcesReactiveOracleConfig.dataSources().get(dataSourceName).reactive().oracle(),
context);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ private static boolean isReactivePostgreSQLPoolDefined(DataSourcesBuildTimeConfi
DataSourceBuildTimeConfig dataSourceBuildTimeConfig = dataSourcesBuildTimeConfig
.dataSources().get(dataSourceName);
DataSourceReactiveBuildTimeConfig dataSourceReactiveBuildTimeConfig = dataSourcesReactiveBuildTimeConfig
.getDataSourceReactiveBuildTimeConfig(dataSourceName);
.dataSources().get(dataSourceName).reactive();

Optional<String> dbKind = DefaultDataSourceDbKindBuildItem.resolve(dataSourceBuildTimeConfig.dbKind(),
defaultDataSourceDbKindBuildItems,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public PgPool apply(SyntheticCreationalContext<PgPool> context) {
eventLoopCount.get(),
dataSourceName,
dataSourcesRuntimeConfig.dataSources().get(dataSourceName),
dataSourcesReactiveRuntimeConfig.getDataSourceReactiveRuntimeConfig(dataSourceName),
dataSourcesReactiveRuntimeConfig.dataSources().get(dataSourceName).reactive(),
dataSourcesReactivePostgreSQLConfig.dataSources().get(dataSourceName).reactive().postgresql(),
context);

Expand Down

0 comments on commit 60a9780

Please sign in to comment.