Search in sources :

Example 1 with JdbcDataSourceSchemaReadyBuildItem

use of io.quarkus.agroal.spi.JdbcDataSourceSchemaReadyBuildItem in project quarkus by quarkusio.

the class FlywayProcessor method createBeansAndStartActions.

@BuildStep
@Consume(LoggingSetupBuildItem.class)
@Record(ExecutionTime.RUNTIME_INIT)
ServiceStartBuildItem createBeansAndStartActions(FlywayRecorder recorder, List<JdbcDataSourceBuildItem> jdbcDataSourceBuildItems, List<JdbcInitialSQLGeneratorBuildItem> sqlGeneratorBuildItems, BuildProducer<AdditionalBeanBuildItem> additionalBeans, BuildProducer<SyntheticBeanBuildItem> syntheticBeanBuildItemBuildProducer, BuildProducer<JdbcDataSourceSchemaReadyBuildItem> schemaReadyBuildItem, MigrationStateBuildItem migrationsBuildItem) {
    // make a FlywayContainerProducer bean
    additionalBeans.produce(AdditionalBeanBuildItem.builder().addBeanClasses(FlywayContainerProducer.class).setUnremovable().setDefaultScope(DotNames.SINGLETON).build());
    // add the @FlywayDataSource class otherwise it won't registered as a qualifier
    additionalBeans.produce(AdditionalBeanBuildItem.builder().addBeanClass(FlywayDataSource.class).build());
    recorder.resetFlywayContainers();
    Collection<String> dataSourceNames = getDataSourceNames(jdbcDataSourceBuildItems);
    for (String dataSourceName : dataSourceNames) {
        boolean hasMigrations = migrationsBuildItem.hasMigrations.contains(dataSourceName);
        boolean createPossible = false;
        if (!hasMigrations) {
            createPossible = sqlGeneratorBuildItems.stream().anyMatch(s -> s.getDatabaseName().equals(dataSourceName));
        }
        SyntheticBeanBuildItem.ExtendedBeanConfigurator configurator = SyntheticBeanBuildItem.configure(Flyway.class).scope(// this is what the existing code does, but it doesn't seem reasonable
        Dependent.class).setRuntimeInit().unremovable().supplier(recorder.flywaySupplier(dataSourceName, hasMigrations, createPossible));
        if (DataSourceUtil.isDefault(dataSourceName)) {
            configurator.addQualifier(Default.class);
        } else {
            String beanName = FLYWAY_BEAN_NAME_PREFIX + dataSourceName;
            configurator.name(beanName);
            configurator.addQualifier().annotation(DotNames.NAMED).addValue("value", beanName).done();
            configurator.addQualifier().annotation(FlywayDataSource.class).addValue("value", dataSourceName).done();
        }
        syntheticBeanBuildItemBuildProducer.produce(configurator.done());
    }
    // will actually run the actions at runtime
    recorder.doStartActions();
    // once we are done running the migrations, we produce a build item indicating that the
    // schema is "ready"
    schemaReadyBuildItem.produce(new JdbcDataSourceSchemaReadyBuildItem(migrationsBuildItem.hasMigrations));
    return new ServiceStartBuildItem("flyway");
}
Also used : DotNames(io.quarkus.arc.processor.DotNames) JavaMigration(org.flywaydb.core.api.migration.JavaMigration) ClassPathUtils(io.quarkus.runtime.util.ClassPathUtils) ClassInfo(org.jboss.jandex.ClassInfo) RecorderContext(io.quarkus.deployment.recording.RecorderContext) CombinedIndexBuildItem(io.quarkus.deployment.builditem.CombinedIndexBuildItem) BuildProducer(io.quarkus.deployment.annotations.BuildProducer) AbstractCollection(java.util.AbstractCollection) AdditionalBeanBuildItem(io.quarkus.arc.deployment.AdditionalBeanBuildItem) FeatureBuildItem(io.quarkus.deployment.builditem.FeatureBuildItem) Map(java.util.Map) LoggingSetupBuildItem(io.quarkus.deployment.logging.LoggingSetupBuildItem) Path(java.nio.file.Path) JdbcInitialSQLGeneratorBuildItem(io.quarkus.agroal.spi.JdbcInitialSQLGeneratorBuildItem) Consume(io.quarkus.deployment.annotations.Consume) STATIC_INIT(io.quarkus.deployment.annotations.ExecutionTime.STATIC_INIT) Collection(java.util.Collection) ExecutionTime(io.quarkus.deployment.annotations.ExecutionTime) Set(java.util.Set) NativeImageResourceBuildItem(io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem) Collectors(java.util.stream.Collectors) Location(org.flywaydb.core.api.Location) FlywayBuildTimeConfig(io.quarkus.flyway.runtime.FlywayBuildTimeConfig) Feature(io.quarkus.deployment.Feature) List(java.util.List) Stream(java.util.stream.Stream) Modifier(java.lang.reflect.Modifier) Callback(org.flywaydb.core.api.callback.Callback) SyntheticBeanBuildItem(io.quarkus.arc.deployment.SyntheticBeanBuildItem) ReflectiveClassBuildItem(io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem) Record(io.quarkus.deployment.annotations.Record) Logger(org.jboss.logging.Logger) DotName(org.jboss.jandex.DotName) FlywayContainerProducer(io.quarkus.flyway.runtime.FlywayContainerProducer) RuntimeReinitializedClassBuildItem(io.quarkus.deployment.builditem.nativeimage.RuntimeReinitializedClassBuildItem) HashMap(java.util.HashMap) SimpleBuildItem(io.quarkus.builder.item.SimpleBuildItem) HashSet(java.util.HashSet) IndexDependencyBuildItem(io.quarkus.deployment.builditem.IndexDependencyBuildItem) BuildStep(io.quarkus.deployment.annotations.BuildStep) ServiceStartBuildItem(io.quarkus.deployment.builditem.ServiceStartBuildItem) DataSourceUtil(io.quarkus.datasource.common.runtime.DataSourceUtil) LinkedHashSet(java.util.LinkedHashSet) Default(javax.enterprise.inject.Default) Files(java.nio.file.Files) IOException(java.io.IOException) JdbcDataSourceSchemaReadyBuildItem(io.quarkus.agroal.spi.JdbcDataSourceSchemaReadyBuildItem) JdbcDataSourceBuildItem(io.quarkus.agroal.spi.JdbcDataSourceBuildItem) Paths(java.nio.file.Paths) Dependent(javax.enterprise.context.Dependent) FlywayRecorder(io.quarkus.flyway.runtime.FlywayRecorder) Flyway(org.flywaydb.core.Flyway) JdbcDataSourceSchemaReadyBuildItem(io.quarkus.agroal.spi.JdbcDataSourceSchemaReadyBuildItem) ServiceStartBuildItem(io.quarkus.deployment.builditem.ServiceStartBuildItem) SyntheticBeanBuildItem(io.quarkus.arc.deployment.SyntheticBeanBuildItem) Dependent(javax.enterprise.context.Dependent) Consume(io.quarkus.deployment.annotations.Consume) BuildStep(io.quarkus.deployment.annotations.BuildStep) Record(io.quarkus.deployment.annotations.Record)

Example 2 with JdbcDataSourceSchemaReadyBuildItem

use of io.quarkus.agroal.spi.JdbcDataSourceSchemaReadyBuildItem in project quarkus by quarkusio.

the class LiquibaseProcessor method startLiquibase.

@BuildStep
@Record(ExecutionTime.RUNTIME_INIT)
@Consume(SyntheticBeansRuntimeInitBuildItem.class)
ServiceStartBuildItem startLiquibase(LiquibaseRecorder recorder, List<JdbcDataSourceBuildItem> jdbcDataSourceBuildItems, BuildProducer<JdbcDataSourceSchemaReadyBuildItem> schemaReadyBuildItem) {
    // will actually run the actions at runtime
    recorder.doStartActions();
    // once we are done running the migrations, we produce a build item indicating that the
    // schema is "ready"
    schemaReadyBuildItem.produce(new JdbcDataSourceSchemaReadyBuildItem(getDataSourceNames(jdbcDataSourceBuildItems)));
    return new ServiceStartBuildItem("liquibase");
}
Also used : JdbcDataSourceSchemaReadyBuildItem(io.quarkus.agroal.spi.JdbcDataSourceSchemaReadyBuildItem) ServiceStartBuildItem(io.quarkus.deployment.builditem.ServiceStartBuildItem) Consume(io.quarkus.deployment.annotations.Consume) BuildStep(io.quarkus.deployment.annotations.BuildStep) Record(io.quarkus.deployment.annotations.Record)

Aggregations

JdbcDataSourceSchemaReadyBuildItem (io.quarkus.agroal.spi.JdbcDataSourceSchemaReadyBuildItem)2 BuildStep (io.quarkus.deployment.annotations.BuildStep)2 Consume (io.quarkus.deployment.annotations.Consume)2 Record (io.quarkus.deployment.annotations.Record)2 ServiceStartBuildItem (io.quarkus.deployment.builditem.ServiceStartBuildItem)2 JdbcDataSourceBuildItem (io.quarkus.agroal.spi.JdbcDataSourceBuildItem)1 JdbcInitialSQLGeneratorBuildItem (io.quarkus.agroal.spi.JdbcInitialSQLGeneratorBuildItem)1 AdditionalBeanBuildItem (io.quarkus.arc.deployment.AdditionalBeanBuildItem)1 SyntheticBeanBuildItem (io.quarkus.arc.deployment.SyntheticBeanBuildItem)1 DotNames (io.quarkus.arc.processor.DotNames)1 SimpleBuildItem (io.quarkus.builder.item.SimpleBuildItem)1 DataSourceUtil (io.quarkus.datasource.common.runtime.DataSourceUtil)1 Feature (io.quarkus.deployment.Feature)1 BuildProducer (io.quarkus.deployment.annotations.BuildProducer)1 ExecutionTime (io.quarkus.deployment.annotations.ExecutionTime)1 STATIC_INIT (io.quarkus.deployment.annotations.ExecutionTime.STATIC_INIT)1 CombinedIndexBuildItem (io.quarkus.deployment.builditem.CombinedIndexBuildItem)1 FeatureBuildItem (io.quarkus.deployment.builditem.FeatureBuildItem)1 IndexDependencyBuildItem (io.quarkus.deployment.builditem.IndexDependencyBuildItem)1 NativeImageResourceBuildItem (io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem)1