use of io.micronaut.configuration.hibernate.jpa.JpaConfiguration in project micronaut-sql by micronaut-projects.
the class EntitiesInPackageCondition method matches.
@Override
public boolean matches(ConditionContext context) {
final AnnotationMetadataProvider component = context.getComponent();
if (component instanceof BeanDefinition) {
BeanDefinition<?> definition = (BeanDefinition<?>) component;
final BeanContext beanContext = context.getBeanContext();
if (beanContext instanceof ApplicationContext) {
final Optional<String> name = definition instanceof NameResolver ? ((NameResolver) definition).resolveName() : Optional.empty();
final Qualifier<JpaConfiguration> q = Qualifiers.byName(name.orElse("default"));
final Optional<JpaConfiguration> jpaConfiguration = beanContext.findBean(JpaConfiguration.class, q);
JpaConfiguration.EntityScanConfiguration entityScanConfig = jpaConfiguration.map(JpaConfiguration::getEntityScanConfiguration).orElse(null);
if (entityScanConfig == null) {
return false;
}
boolean isClasspathScanEnabled = entityScanConfig.isClasspath();
String[] packagesToScan = entityScanConfig.getPackages();
boolean hasEntitiesOnClassPath = false;
boolean hasIntrospections = false;
if (isClasspathScanEnabled) {
final Environment environment = ((ApplicationContext) beanContext).getEnvironment();
if (ArrayUtils.isNotEmpty(packagesToScan)) {
hasEntitiesOnClassPath = environment.scan(Entity.class, packagesToScan).findAny().isPresent();
} else {
hasEntitiesOnClassPath = environment.scan(Entity.class).findAny().isPresent();
}
} else {
if (ArrayUtils.isNotEmpty(packagesToScan)) {
hasIntrospections = !BeanIntrospector.SHARED.findIntrospections(Entity.class, packagesToScan).isEmpty();
} else {
hasIntrospections = !BeanIntrospector.SHARED.findIntrospections(Entity.class).isEmpty();
}
}
return hasEntitiesOnClassPath || hasIntrospections;
}
}
return true;
}
use of io.micronaut.configuration.hibernate.jpa.JpaConfiguration in project micronaut-sql by micronaut-projects.
the class HibernateJCacheManagerBinder method onCreated.
@Override
public JpaConfiguration onCreated(BeanCreatedEvent<JpaConfiguration> event) {
JpaConfiguration jpaConfiguration = event.getBean();
Map<String, Object> jpaProperties = jpaConfiguration.getProperties();
jpaProperties.put(ConfigSettings.CACHE_MANAGER, cacheManager);
return jpaConfiguration;
}
use of io.micronaut.configuration.hibernate.jpa.JpaConfiguration 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);
}
use of io.micronaut.configuration.hibernate.jpa.JpaConfiguration in project micronaut-data by micronaut-projects.
the class PhysicalNamingStrategyConfiguration method onCreated.
@Override
public JpaConfiguration onCreated(BeanCreatedEvent<JpaConfiguration> event) {
JpaConfiguration jpaConfiguration = event.getBean();
jpaConfiguration.getProperties().putIfAbsent(AvailableSettings.PHYSICAL_NAMING_STRATEGY, physicalNamingStrategy);
return jpaConfiguration;
}
Aggregations