Search in sources :

Example 1 with JdbcInitialSQLGeneratorBuildItem

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

the class HibernateOrmProcessor method handleGenerateSqlForPu.

private void handleGenerateSqlForPu(BuildProducer<DevConsoleRuntimeTemplateInfoBuildItem> runtimeInfoProducer, BuildProducer<JdbcInitialSQLGeneratorBuildItem> initialSQLGeneratorBuildItemBuildProducer, String puName, String dsName, CurateOutcomeBuildItem curateOutcomeBuildItem) {
    DevConsoleRuntimeTemplateInfoBuildItem devConsoleRuntimeTemplateInfoBuildItem = new DevConsoleRuntimeTemplateInfoBuildItem("create-ddl." + puName, new HibernateOrmDevConsoleCreateDDLSupplier(puName), this.getClass(), curateOutcomeBuildItem);
    runtimeInfoProducer.produce(devConsoleRuntimeTemplateInfoBuildItem);
    initialSQLGeneratorBuildItemBuildProducer.produce(new JdbcInitialSQLGeneratorBuildItem(dsName, new Supplier<String>() {

        @Override
        public String get() {
            return DevConsoleManager.getTemplateInfo().get(devConsoleRuntimeTemplateInfoBuildItem.getGroupId() + "." + devConsoleRuntimeTemplateInfoBuildItem.getArtifactId()).get(devConsoleRuntimeTemplateInfoBuildItem.getName()).toString();
        }
    }));
}
Also used : HibernateOrmDevConsoleCreateDDLSupplier(io.quarkus.hibernate.orm.runtime.devconsole.HibernateOrmDevConsoleCreateDDLSupplier) DevConsoleRuntimeTemplateInfoBuildItem(io.quarkus.devconsole.spi.DevConsoleRuntimeTemplateInfoBuildItem) JdbcInitialSQLGeneratorBuildItem(io.quarkus.agroal.spi.JdbcInitialSQLGeneratorBuildItem) Supplier(java.util.function.Supplier) HibernateOrmDevConsoleCreateDDLSupplier(io.quarkus.hibernate.orm.runtime.devconsole.HibernateOrmDevConsoleCreateDDLSupplier)

Example 2 with JdbcInitialSQLGeneratorBuildItem

use of io.quarkus.agroal.spi.JdbcInitialSQLGeneratorBuildItem 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)

Aggregations

JdbcInitialSQLGeneratorBuildItem (io.quarkus.agroal.spi.JdbcInitialSQLGeneratorBuildItem)2 JdbcDataSourceBuildItem (io.quarkus.agroal.spi.JdbcDataSourceBuildItem)1 JdbcDataSourceSchemaReadyBuildItem (io.quarkus.agroal.spi.JdbcDataSourceSchemaReadyBuildItem)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 BuildStep (io.quarkus.deployment.annotations.BuildStep)1 Consume (io.quarkus.deployment.annotations.Consume)1 ExecutionTime (io.quarkus.deployment.annotations.ExecutionTime)1 STATIC_INIT (io.quarkus.deployment.annotations.ExecutionTime.STATIC_INIT)1 Record (io.quarkus.deployment.annotations.Record)1 CombinedIndexBuildItem (io.quarkus.deployment.builditem.CombinedIndexBuildItem)1 FeatureBuildItem (io.quarkus.deployment.builditem.FeatureBuildItem)1 IndexDependencyBuildItem (io.quarkus.deployment.builditem.IndexDependencyBuildItem)1 ServiceStartBuildItem (io.quarkus.deployment.builditem.ServiceStartBuildItem)1 NativeImageResourceBuildItem (io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem)1