Skip to content

Commit

Permalink
Liquibase - make use of synthetic injection point
Browse files Browse the repository at this point in the history
  • Loading branch information
mkouba committed Feb 15, 2023
1 parent cc8074d commit b8dcf27
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -23,29 +22,27 @@
@Recorder
public class LiquibaseRecorder {

private static final Logger log = Logger.getLogger(LiquibaseRecorder.class);

private final RuntimeValue<LiquibaseRuntimeConfig> config;

public LiquibaseRecorder(RuntimeValue<LiquibaseRuntimeConfig> config) {
this.config = config;
}

public Supplier<LiquibaseFactory> liquibaseSupplier(String dataSourceName) {
public Function<SyntheticCreationalContext<LiquibaseFactory>, LiquibaseFactory> liquibaseFunction(String dataSourceName) {
DataSource dataSource = DataSources.fromName(dataSourceName);
if (dataSource instanceof UnconfiguredDataSource) {
return new Supplier<LiquibaseFactory>() {
return new Function<SyntheticCreationalContext<LiquibaseFactory>, LiquibaseFactory>() {
@Override
public LiquibaseFactory get() {
public LiquibaseFactory apply(SyntheticCreationalContext<LiquibaseFactory> 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<LiquibaseFactory>() {
return new Function<SyntheticCreationalContext<LiquibaseFactory>, LiquibaseFactory>() {
@Override
public LiquibaseFactory get() {
public LiquibaseFactory apply(SyntheticCreationalContext<LiquibaseFactory> context) {
LiquibaseFactoryProducer liquibaseProducer = context.getInjectedReference(LiquibaseFactoryProducer.class);
LiquibaseFactory liquibaseFactory = liquibaseProducer.createLiquibaseFactory(dataSource, dataSourceName);
return liquibaseFactory;
}
};
Expand Down

0 comments on commit b8dcf27

Please sign in to comment.