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);
}
Aggregations