From b8dcf27b988067532ebc7967e19ef42753f017e2 Mon Sep 17 00:00:00 2001 From: Martin Kouba Date: Wed, 15 Feb 2023 10:26:54 +0100 Subject: [PATCH] Liquibase - make use of synthetic injection point --- .../deployment/LiquibaseProcessor.java | 4 +++- .../liquibase/runtime/LiquibaseRecorder.java | 21 ++++++++----------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/extensions/liquibase/deployment/src/main/java/io/quarkus/liquibase/deployment/LiquibaseProcessor.java b/extensions/liquibase/deployment/src/main/java/io/quarkus/liquibase/deployment/LiquibaseProcessor.java index 7b0b6f71fad39..a26416f13fac5 100644 --- a/extensions/liquibase/deployment/src/main/java/io/quarkus/liquibase/deployment/LiquibaseProcessor.java +++ b/extensions/liquibase/deployment/src/main/java/io/quarkus/liquibase/deployment/LiquibaseProcessor.java @@ -23,6 +23,7 @@ import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.AnnotationTarget; +import org.jboss.jandex.ClassType; import org.jboss.jandex.DotName; import org.jboss.logging.Logger; @@ -264,7 +265,8 @@ void createBeans(LiquibaseRecorder recorder, .scope(ApplicationScoped.class) // this is what the existing code does, but it doesn't seem reasonable .setRuntimeInit() .unremovable() - .supplier(recorder.liquibaseSupplier(dataSourceName)); + .addInjectionPoint(ClassType.create(DotName.createSimple(LiquibaseFactoryProducer.class))) + .createWith(recorder.liquibaseFunction(dataSourceName)); if (DataSourceUtil.isDefault(dataSourceName)) { configurator.addQualifier(Default.class); diff --git a/extensions/liquibase/runtime/src/main/java/io/quarkus/liquibase/runtime/LiquibaseRecorder.java b/extensions/liquibase/runtime/src/main/java/io/quarkus/liquibase/runtime/LiquibaseRecorder.java index f2250add827c3..2b9429b73d5bf 100644 --- a/extensions/liquibase/runtime/src/main/java/io/quarkus/liquibase/runtime/LiquibaseRecorder.java +++ b/extensions/liquibase/runtime/src/main/java/io/quarkus/liquibase/runtime/LiquibaseRecorder.java @@ -1,19 +1,18 @@ package io.quarkus.liquibase.runtime; -import java.util.function.Supplier; +import java.util.function.Function; import javax.sql.DataSource; import jakarta.enterprise.inject.Any; import jakarta.enterprise.inject.UnsatisfiedResolutionException; -import org.jboss.logging.Logger; - import io.quarkus.agroal.runtime.DataSources; import io.quarkus.agroal.runtime.UnconfiguredDataSource; import io.quarkus.arc.Arc; import io.quarkus.arc.InjectableInstance; import io.quarkus.arc.InstanceHandle; +import io.quarkus.arc.SyntheticCreationalContext; import io.quarkus.liquibase.LiquibaseFactory; import io.quarkus.runtime.RuntimeValue; import io.quarkus.runtime.annotations.Recorder; @@ -23,29 +22,27 @@ @Recorder public class LiquibaseRecorder { - private static final Logger log = Logger.getLogger(LiquibaseRecorder.class); - private final RuntimeValue config; public LiquibaseRecorder(RuntimeValue config) { this.config = config; } - public Supplier liquibaseSupplier(String dataSourceName) { + public Function, LiquibaseFactory> liquibaseFunction(String dataSourceName) { DataSource dataSource = DataSources.fromName(dataSourceName); if (dataSource instanceof UnconfiguredDataSource) { - return new Supplier() { + return new Function, LiquibaseFactory>() { @Override - public LiquibaseFactory get() { + public LiquibaseFactory apply(SyntheticCreationalContext context) { throw new UnsatisfiedResolutionException("No datasource has been configured"); } }; } - LiquibaseFactoryProducer liquibaseProducer = Arc.container().instance(LiquibaseFactoryProducer.class).get(); - LiquibaseFactory liquibaseFactory = liquibaseProducer.createLiquibaseFactory(dataSource, dataSourceName); - return new Supplier() { + return new Function, LiquibaseFactory>() { @Override - public LiquibaseFactory get() { + public LiquibaseFactory apply(SyntheticCreationalContext context) { + LiquibaseFactoryProducer liquibaseProducer = context.getInjectedReference(LiquibaseFactoryProducer.class); + LiquibaseFactory liquibaseFactory = liquibaseProducer.createLiquibaseFactory(dataSource, dataSourceName); return liquibaseFactory; } };