diff options
Diffstat (limited to 'id/server/moa-id-commons/src/main/java/com')
4 files changed, 41 insertions, 5 deletions
diff --git a/id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/Configuration.java b/id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/Configuration.java index 6ec43c583..43f7d9454 100644 --- a/id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/Configuration.java +++ b/id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/Configuration.java @@ -27,7 +27,7 @@ public interface Configuration { * @param key * @param value */ - void set(String key, Object value); + boolean set(String key, Object value); /** * @@ -45,4 +45,11 @@ public interface Configuration { * @return */ <T> List<T> getList(String key, Class<T> clazz); + + /** + * + * @param key + * @return + */ + void delete(String key); }
\ No newline at end of file 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 7a52d0c9d..eebecf509 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 @@ -66,7 +66,7 @@ public class ConfigurationImpl implements Configuration { } @Override - public void set(String key, Object value) { + public boolean set(String key, Object value) { ConfigProperty keyValue = new ConfigProperty(); keyValue.setKey(key); @@ -74,10 +74,11 @@ public class ConfigurationImpl implements Configuration { keyValue.setValue(mapper.serialize(value)); // System.out.println(">> key - value: " + keyValue.getKey() + " - " + keyValue.getValue() + "\n"); configPropertyDao.saveProperty(keyValue); - + return true; } catch (JsonProcessingException e) { // TODO do proper error handling e.printStackTrace(); + return false; } } @@ -98,6 +99,10 @@ 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(); @@ -120,6 +125,12 @@ public class ConfigurationImpl implements Configuration { return property.getValue(); } + @Override + public void delete(String key) { + configPropertyDao.delete(key); + } + + /** * * @@ -178,4 +189,5 @@ public class ConfigurationImpl implements Configuration { }; + } diff --git a/id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/dal/ConfigPropertyDao.java b/id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/dal/ConfigPropertyDao.java index a11d23ce8..50dddd745 100644 --- a/id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/dal/ConfigPropertyDao.java +++ b/id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/dal/ConfigPropertyDao.java @@ -42,4 +42,11 @@ public interface ConfigPropertyDao { * @param properties The list containing all the properties to be persisted. */ public void saveProperties(Set<ConfigProperty> properties); + + /** + * Deletes the object associated with the given key. + * @param key the key + */ + public void delete(String key); + } diff --git a/id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/dal/ConfigPropertyDaoImpl.java b/id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/dal/ConfigPropertyDaoImpl.java index 2b28cb245..752c7dc09 100644 --- a/id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/dal/ConfigPropertyDaoImpl.java +++ b/id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/dal/ConfigPropertyDaoImpl.java @@ -64,12 +64,12 @@ public class ConfigPropertyDaoImpl implements ConfigPropertyDao { @Override public List<ConfigProperty> getProperties() { - + if (null == em) { log.error("No EntityManager set!"); return null; } - + log.debug("Retrieving all properties from database."); TypedQuery<ConfigProperty> query = em.createQuery("select mc from ConfigProperty mc", ConfigProperty.class); try { @@ -90,4 +90,14 @@ public class ConfigPropertyDaoImpl implements ConfigPropertyDao { em.flush(); } + @Override + public void delete(String key) { + log.debug("Deleting entry with key '{}'.", key); + try{ + em.remove(em.find(ConfigProperty.class, key)); + }catch (IllegalArgumentException e){ + log.trace("Error while deleting entry with key '{}':" + e.getMessage(), key); + } + } + } |