Java Code Examples for io.micronaut.jdbc.DataSourceResolver

The following examples show how to use io.micronaut.jdbc.DataSourceResolver. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * @param applicationContext The application context
 * @param eventPublisher     The event publisher
 * @param dataSourceResolver The data source resolver
 */
public DataSourceMigrationRunner(ApplicationContext applicationContext,
                                 ApplicationEventPublisher eventPublisher,
                                 @Nullable DataSourceResolver dataSourceResolver) {
    super(applicationContext, eventPublisher);
    this.dataSourceResolver = dataSourceResolver != null ? dataSourceResolver : DataSourceResolver.DEFAULT;
}
 
Example 2
Source Project: micronaut-sql   Source File: JooqConfigurationFactory.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Creates jOOQ {@link Configuration}.
 * It will configure it with available jOOQ provider beans with the same qualifier.
 *
 * @param name                   The data source name
 * @param dataSource             The {@link DataSource}
 * @param transactionProvider    The transaction provider
 * @param settings               The settings
 * @param executorProvider       The executor provider
 * @param recordMapperProvider   The record mapper provider
 * @param recordUnmapperProvider The record unmapper provider
 * @param metaProvider           The metadata provider
 * @param ctx                    The {@link ApplicationContext}
 * @return A {@link Configuration}
 */
@EachBean(DataSource.class)
public Configuration jooqConfiguration(
        @Parameter String name,
        DataSource dataSource,
        @Parameter @Nullable TransactionProvider transactionProvider,
        @Parameter @Nullable Settings settings,
        @Parameter @Nullable ExecutorProvider executorProvider,
        @Parameter @Nullable RecordMapperProvider recordMapperProvider,
        @Parameter @Nullable RecordUnmapperProvider recordUnmapperProvider,
        @Parameter @Nullable MetaProvider metaProvider,
        ApplicationContext ctx
) {
    DefaultConfiguration configuration = new DefaultConfiguration();

    JooqConfigurationProperties properties = ctx.findBean(JooqConfigurationProperties.class, Qualifiers.byName(name))
            .orElseGet(JooqConfigurationProperties::new);
    DataSourceResolver dataSourceResolver = ctx.findBean(DataSourceResolver.class).orElse(DataSourceResolver.DEFAULT);
    configuration.setSQLDialect(properties.determineSqlDialect(dataSourceResolver.resolve(dataSource)));

    configuration.setDataSource(dataSource);
    if (transactionProvider != null) {
        configuration.setTransactionProvider(transactionProvider);
    }
    if (settings != null) {
        configuration.setSettings(settings);
    }
    if (executorProvider != null) {
        configuration.setExecutorProvider(executorProvider);
    }
    if (recordMapperProvider != null) {
        configuration.setRecordMapperProvider(recordMapperProvider);
    }
    if (recordUnmapperProvider != null) {
        configuration.setRecordUnmapperProvider(recordUnmapperProvider);
    }
    if (metaProvider != null) {
        configuration.setMetaProvider(metaProvider);
    }
    configuration.setExecuteListenerProvider(ctx.getBeansOfType(ExecuteListenerProvider.class, Qualifiers.byName(name))
            .toArray(new ExecuteListenerProvider[0]));
    configuration.setRecordListenerProvider(ctx.getBeansOfType(RecordListenerProvider.class, Qualifiers.byName(name))
            .toArray(new RecordListenerProvider[0]));
    configuration.setVisitListenerProvider(ctx.getBeansOfType(VisitListenerProvider.class, Qualifiers.byName(name))
            .toArray(new VisitListenerProvider[0]));
    configuration.setTransactionListenerProvider(ctx.getBeansOfType(TransactionListenerProvider.class, Qualifiers.byName(name))
            .toArray(new TransactionListenerProvider[0]));
    configuration.setDiagnosticsListenerProvider(ctx.getBeansOfType(DiagnosticsListenerProvider.class, Qualifiers.byName(name))
            .toArray(new DiagnosticsListenerProvider[0]));

    return configuration;
}
 
Example 3
Source Project: micronaut-sql   Source File: DatasourceFactory.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Default constructor.
 * @param dataSourceResolver The data source resolver
 */
public DatasourceFactory(@Nullable DataSourceResolver dataSourceResolver) {
    this.dataSourceResolver = dataSourceResolver == null ? DataSourceResolver.DEFAULT : dataSourceResolver;
}
 
Example 4
Source Project: micronaut-sql   Source File: DatasourceFactory.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Default constructor.
 * @param dataSourceResolver The data source resolver
 */
public DatasourceFactory(@Nullable DataSourceResolver dataSourceResolver) {
    this.dataSourceResolver = dataSourceResolver == null ? DataSourceResolver.DEFAULT : dataSourceResolver;
}