From eee8c79add98a906b8d659e437394aae23d64d9a Mon Sep 17 00:00:00 2001 From: jvi Date: Mon, 8 Feb 2021 14:10:34 +0100 Subject: [PATCH] Fix to #199 --- .../fhir/jpa/starter/EnvironmentHelper.java | 40 +++++++++---------- src/main/resources/application.yaml | 6 +-- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/main/java/ca/uhn/fhir/jpa/starter/EnvironmentHelper.java b/src/main/java/ca/uhn/fhir/jpa/starter/EnvironmentHelper.java index 6dd8311..d5384c1 100644 --- a/src/main/java/ca/uhn/fhir/jpa/starter/EnvironmentHelper.java +++ b/src/main/java/ca/uhn/fhir/jpa/starter/EnvironmentHelper.java @@ -18,29 +18,29 @@ public class EnvironmentHelper { public static Properties getHibernateProperties(ConfigurableEnvironment environment) { Properties properties = new Properties(); - if (environment.getProperty("spring.jpa.properties", String.class) == null) { - properties.put("hibernate.search.model_mapping", "ca.uhn.fhir.jpa.search.LuceneSearchMappingFactory"); - properties.put("hibernate.format_sql", "false"); - properties.put("hibernate.show_sql", "false"); - properties.put("hibernate.hbm2ddl.auto", "update"); - properties.put("hibernate.jdbc.batch_size", "20"); - properties.put("hibernate.cache.use_query_cache", "false"); - properties.put("hibernate.cache.use_second_level_cache", "false"); - properties.put("hibernate.cache.use_structured_entries", "false"); - properties.put("hibernate.cache.use_minimal_puts", "false"); - properties.put("hibernate.search.default.directory_provider", "filesystem"); - properties.put("hibernate.search.default.indexBase", "target/lucenefiles"); - properties.put("hibernate.search.lucene_version", "LUCENE_CURRENT"); - } else { - Arrays.asList(environment.getProperty("spring.jpa.properties", String.class).split(" ")).stream().forEach(s -> - { - String[] values = s.split("="); - properties.put(values[0], values[1]); - }); + Map jpaProps = getPropertiesStartingWith(environment, "spring.jpa.properties"); + + properties.putIfAbsent("hibernate.search.model_mapping", "ca.uhn.fhir.jpa.search.LuceneSearchMappingFactory"); + properties.putIfAbsent("hibernate.format_sql", "false"); + properties.putIfAbsent("hibernate.show_sql", "false"); + properties.putIfAbsent("hibernate.hbm2ddl.auto", "update"); + properties.putIfAbsent("hibernate.jdbc.batch_size", "20"); + properties.putIfAbsent("hibernate.cache.use_query_cache", "false"); + properties.putIfAbsent("hibernate.cache.use_second_level_cache", "false"); + properties.putIfAbsent("hibernate.cache.use_structured_entries", "false"); + properties.putIfAbsent("hibernate.cache.use_minimal_puts", "false"); + properties.putIfAbsent("hibernate.search.default.directory_provider", "filesystem"); + properties.putIfAbsent("hibernate.search.default.indexBase", "target/lucenefiles"); + properties.putIfAbsent("hibernate.search.lucene_version", "LUCENE_CURRENT"); + + for (Map.Entry entry : jpaProps.entrySet()) { + String strippedKey = entry.getKey().replace("spring.jpa.properties.", ""); + properties.put(strippedKey, entry.getValue().toString()); } + if (environment.getProperty("elasticsearch.enabled", Boolean.class) != null - && environment.getProperty("elasticsearch.enabled", Boolean.class) == true ){ + && environment.getProperty("elasticsearch.enabled", Boolean.class) == true) { ElasticsearchHibernatePropertiesBuilder builder = new ElasticsearchHibernatePropertiesBuilder(); ElasticsearchIndexStatus requiredIndexStatus = environment.getProperty("elasticsearch.required_index_status", ElasticsearchIndexStatus.class); if (requiredIndexStatus == null) { diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index 7c6a11c..5efd453 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -6,11 +6,11 @@ spring: password: null driverClassName: org.h2.Driver max-active: 15 -# jpa: -# properties: + jpa: + properties: # hibernate.dialect: org.hibernate.dialect.h2dialect # hibernate.search.model_mapping: ca.uhn.fhir.jpa.search.lucenesearchmappingfactory -# hibernate.format_sql: false + hibernate.format_sql: true # hibernate.show_sql: false # hibernate.hbm2ddl.auto: update # hibernate.jdbc.batch_size: 20