Search in sources :

Example 1 with DelegatingDataSource

use of io.micronaut.transaction.jdbc.DelegatingDataSource in project mintaka by FIWARE.

the class MultiTenantEntityManagerFactoryBean method hibernateStandardServiceRegistry.

@EachBean(DataSource.class)
@Replaces(factory = EntityManagerFactoryBean.class, bean = StandardServiceRegistry.class)
protected StandardServiceRegistry hibernateStandardServiceRegistry(@Parameter String dataSourceName, DataSource dataSource) {
    if (dataSource instanceof DelegatingDataSource) {
        dataSource = ((DelegatingDataSource) dataSource).getTargetDataSource();
    }
    connectionProvider.registerDefaultDatasource(dataSource);
    Map<String, Object> additionalSettings = new LinkedHashMap<>();
    additionalSettings.put("hibernate.connection.datasource", dataSource);
    additionalSettings.put("hibernate.current_session_context_class", MicronautSessionContext.class.getName());
    additionalSettings.put("hibernate.session_factory_name", dataSourceName);
    additionalSettings.put("hibernate.session_factory_name_is_jndi", false);
    additionalSettings.putIfAbsent(AvailableSettings.MULTI_TENANT, MultiTenancyStrategy.DATABASE);
    additionalSettings.putIfAbsent(AvailableSettings.MULTI_TENANT_CONNECTION_PROVIDER, connectionProvider);
    additionalSettings.putIfAbsent(AvailableSettings.MULTI_TENANT_IDENTIFIER_RESOLVER, multiTenantResolver);
    JpaConfiguration currentJpaConfiguration = this.beanLocator.findBean(JpaConfiguration.class, Qualifiers.byName(dataSourceName)).orElse(this.jpaConfiguration);
    return currentJpaConfiguration.buildStandardServiceRegistry(additionalSettings);
}
Also used : DelegatingDataSource(io.micronaut.transaction.jdbc.DelegatingDataSource) LinkedHashMap(java.util.LinkedHashMap) MicronautSessionContext(io.micronaut.transaction.hibernate5.MicronautSessionContext) JpaConfiguration(io.micronaut.configuration.hibernate.jpa.JpaConfiguration) EachBean(io.micronaut.context.annotation.EachBean) Replaces(io.micronaut.context.annotation.Replaces)

Aggregations

JpaConfiguration (io.micronaut.configuration.hibernate.jpa.JpaConfiguration)1 EachBean (io.micronaut.context.annotation.EachBean)1 Replaces (io.micronaut.context.annotation.Replaces)1 MicronautSessionContext (io.micronaut.transaction.hibernate5.MicronautSessionContext)1 DelegatingDataSource (io.micronaut.transaction.jdbc.DelegatingDataSource)1 LinkedHashMap (java.util.LinkedHashMap)1