Skip to content

Commit

Permalink
Ensure that DataSource beans dependencies are initialized before the …
Browse files Browse the repository at this point in the history
…datasources
  • Loading branch information
geoand committed Jul 18, 2023
1 parent b29c43f commit 3f9de0c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import jakarta.enterprise.inject.Default;
import jakarta.inject.Singleton;

import org.jboss.jandex.ClassType;
import org.jboss.jandex.DotName;
import org.jboss.logging.Logger;

Expand Down Expand Up @@ -278,9 +279,10 @@ void generateDataSourceBeans(AgroalRecorder recorder,
.scope(Singleton.class)
.setRuntimeInit()
.unremovable()
.addInjectionPoint(ClassType.create(DotName.createSimple(DataSources.class)))
// pass the runtime config into the recorder to ensure that the DataSource related beans
// are created after runtime configuration has been set up
.supplier(recorder.agroalDataSourceSupplier(dataSourceName, dataSourcesRuntimeConfig));
.createWith(recorder.agroalDataSourceSupplier(dataSourceName, dataSourcesRuntimeConfig));

if (entry.getValue().isDefault) {
configurator.addQualifier(Default.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package io.quarkus.agroal.runtime;

import java.util.function.Function;
import java.util.function.Supplier;

import io.agroal.api.AgroalDataSource;
import io.quarkus.arc.SyntheticCreationalContext;
import io.quarkus.datasource.runtime.DataSourcesRuntimeConfig;
import io.quarkus.runtime.annotations.Recorder;

Expand All @@ -18,13 +20,14 @@ public DataSourceSupport get() {
};
}

public Supplier<AgroalDataSource> agroalDataSourceSupplier(String dataSourceName,
public Function<SyntheticCreationalContext<AgroalDataSource>, AgroalDataSource> agroalDataSourceSupplier(
String dataSourceName,
@SuppressWarnings("unused") DataSourcesRuntimeConfig dataSourcesRuntimeConfig) {
final AgroalDataSource agroalDataSource = DataSources.fromName(dataSourceName);
return new Supplier<AgroalDataSource>() {
return new Function<>() {
@Override
public AgroalDataSource get() {
return agroalDataSource;
public AgroalDataSource apply(SyntheticCreationalContext<AgroalDataSource> context) {
DataSources dataSources = context.getInjectedReference(DataSources.class);
return dataSources.getDataSource(dataSourceName);
}
};
}
Expand Down

0 comments on commit 3f9de0c

Please sign in to comment.