From 164a6595c4652c79ea1f5d043ba02ab7d71b3d19 Mon Sep 17 00:00:00 2001 From: Viet Nguyen Date: Tue, 26 Nov 2024 23:45:54 -0600 Subject: [PATCH] add safeget method --- .../org/hisp/dhis/config/HibernateConfig.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/config/HibernateConfig.java b/dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/config/HibernateConfig.java index 1967b6a7b60..363ab7a7069 100644 --- a/dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/config/HibernateConfig.java +++ b/dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/config/HibernateConfig.java @@ -157,9 +157,7 @@ private Properties getAdditionalProperties(DhisConfigurationProvider dhisConfig) properties.put(AvailableSettings.USE_QUERY_CACHE, dhisConfig.getProperty(USE_QUERY_CACHE)); } - properties.put( - AvailableSettings.HBM2DDL_AUTO, - Action.valueOf(dhisConfig.getProperty(CONNECTION_SCHEMA).toUpperCase())); + properties.put(AvailableSettings.HBM2DDL_AUTO, getHibernateSchemaAction(dhisConfig)); // TODO: this is anti-pattern and should be turn off properties.put("hibernate.allow_update_outside_transaction", "true"); @@ -197,4 +195,16 @@ private String[] loadResources() { private boolean shouldGenerateDDL(DhisConfigurationProvider dhisConfig) { return "update".equals(dhisConfig.getProperty(ConfigurationKey.CONNECTION_SCHEMA)); } + + private Action getHibernateSchemaAction(DhisConfigurationProvider dhisConfig) { + try { + return Action.interpretHbm2ddlSetting(dhisConfig.getProperty(CONNECTION_SCHEMA)); + } catch (Exception e) { + log.warn( + String.format( + "Invalid value for property connection.schema: %s. Using validate as default mode.", + dhisConfig.getProperty(CONNECTION_SCHEMA))); + return Action.VALIDATE; + } + } }