Skip to content

Commit

Permalink
Fix liquibase datasource bean creation issue
Browse files Browse the repository at this point in the history
  • Loading branch information
geoand committed Aug 10, 2023
1 parent e6cad15 commit 2117996
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.jboss.jandex.DotName;
import org.jboss.logging.Logger;

import io.quarkus.agroal.runtime.DataSources;
import io.quarkus.agroal.spi.JdbcDataSourceBuildItem;
import io.quarkus.agroal.spi.JdbcDataSourceSchemaReadyBuildItem;
import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
Expand Down Expand Up @@ -285,6 +286,7 @@ void createBeans(LiquibaseRecorder recorder,
.setRuntimeInit()
.unremovable()
.addInjectionPoint(ClassType.create(DotName.createSimple(LiquibaseFactoryProducer.class)))
.addInjectionPoint(ClassType.create(DotName.createSimple(DataSources.class)))
.createWith(recorder.liquibaseFunction(dataSourceName));

if (DataSourceUtil.isDefault(dataSourceName)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,16 @@ public LiquibaseRecorder(RuntimeValue<LiquibaseRuntimeConfig> config) {
}

public Function<SyntheticCreationalContext<LiquibaseFactory>, LiquibaseFactory> liquibaseFunction(String dataSourceName) {
DataSource dataSource = DataSources.fromName(dataSourceName);
if (dataSource instanceof UnconfiguredDataSource) {
return new Function<SyntheticCreationalContext<LiquibaseFactory>, LiquibaseFactory>() {
@Override
public LiquibaseFactory apply(SyntheticCreationalContext<LiquibaseFactory> context) {
throw new UnsatisfiedResolutionException("No datasource has been configured");
}
};
}
return new Function<SyntheticCreationalContext<LiquibaseFactory>, LiquibaseFactory>() {
@Override
public LiquibaseFactory apply(SyntheticCreationalContext<LiquibaseFactory> context) {
DataSource dataSource = context.getInjectedReference(DataSources.class).getDataSource(dataSourceName);
if (dataSource instanceof UnconfiguredDataSource) {
throw new UnsatisfiedResolutionException("No datasource has been configured");
}

LiquibaseFactoryProducer liquibaseProducer = context.getInjectedReference(LiquibaseFactoryProducer.class);
LiquibaseFactory liquibaseFactory = liquibaseProducer.createLiquibaseFactory(dataSource, dataSourceName);
return liquibaseFactory;
return liquibaseProducer.createLiquibaseFactory(dataSource, dataSourceName);
}
};
}
Expand Down

0 comments on commit 2117996

Please sign in to comment.