Search in sources :

Example 1 with SchemaManagementStrategyName

use of org.hibernate.search.mapper.orm.schema.management.SchemaManagementStrategyName in project hibernate-search by hibernate.

the class AbstractSchemaManagementStrategyIT method setup.

protected final SessionFactory setup() {
    backendMock.expectAnySchema(IndexedEntity1.NAME);
    backendMock.expectAnySchema(IndexedEntity2.NAME);
    SchemaManagementStrategyName strategyName = getStrategyName();
    return setupHelper.start().withProperty(HibernateOrmMapperSettings.SCHEMA_MANAGEMENT_STRATEGY, strategyName == null ? null : strategyName.externalRepresentation()).setup(IndexedEntity1.class, IndexedEntity2.class);
}
Also used : SchemaManagementStrategyName(org.hibernate.search.mapper.orm.schema.management.SchemaManagementStrategyName)

Example 2 with SchemaManagementStrategyName

use of org.hibernate.search.mapper.orm.schema.management.SchemaManagementStrategyName in project hibernate-search by hibernate.

the class HibernateOrmMapping method create.

public static MappingImplementor<HibernateOrmMapping> create(PojoMappingDelegate mappingDelegate, HibernateOrmTypeContextContainer typeContextContainer, BeanHolder<? extends CoordinationStrategy> coordinationStrategyHolder, ConfiguredAutomaticIndexingStrategy configuredAutomaticIndexingStrategy, SessionFactoryImplementor sessionFactory, ConfigurationPropertySource propertySource) {
    EntityLoadingCacheLookupStrategy cacheLookupStrategy = QUERY_LOADING_CACHE_LOOKUP_STRATEGY.get(propertySource);
    int fetchSize = QUERY_LOADING_FETCH_SIZE.get(propertySource);
    SchemaManagementStrategyName schemaManagementStrategyName = SCHEMA_MANAGEMENT_STRATEGY.get(propertySource);
    SchemaManagementListener schemaManagementListener = new SchemaManagementListener(schemaManagementStrategyName);
    return new HibernateOrmMapping(mappingDelegate, typeContextContainer, sessionFactory, coordinationStrategyHolder, configuredAutomaticIndexingStrategy, cacheLookupStrategy, fetchSize, schemaManagementListener);
}
Also used : EntityLoadingCacheLookupStrategy(org.hibernate.search.mapper.orm.search.loading.EntityLoadingCacheLookupStrategy) SchemaManagementListener(org.hibernate.search.mapper.orm.schema.management.impl.SchemaManagementListener) SchemaManagementStrategyName(org.hibernate.search.mapper.orm.schema.management.SchemaManagementStrategyName)

Example 3 with SchemaManagementStrategyName

use of org.hibernate.search.mapper.orm.schema.management.SchemaManagementStrategyName in project hapi-fhir-jpaserver-starter by hapifhir.

the class EnvironmentHelper method getHibernateProperties.

public static Properties getHibernateProperties(ConfigurableEnvironment environment, ConfigurableListableBeanFactory myConfigurableListableBeanFactory) {
    Properties properties = new Properties();
    Map<String, Object> jpaProps = getPropertiesStartingWith(environment, "spring.jpa.properties");
    for (Map.Entry<String, Object> entry : jpaProps.entrySet()) {
        String strippedKey = entry.getKey().replace("spring.jpa.properties.", "");
        properties.put(strippedKey, entry.getValue().toString());
    }
    // Spring Boot Autoconfiguration defaults
    properties.putIfAbsent(AvailableSettings.SCANNER, "org.hibernate.boot.archive.scan.internal.DisabledScanner");
    properties.putIfAbsent(AvailableSettings.IMPLICIT_NAMING_STRATEGY, SpringImplicitNamingStrategy.class.getName());
    properties.putIfAbsent(AvailableSettings.PHYSICAL_NAMING_STRATEGY, SpringPhysicalNamingStrategy.class.getName());
    // TODO The bean factory should be added as parameter but that requires that it can be injected from the entityManagerFactory bean from xBaseConfig
    // properties.putIfAbsent(AvailableSettings.BEAN_CONTAINER, new SpringBeanContainer(beanFactory));
    // hapi-fhir-jpaserver-base "sensible defaults"
    Map<String, Object> hapiJpaPropertyMap = new HapiFhirLocalContainerEntityManagerFactoryBean(myConfigurableListableBeanFactory).getJpaPropertyMap();
    hapiJpaPropertyMap.forEach(properties::putIfAbsent);
    // hapi-fhir-jpaserver-starter defaults
    properties.putIfAbsent(AvailableSettings.FORMAT_SQL, false);
    properties.putIfAbsent(AvailableSettings.SHOW_SQL, false);
    properties.putIfAbsent(AvailableSettings.HBM2DDL_AUTO, "update");
    properties.putIfAbsent(AvailableSettings.STATEMENT_BATCH_SIZE, 20);
    properties.putIfAbsent(AvailableSettings.USE_QUERY_CACHE, false);
    properties.putIfAbsent(AvailableSettings.USE_SECOND_LEVEL_CACHE, false);
    properties.putIfAbsent(AvailableSettings.USE_STRUCTURED_CACHE, false);
    properties.putIfAbsent(AvailableSettings.USE_MINIMAL_PUTS, false);
    // Hibernate Search defaults
    properties.putIfAbsent(HibernateOrmMapperSettings.ENABLED, false);
    if (Boolean.parseBoolean(String.valueOf(properties.get(HibernateOrmMapperSettings.ENABLED)))) {
        if (isElasticsearchEnabled(environment)) {
            properties.putIfAbsent(BackendSettings.backendKey(BackendSettings.TYPE), ElasticsearchBackendSettings.TYPE_NAME);
        } else {
            properties.putIfAbsent(BackendSettings.backendKey(BackendSettings.TYPE), LuceneBackendSettings.TYPE_NAME);
        }
        if (properties.get(BackendSettings.backendKey(BackendSettings.TYPE)).equals(LuceneBackendSettings.TYPE_NAME)) {
            properties.putIfAbsent(BackendSettings.backendKey(LuceneIndexSettings.DIRECTORY_TYPE), LocalFileSystemDirectoryProvider.NAME);
            properties.putIfAbsent(BackendSettings.backendKey(LuceneIndexSettings.DIRECTORY_ROOT), "target/lucenefiles");
            properties.putIfAbsent(BackendSettings.backendKey(LuceneBackendSettings.ANALYSIS_CONFIGURER), HapiLuceneAnalysisConfigurer.class.getName());
            properties.putIfAbsent(BackendSettings.backendKey(LuceneBackendSettings.LUCENE_VERSION), Version.LATEST);
        } else if (properties.get(BackendSettings.backendKey(BackendSettings.TYPE)).equals(ElasticsearchBackendSettings.TYPE_NAME)) {
            ElasticsearchHibernatePropertiesBuilder builder = new ElasticsearchHibernatePropertiesBuilder();
            IndexStatus requiredIndexStatus = environment.getProperty("elasticsearch.required_index_status", IndexStatus.class);
            builder.setRequiredIndexStatus(requireNonNullElse(requiredIndexStatus, IndexStatus.YELLOW));
            builder.setHosts(getElasticsearchServerUrl(environment));
            builder.setUsername(getElasticsearchServerUsername(environment));
            builder.setPassword(getElasticsearchServerPassword(environment));
            builder.setProtocol(getElasticsearchServerProtocol(environment));
            SchemaManagementStrategyName indexSchemaManagementStrategy = environment.getProperty("elasticsearch.schema_management_strategy", SchemaManagementStrategyName.class);
            builder.setIndexSchemaManagementStrategy(requireNonNullElse(indexSchemaManagementStrategy, SchemaManagementStrategyName.CREATE));
            Boolean refreshAfterWrite = environment.getProperty("elasticsearch.debug.refresh_after_write", Boolean.class);
            if (refreshAfterWrite == null || !refreshAfterWrite) {
                builder.setDebugIndexSyncStrategy(AutomaticIndexingSynchronizationStrategyNames.ASYNC);
            } else {
                builder.setDebugIndexSyncStrategy(AutomaticIndexingSynchronizationStrategyNames.READ_SYNC);
            }
            builder.setDebugPrettyPrintJsonLog(requireNonNullElse(environment.getProperty("elasticsearch.debug.pretty_print_json_log", Boolean.class), false));
            builder.apply(properties);
        } else {
            throw new UnsupportedOperationException("Unsupported Hibernate Search backend: " + properties.get(BackendSettings.backendKey(BackendSettings.TYPE)));
        }
    }
    return properties;
}
Also used : HapiFhirLocalContainerEntityManagerFactoryBean(ca.uhn.fhir.jpa.config.HapiFhirLocalContainerEntityManagerFactoryBean) Properties(java.util.Properties) HapiLuceneAnalysisConfigurer(ca.uhn.fhir.jpa.search.HapiLuceneAnalysisConfigurer) SpringPhysicalNamingStrategy(org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy) SchemaManagementStrategyName(org.hibernate.search.mapper.orm.schema.management.SchemaManagementStrategyName) IndexStatus(org.hibernate.search.backend.elasticsearch.index.IndexStatus) ElasticsearchHibernatePropertiesBuilder(ca.uhn.fhir.jpa.search.elastic.ElasticsearchHibernatePropertiesBuilder) SpringImplicitNamingStrategy(org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with SchemaManagementStrategyName

use of org.hibernate.search.mapper.orm.schema.management.SchemaManagementStrategyName in project hibernate-search by hibernate.

the class AbstractSchemaManagementStrategyIT method noIndexedType.

@Test
public void noIndexedType() {
    SchemaManagementStrategyName strategyName = getStrategyName();
    SessionFactory sessionFactory = setupHelper.start().withProperty(HibernateOrmMapperSettings.SCHEMA_MANAGEMENT_STRATEGY, strategyName == null ? null : strategyName.externalRepresentation()).setup();
    // Nothing should have happened
    backendMock.verifyExpectationsMet();
    sessionFactory.close();
    // Nothing should have happened
    backendMock.verifyExpectationsMet();
}
Also used : SessionFactory(org.hibernate.SessionFactory) SchemaManagementStrategyName(org.hibernate.search.mapper.orm.schema.management.SchemaManagementStrategyName) Test(org.junit.Test)

Aggregations

SchemaManagementStrategyName (org.hibernate.search.mapper.orm.schema.management.SchemaManagementStrategyName)4 HapiFhirLocalContainerEntityManagerFactoryBean (ca.uhn.fhir.jpa.config.HapiFhirLocalContainerEntityManagerFactoryBean)1 HapiLuceneAnalysisConfigurer (ca.uhn.fhir.jpa.search.HapiLuceneAnalysisConfigurer)1 ElasticsearchHibernatePropertiesBuilder (ca.uhn.fhir.jpa.search.elastic.ElasticsearchHibernatePropertiesBuilder)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Properties (java.util.Properties)1 SessionFactory (org.hibernate.SessionFactory)1 IndexStatus (org.hibernate.search.backend.elasticsearch.index.IndexStatus)1 SchemaManagementListener (org.hibernate.search.mapper.orm.schema.management.impl.SchemaManagementListener)1 EntityLoadingCacheLookupStrategy (org.hibernate.search.mapper.orm.search.loading.EntityLoadingCacheLookupStrategy)1 Test (org.junit.Test)1 SpringImplicitNamingStrategy (org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy)1 SpringPhysicalNamingStrategy (org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy)1