added support for default values
This commit is contained in:
@ -81,6 +81,28 @@ public class ConfigService implements Serializable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getConfigValue(String configKey, String defaultValue) throws ConfigException {
|
||||||
|
return getConfigValue(configKey, defaultValue, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getConfigValue(String configKey, String defaultValue, boolean storeDefaultValue) throws ConfigException {
|
||||||
|
// get configValue as usual
|
||||||
|
String configValue = getConfigValue(configKey);
|
||||||
|
|
||||||
|
// if config value is not found null has been returned
|
||||||
|
// in this case the value to return is the defaultValue
|
||||||
|
if (configValue == null) {
|
||||||
|
configValue = defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if the default value should be stored in the database
|
||||||
|
if (storeDefaultValue) {
|
||||||
|
updateConfigValue(configKey, null, configValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
public String getConfigValue(String configKey, AccountEntity account) throws ConfigException {
|
public String getConfigValue(String configKey, AccountEntity account) throws ConfigException {
|
||||||
Query query = em.createNamedQuery("ConfigEntity.findByConfigKeyAndAccount");
|
Query query = em.createNamedQuery("ConfigEntity.findByConfigKeyAndAccount");
|
||||||
query.setParameter("configKey", configKey);
|
query.setParameter("configKey", configKey);
|
||||||
|
|||||||
Reference in New Issue
Block a user