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);
|
||||||
@ -101,7 +123,7 @@ public class ConfigService implements Serializable {
|
|||||||
@Transactional
|
@Transactional
|
||||||
@Lock(LockType.WRITE)
|
@Lock(LockType.WRITE)
|
||||||
public boolean updateConfigValue(String configKey, String accountName, String configValue) {
|
public boolean updateConfigValue(String configKey, String accountName, String configValue) {
|
||||||
if ((configKey == null) || (configKey.equals ("")) || (configValue == null) || (configValue.equals (""))) {
|
if ((configKey == null) || (configKey.equals("")) || (configValue == null) || (configValue.equals(""))) {
|
||||||
// null or empty key / values are not possible
|
// null or empty key / values are not possible
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user