Skip to content

Commit

Permalink
add safeget method
Browse files Browse the repository at this point in the history
  • Loading branch information
vietnguyen committed Nov 27, 2024
1 parent d17f207 commit 164a659
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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;
}
}
}

0 comments on commit 164a659

Please sign in to comment.