Skip to content

Commit

Permalink
fix: use default schema validate if config value is invalid (#19312)
Browse files Browse the repository at this point in the history
  • Loading branch information
vietnguyen authored Dec 3, 2024
1 parent c02f941 commit 96ee381
Showing 1 changed file with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
*/
package org.hisp.dhis.config;

import static org.hisp.dhis.external.conf.ConfigurationKey.CONNECTION_SCHEMA;
import static org.hisp.dhis.external.conf.ConfigurationKey.USE_QUERY_CACHE;
import static org.hisp.dhis.external.conf.ConfigurationKey.USE_SECOND_LEVEL_CACHE;

Expand Down Expand Up @@ -137,7 +138,7 @@ public EntityManagerFactory entityManagerFactory(
* @return TRUE if connection.schema is not set to none
*/
private boolean shouldGenerateDDL(DhisConfigurationProvider dhisConfig) {
return "update".equals(dhisConfig.getProperty(ConfigurationKey.CONNECTION_SCHEMA));
return "update".equals(dhisConfig.getProperty(CONNECTION_SCHEMA));
}

/**
Expand Down Expand Up @@ -180,9 +181,7 @@ private Properties getAdditionalProperties(DhisConfigurationProvider dhisConfig)
MissingCacheStrategy.CREATE.getExternalRepresentation());
}

properties.put(
AvailableSettings.HBM2DDL_AUTO,
Action.valueOf(dhisConfig.getProperty(ConfigurationKey.CONNECTION_SCHEMA).toUpperCase()));
properties.put(AvailableSettings.HBM2DDL_AUTO, getHibernateSchemaAction(dhisConfig));

properties.put(
AvailableSettings.SHOW_SQL, dhisConfig.getProperty(ConfigurationKey.HIBERNATE_SHOW_SQL));
Expand All @@ -197,4 +196,16 @@ private Properties getAdditionalProperties(DhisConfigurationProvider dhisConfig)

return properties;
}

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 96ee381

Please sign in to comment.