aboutsummaryrefslogtreecommitdiff
path: root/id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/ConfigurationImpl.java
diff options
context:
space:
mode:
Diffstat (limited to 'id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/ConfigurationImpl.java')
-rw-r--r--id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/ConfigurationImpl.java79
1 files changed, 51 insertions, 28 deletions
diff --git a/id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/ConfigurationImpl.java b/id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/ConfigurationImpl.java
index 5cab9a5ff..297a1db4c 100644
--- a/id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/ConfigurationImpl.java
+++ b/id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/ConfigurationImpl.java
@@ -42,9 +42,17 @@ public class ConfigurationImpl implements Configuration {
public Object get(String key) {
// return null if key does not exist
try {
- return mapper.deserialize(configPropertyDao.getProperty(key).getValue(), null);
+ ConfigProperty property = configPropertyDao.getProperty(key);
+ if (property != null && property.getValue() != null) {
+ return mapper.deserialize(property.getValue(), null);
+ } else {
+ return null;
+ }
+ } catch (IllegalArgumentException e) {
+ log.debug("Error while searching for key '{}' in the database.", key);
+ return null;
} catch (Exception e) {
- log.trace("Error while deserializing value of key '{}' to object.", key);
+ log.debug("Error while deserializing value of key '{}' to object.", key);
return null;
}
}
@@ -52,37 +60,49 @@ public class ConfigurationImpl implements Configuration {
@Override
public <T> T get(String key, Class<T> clazz) {
// return null if key does not exist
- ConfigProperty property = configPropertyDao.getProperty(key);
- if (property != null && property.getValue() != null) {
- try {
+ try {
+ ConfigProperty property = configPropertyDao.getProperty(key);
+ if (property != null && property.getValue() != null) {
return clazz.cast(mapper.deserialize(property.getValue(), clazz));
- } catch (IOException e) {
- log.trace("Error while deserializing value of key '{}' to object of type {}.",key,clazz.getClass());
+ } else {
return null;
}
- } else {
+ } catch (IllegalArgumentException e) {
+ log.debug("Error while searching for key '{}' in the database.", key);
+ return null;
+ } catch (Exception e) {
+ log.debug("Error while deserializing value of key '{}' to object of type {}.", key, clazz.getClass());
return null;
}
}
@Override
public boolean set(String key, Object value) {
+ return this.set(key, value, false);
+ }
- if (value == null) {
- configPropertyDao.delete(key);
- return true;
- } else {
+ @Override
+ public boolean set(String key, Object value, boolean overwrite) {
+
+ try {
+ if (value == null) {
+ configPropertyDao.delete(key);
+ return true;
+ } else {
+
+ ConfigProperty keyValue = new ConfigProperty();
+ keyValue.setKey(key);
- ConfigProperty keyValue = new ConfigProperty();
- keyValue.setKey(key);
- try {
keyValue.setValue(mapper.serialize(value));
- configPropertyDao.saveProperty(keyValue);
+ configPropertyDao.saveProperty(keyValue, overwrite);
return true;
- } catch (JsonProcessingException e) {
- log.trace("Error while serializing object for key '{}'.", key);
- return false;
}
+ } catch (JsonProcessingException e) {
+ log.debug("Error while serializing object for key '{}'.", key);
+ return false;
+ } catch (Exception e){
+ log.debug("Error while setting value for key '{}' in the database.", key);
+ return false;
}
}
@@ -102,24 +122,27 @@ public class ConfigurationImpl implements Configuration {
public <T> List<T> getList(String key, Class<T> clazz) {
CollectionType listType = TypeFactory.defaultInstance().constructCollectionType(List.class, clazz);
-
- if(configPropertyDao.getProperty(key)==null){
- return new ArrayList<T>();
- }
- String json = configPropertyDao.getProperty(key).getValue();
- ObjectMapper mapper = new ObjectMapper();
-
try {
+ if ((configPropertyDao.getProperty(key) == null)
+ || (configPropertyDao.getProperty(key).getValue() == null)) {
+ return new ArrayList<T>();
+ }
+ String json = configPropertyDao.getProperty(key).getValue();
+ ObjectMapper mapper = new ObjectMapper();
+
return (List<T>) mapper.readValue(json, listType);
} catch (JsonMappingException e) {
ArrayList<T> tmp = new ArrayList<T>();
T value = get(key, clazz);
- if(value != null){
+ if (value != null) {
tmp.add(value);
}
return tmp;
} catch (IOException e) {
- log.trace("Error while deserializing value for key '{}' to List<{}>.", key,clazz.getClass());
+ log.debug("Error while deserializing value for key '{}' to List<{}>.", key, clazz.getClass());
+ return new ArrayList<T>();
+ } catch (Exception e){
+ log.debug("Error while searching key '{}' in the database.", key);
return new ArrayList<T>();
}
}