changeset 213:8fdb699405aa

Refactored repositories to avoid race conditions.
author Raimund Renkert <rrenkert@intevation.de>
date Wed, 03 Jul 2013 15:54:00 +0200
parents 5b232dab4b50
children 0b233de80756
files src/main/java/de/intevation/lada/authentication/LdapAuthentication.java src/main/java/de/intevation/lada/data/LKommentarMRepository.java src/main/java/de/intevation/lada/data/LKommentarPRepository.java src/main/java/de/intevation/lada/data/LMessungRepository.java src/main/java/de/intevation/lada/data/LMesswertRepository.java src/main/java/de/intevation/lada/data/LOrtRepository.java src/main/java/de/intevation/lada/data/LProbeRepository.java src/main/java/de/intevation/lada/data/LStatusRepository.java src/main/java/de/intevation/lada/data/LZusatzwertRepository.java src/main/java/de/intevation/lada/data/OrtRepository.java src/main/java/de/intevation/lada/data/QueryBuilder.java src/main/java/de/intevation/lada/data/ReadOnlyRepository.java src/main/java/de/intevation/lada/data/Repository.java src/main/java/de/intevation/lada/utils/Resources.java
diffstat 14 files changed, 579 insertions(+), 115 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/de/intevation/lada/authentication/LdapAuthentication.java	Wed Jul 03 12:21:20 2013 +0200
+++ b/src/main/java/de/intevation/lada/authentication/LdapAuthentication.java	Wed Jul 03 15:54:00 2013 +0200
@@ -3,6 +3,7 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import javax.enterprise.context.ApplicationScoped;
 import javax.enterprise.context.RequestScoped;
 import javax.inject.Inject;
 import javax.inject.Named;
@@ -27,7 +28,7 @@
  *
  * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a>
  */
-@RequestScoped
+@ApplicationScoped
 @Named("ldapauth")
 public class LdapAuthentication
 implements Authentication
--- a/src/main/java/de/intevation/lada/data/LKommentarMRepository.java	Wed Jul 03 12:21:20 2013 +0200
+++ b/src/main/java/de/intevation/lada/data/LKommentarMRepository.java	Wed Jul 03 15:54:00 2013 +0200
@@ -1,10 +1,17 @@
 package de.intevation.lada.data;
 
+import java.util.List;
+
 import javax.ejb.EJBTransactionRolledbackException;
+import javax.enterprise.context.ApplicationScoped;
 import javax.inject.Inject;
 import javax.inject.Named;
 import javax.persistence.EntityExistsException;
+import javax.persistence.EntityManager;
 import javax.persistence.TransactionRequiredException;
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Root;
 
 import de.intevation.lada.manage.Manager;
 import de.intevation.lada.model.LKommentarM;
@@ -16,10 +23,15 @@
  * 
  * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a>
  */
+@ApplicationScoped
 @Named("lkommentarmrepository")
-public class LKommentarMRepository
-extends Repository
+public class LKommentarMRepository implements Repository
 {
+    /**
+     * The entitymanager managing the data.
+     */
+    @Inject
+    private EntityManager em;
 
     /**
      * Manager class for LPRobe. Used to manipulate data objects.
@@ -28,6 +40,51 @@
     @Named("datamanager")
     private Manager manager;
 
+    public EntityManager getEntityManager() {
+        return this.em;
+    }
+    /**
+     * Filter object list by the given criteria.
+     *
+     * @param criteria
+     * @return List of objects.
+     */
+    public <T> Response filter(CriteriaQuery<T> filter) {
+        List<T> result = em.createQuery(filter).getResultList();
+        return new Response(true, 200, result);
+    }
+
+
+    /**
+     * Get all objects of type <link>clazz</link>from database.
+     *
+     * @param clazz The class type.
+     * @return List of objects.
+     */
+    public <T> Response findAll(Class<T> clazz) {
+        CriteriaBuilder builder = em.getCriteriaBuilder();
+        CriteriaQuery<T> criteria = builder.createQuery(clazz);
+        Root<T> member = criteria.from(clazz);
+        criteria.select(member);
+        List<T> result = em.createQuery(criteria).getResultList();
+        return new Response(true, 200, result);
+    }
+
+    /**
+     * Find a single object identified by its id.
+     * 
+     * @param clazz The class type.
+     * @param id The object id.
+     * @return The requested object of type clazz
+     */
+    public <T> Response findById(Class<T> clazz, String id) {
+        T item = em.find(clazz, id);
+        if (item == null) {
+            return new Response(false, 600, null);
+        }
+        return new Response(true, 200, item);
+    }
+
     @Override
     public Response create(Object object) {
         if (!(object instanceof LKommentarM)) {
--- a/src/main/java/de/intevation/lada/data/LKommentarPRepository.java	Wed Jul 03 12:21:20 2013 +0200
+++ b/src/main/java/de/intevation/lada/data/LKommentarPRepository.java	Wed Jul 03 15:54:00 2013 +0200
@@ -1,22 +1,32 @@
 package de.intevation.lada.data;
 
+import java.util.List;
 import java.util.logging.Logger;
 
 import javax.ejb.EJBTransactionRolledbackException;
+import javax.enterprise.context.ApplicationScoped;
 import javax.inject.Inject;
 import javax.inject.Named;
 import javax.persistence.EntityExistsException;
+import javax.persistence.EntityManager;
 import javax.persistence.TransactionRequiredException;
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Root;
 
 import de.intevation.lada.manage.Manager;
 import de.intevation.lada.model.LKommentarP;
 import de.intevation.lada.rest.Response;
 
-
+@ApplicationScoped
 @Named("lkommentarRepository")
-public class LKommentarPRepository
-extends Repository
+public class LKommentarPRepository implements Repository
 {
+    /**
+     * The entitymanager managing the data.
+     */
+    @Inject
+    private EntityManager em;
 
     @Inject
     @Named("datamanager")
@@ -25,6 +35,53 @@
     @Inject
     private Logger logger;
 
+    public EntityManager getEntityManager() {
+        return this.em;
+    }
+
+    /**
+     * Filter object list by the given criteria.
+     *
+     * @param criteria
+     * @return List of objects.
+     */
+    public <T> Response filter(CriteriaQuery<T> filter) {
+        List<T> result = em.createQuery(filter).getResultList();
+        return new Response(true, 200, result);
+    }
+
+
+    /**
+     * Get all objects of type <link>clazz</link>from database.
+     *
+    * @param clazz The class type.
+    * @return List of objects.
+    */
+   public <T> Response findAll(Class<T> clazz) {
+       CriteriaBuilder builder = em.getCriteriaBuilder();
+       CriteriaQuery<T> criteria = builder.createQuery(clazz);
+       Root<T> member = criteria.from(clazz);
+       criteria.select(member);
+       List<T> result = em.createQuery(criteria).getResultList();
+       return new Response(true, 200, result);
+   }
+
+   /**
+    * Find a single object identified by its id.
+    * 
+    * @param clazz The class type.
+    * @param id The object id.
+    * @return The requested object of type clazz
+    */
+   public <T> Response findById(Class<T> clazz, String id) {
+       T item = em.find(clazz, id);
+       if (item == null) {
+           return new Response(false, 600, null);
+       }
+       return new Response(true, 200, item);
+   }
+
+
     public Response create(Object object) {
         if (!(object instanceof LKommentarP)) {
             return new Response(false, 602, object);
@@ -54,7 +111,6 @@
         return response;
     }
 
-    @Override
     public Response update(Object object) {
         if (!(object instanceof LKommentarP)) {
             return new Response(false, 602, object);
@@ -84,7 +140,6 @@
         return response;
     }
 
-    @Override
     public Response delete(Object object) {
         if (!(object instanceof LKommentarP)) {
             return new Response(false, 602, null);
--- a/src/main/java/de/intevation/lada/data/LMessungRepository.java	Wed Jul 03 12:21:20 2013 +0200
+++ b/src/main/java/de/intevation/lada/data/LMessungRepository.java	Wed Jul 03 15:54:00 2013 +0200
@@ -1,12 +1,18 @@
 package de.intevation.lada.data;
 
+import java.util.List;
 import java.util.Map;
 
 import javax.ejb.EJBTransactionRolledbackException;
+import javax.enterprise.context.ApplicationScoped;
 import javax.inject.Inject;
 import javax.inject.Named;
 import javax.persistence.EntityExistsException;
+import javax.persistence.EntityManager;
 import javax.persistence.TransactionRequiredException;
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Root;
 
 import de.intevation.lada.manage.Manager;
 import de.intevation.lada.model.LMessung;
@@ -20,10 +26,15 @@
  * 
  * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a>
  */
+@ApplicationScoped
 @Named("lmessungrepository")
-public class LMessungRepository
-extends Repository
+public class LMessungRepository implements Repository
 {
+    /**
+     * The entitymanager managing the data.
+     */
+    @Inject
+    private EntityManager em;
 
     /**
      * Manager class for LPRobe. Used to manipulate data objects.
@@ -36,6 +47,52 @@
     @Named("lmessungvalidator")
     private Validator validator;
 
+    @Override
+    public EntityManager getEntityManager() {
+        return this.em;
+    }
+    /**
+     * Filter object list by the given criteria.
+     *
+     * @param criteria
+     * @return List of objects.
+     */
+    public <T> Response filter(CriteriaQuery<T> filter) {
+        List<T> result = em.createQuery(filter).getResultList();
+        return new Response(true, 200, result);
+    }
+
+
+    /**
+     * Get all objects of type <link>clazz</link>from database.
+     *
+     * @param clazz The class type.
+     * @return List of objects.
+     */
+    public <T> Response findAll(Class<T> clazz) {
+        CriteriaBuilder builder = em.getCriteriaBuilder();
+        CriteriaQuery<T> criteria = builder.createQuery(clazz);
+        Root<T> member = criteria.from(clazz);
+        criteria.select(member);
+        List<T> result = em.createQuery(criteria).getResultList();
+        return new Response(true, 200, result);
+    }
+
+    /**
+     * Find a single object identified by its id.
+     * 
+     * @param clazz The class type.
+     * @param id The object id.
+     * @return The requested object of type clazz
+     */
+    public <T> Response findById(Class<T> clazz, String id) {
+        T item = em.find(clazz, id);
+        if (item == null) {
+            return new Response(false, 600, null);
+        }
+        return new Response(true, 200, item);
+    }
+
     /**
      * Validate and persist a new LProbe object.
      *
--- a/src/main/java/de/intevation/lada/data/LMesswertRepository.java	Wed Jul 03 12:21:20 2013 +0200
+++ b/src/main/java/de/intevation/lada/data/LMesswertRepository.java	Wed Jul 03 15:54:00 2013 +0200
@@ -1,10 +1,17 @@
 package de.intevation.lada.data;
 
+import java.util.List;
+
 import javax.ejb.EJBTransactionRolledbackException;
+import javax.enterprise.context.ApplicationScoped;
 import javax.inject.Inject;
 import javax.inject.Named;
 import javax.persistence.EntityExistsException;
+import javax.persistence.EntityManager;
 import javax.persistence.TransactionRequiredException;
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Root;
 
 import de.intevation.lada.manage.Manager;
 import de.intevation.lada.model.LMesswert;
@@ -16,10 +23,15 @@
  * 
  * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a>
  */
+@ApplicationScoped
 @Named("lmesswertrepository")
-public class LMesswertRepository
-extends Repository
+public class LMesswertRepository implements Repository
 {
+    /**
+     * The entitymanager managing the data.
+     */
+    @Inject
+    private EntityManager em;
 
     /**
      * Manager class for LPRobe. Used to manipulate data objects.
@@ -28,7 +40,51 @@
     @Named("datamanager")
     private Manager manager;
 
-    @Override
+    public EntityManager getEntityManager() {
+        return this.em;
+    }
+    /**
+     * Filter object list by the given criteria.
+     *
+     * @param criteria
+     * @return List of objects.
+     */
+    public <T> Response filter(CriteriaQuery<T> filter) {
+        List<T> result = em.createQuery(filter).getResultList();
+        return new Response(true, 200, result);
+    }
+
+
+    /**
+     * Get all objects of type <link>clazz</link>from database.
+     *
+     * @param clazz The class type.
+     * @return List of objects.
+     */
+    public <T> Response findAll(Class<T> clazz) {
+        CriteriaBuilder builder = em.getCriteriaBuilder();
+        CriteriaQuery<T> criteria = builder.createQuery(clazz);
+        Root<T> member = criteria.from(clazz);
+        criteria.select(member);
+        List<T> result = em.createQuery(criteria).getResultList();
+        return new Response(true, 200, result);
+    }
+
+    /**
+     * Find a single object identified by its id.
+     * 
+     * @param clazz The class type.
+     * @param id The object id.
+     * @return The requested object of type clazz
+     */
+    public <T> Response findById(Class<T> clazz, String id) {
+        T item = em.find(clazz, id);
+        if (item == null) {
+            return new Response(false, 600, null);
+        }
+        return new Response(true, 200, item);
+    }
+
     public Response create(Object object) {
         if (!(object instanceof LMesswert)) {
             return new Response(false, 602, object);
@@ -59,7 +115,6 @@
         return response;
     }
 
-    @Override
     public Response update(Object object) {
         if (!(object instanceof LMesswert)) {
             return new Response(false, 602, object);
@@ -90,10 +145,8 @@
         return response;
     }
 
-    @Override
     public Response delete(Object object) {
         // TODO Auto-generated method stub
         return null;
     }
-}
-
+}
\ No newline at end of file
--- a/src/main/java/de/intevation/lada/data/LOrtRepository.java	Wed Jul 03 12:21:20 2013 +0200
+++ b/src/main/java/de/intevation/lada/data/LOrtRepository.java	Wed Jul 03 15:54:00 2013 +0200
@@ -1,12 +1,18 @@
 package de.intevation.lada.data;
 
+import java.util.List;
 import java.util.Map;
 
 import javax.ejb.EJBTransactionRolledbackException;
+import javax.enterprise.context.ApplicationScoped;
 import javax.inject.Inject;
 import javax.inject.Named;
 import javax.persistence.EntityExistsException;
+import javax.persistence.EntityManager;
 import javax.persistence.TransactionRequiredException;
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Root;
 
 import de.intevation.lada.manage.Manager;
 import de.intevation.lada.model.LOrt;
@@ -14,10 +20,15 @@
 import de.intevation.lada.validation.ValidationException;
 import de.intevation.lada.validation.Validator;
 
+@ApplicationScoped
 @Named("lortrepository")
-public class LOrtRepository
-extends Repository
+public class LOrtRepository implements Repository
 {
+    /**
+     * The entitymanager managing the data.
+     */
+    @Inject
+    private EntityManager em;
 
     @Inject
     @Named("lortvalidator")
@@ -27,6 +38,52 @@
     @Named("datamanager")
     private Manager manager;
 
+    @Override
+    public EntityManager getEntityManager() {
+        return this.em;
+    }
+
+    /**
+     * Filter object list by the given criteria.
+     *
+     * @param criteria
+     * @return List of objects.
+     */
+    public <T> Response filter(CriteriaQuery<T> filter) {
+        List<T> result = em.createQuery(filter).getResultList();
+        return new Response(true, 200, result);
+    }
+
+    /**
+     * Get all objects of type <link>clazz</link>from database.
+     *
+     * @param clazz The class type.
+     * @return List of objects.
+     */
+    public <T> Response findAll(Class<T> clazz) {
+        CriteriaBuilder builder = em.getCriteriaBuilder();
+        CriteriaQuery<T> criteria = builder.createQuery(clazz);
+        Root<T> member = criteria.from(clazz);
+        criteria.select(member);
+        List<T> result = em.createQuery(criteria).getResultList();
+        return new Response(true, 200, result);
+    }
+
+    /**
+     * Find a single object identified by its id.
+     *
+     * @param clazz The class type.
+     * @param id The object id.
+     * @return The requested object of type clazz
+     */
+    public <T> Response findById(Class<T> clazz, String id) {
+        T item = em.find(clazz, id);
+        if (item == null) {
+            return new Response(false, 600, null);
+        }
+        return new Response(true, 200, item);
+    }
+
     /**
      * Validate and persist a new LProbe object.
      *
--- a/src/main/java/de/intevation/lada/data/LProbeRepository.java	Wed Jul 03 12:21:20 2013 +0200
+++ b/src/main/java/de/intevation/lada/data/LProbeRepository.java	Wed Jul 03 15:54:00 2013 +0200
@@ -1,12 +1,16 @@
 package de.intevation.lada.data;
 
+import java.util.List;
 import java.util.Map;
 
 import javax.ejb.EJBTransactionRolledbackException;
+import javax.enterprise.context.ApplicationScoped;
 import javax.inject.Inject;
 import javax.inject.Named;
 import javax.persistence.EntityExistsException;
+import javax.persistence.EntityManager;
 import javax.persistence.TransactionRequiredException;
+import javax.persistence.criteria.CriteriaQuery;
 
 import de.intevation.lada.manage.Manager;
 import de.intevation.lada.model.LProbe;
@@ -21,9 +25,14 @@
  * 
  * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a>
  */
+@ApplicationScoped
 @Named("lproberepository")
-public class LProbeRepository
-extends Repository{
+public class LProbeRepository implements Repository{
+    /**
+     * The entitymanager managing the data.
+     */
+    @Inject
+    private EntityManager em;
 
     /**
      * Manager class for LPRobe. Used to manipulate data objects.
@@ -36,7 +45,20 @@
     @Named("lprobevalidator")
     private Validator validator;
 
-    @Override
+    public EntityManager getEntityManager() {
+        return this.em;
+    }
+    /**
+     * Filter object list by the given criteria.
+     *
+     * @param criteria
+     * @return List of objects.
+     */
+    public <T> Response filter(CriteriaQuery<T> filter) {
+        List<T> result = em.createQuery(filter).getResultList();
+        return new Response(true, 200, result);
+    }
+
     public <T> Response findAll(Class<T> clazz) {
         QueryBuilder<LProbeInfo> builder =
             new QueryBuilder<LProbeInfo>(this.getEntityManager(), LProbeInfo.class);
@@ -44,7 +66,6 @@
         return filter(builder.getQuery());
     }
 
-    @Override
     public <T> Response findById(Class<T> clazz, String id) {
         QueryBuilder<LProbeInfo> builder =
             new QueryBuilder<LProbeInfo>(this.getEntityManager(), LProbeInfo.class);
--- a/src/main/java/de/intevation/lada/data/LStatusRepository.java	Wed Jul 03 12:21:20 2013 +0200
+++ b/src/main/java/de/intevation/lada/data/LStatusRepository.java	Wed Jul 03 15:54:00 2013 +0200
@@ -1,10 +1,17 @@
 package de.intevation.lada.data;
 
+import java.util.List;
+
 import javax.ejb.EJBTransactionRolledbackException;
+import javax.enterprise.context.ApplicationScoped;
 import javax.inject.Inject;
 import javax.inject.Named;
 import javax.persistence.EntityExistsException;
+import javax.persistence.EntityManager;
 import javax.persistence.TransactionRequiredException;
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Root;
 
 import de.intevation.lada.manage.Manager;
 import de.intevation.lada.model.LStatus;
@@ -16,10 +23,15 @@
  * 
  * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a>
  */
+@ApplicationScoped
 @Named("lstatusrepository")
-public class LStatusRepository
-extends Repository
+public class LStatusRepository implements Repository
 {
+    /**
+     * The entitymanager managing the data.
+     */
+    @Inject
+    private EntityManager em;
 
     /**
      * Manager class for LPRobe. Used to manipulate data objects.
@@ -28,7 +40,52 @@
     @Named("datamanager")
     private Manager manager;
 
-    @Override
+    public EntityManager getEntityManager() {
+        return this.em;
+    }
+
+    /**
+     * Filter object list by the given criteria.
+     *
+     * @param criteria
+     * @return List of objects.
+     */
+    public <T> Response filter(CriteriaQuery<T> filter) {
+        List<T> result = em.createQuery(filter).getResultList();
+        return new Response(true, 200, result);
+    }
+
+
+    /**
+     * Get all objects of type <link>clazz</link>from database.
+     *
+     * @param clazz The class type.
+     * @return List of objects.
+     */
+    public <T> Response findAll(Class<T> clazz) {
+        CriteriaBuilder builder = em.getCriteriaBuilder();
+        CriteriaQuery<T> criteria = builder.createQuery(clazz);
+        Root<T> member = criteria.from(clazz);
+        criteria.select(member);
+        List<T> result = em.createQuery(criteria).getResultList();
+        return new Response(true, 200, result);
+    }
+
+    /**
+     * Find a single object identified by its id.
+     * 
+     * @param clazz The class type.
+     * @param id The object id.
+     * @return The requested object of type clazz
+     */
+    public <T> Response findById(Class<T> clazz, String id) {
+        T item = em.find(clazz, id);
+        if (item == null) {
+            return new Response(false, 600, null);
+        }
+        return new Response(true, 200, item);
+    }
+
     public Response create(Object object) {
         if (!(object instanceof LStatus)) {
             return new Response(false, 602, object);
@@ -59,7 +116,6 @@
         return response;
     }
 
-    @Override
     public Response update(Object object) {
         if (!(object instanceof LStatus)) {
             return new Response(false, 602, object);
@@ -89,9 +145,7 @@
         return response;
     }
 
-    @Override
     public Response delete(Object object) {
-        // TODO Auto-generated method stub
         return null;
     }
 }
--- a/src/main/java/de/intevation/lada/data/LZusatzwertRepository.java	Wed Jul 03 12:21:20 2013 +0200
+++ b/src/main/java/de/intevation/lada/data/LZusatzwertRepository.java	Wed Jul 03 15:54:00 2013 +0200
@@ -1,10 +1,17 @@
 package de.intevation.lada.data;
 
+import java.util.List;
+
 import javax.ejb.EJBTransactionRolledbackException;
+import javax.enterprise.context.ApplicationScoped;
 import javax.inject.Inject;
 import javax.inject.Named;
 import javax.persistence.EntityExistsException;
+import javax.persistence.EntityManager;
 import javax.persistence.TransactionRequiredException;
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Root;
 
 import de.intevation.lada.manage.Manager;
 import de.intevation.lada.model.LZusatzWert;
@@ -17,10 +24,15 @@
  * 
  * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a>
  */
+@ApplicationScoped
 @Named("lzusatzwertrepository")
-public class LZusatzwertRepository
-extends Repository
+public class LZusatzwertRepository implements Repository
 {
+    /**
+     * The entitymanager managing the data.
+     */
+    @Inject
+    private EntityManager em;
 
     /**
      * Manager class for LPRobe. Used to manipulate data objects.
@@ -29,7 +41,51 @@
     @Named("datamanager")
     private Manager manager;
 
-    @Override
+    public EntityManager getEntityManager() {
+        return this.em;
+    }
+    /**
+     * Filter object list by the given criteria.
+     *
+     * @param criteria
+     * @return List of objects.
+     */
+    public <T> Response filter(CriteriaQuery<T> filter) {
+        List<T> result = em.createQuery(filter).getResultList();
+        return new Response(true, 200, result);
+    }
+
+
+    /**
+     * Get all objects of type <link>clazz</link>from database.
+     *
+     * @param clazz The class type.
+     * @return List of objects.
+     */
+    public <T> Response findAll(Class<T> clazz) {
+        CriteriaBuilder builder = em.getCriteriaBuilder();
+        CriteriaQuery<T> criteria = builder.createQuery(clazz);
+        Root<T> member = criteria.from(clazz);
+        criteria.select(member);
+        List<T> result = em.createQuery(criteria).getResultList();
+        return new Response(true, 200, result);
+    }
+
+    /**
+     * Find a single object identified by its id.
+     * 
+     * @param clazz The class type.
+     * @param id The object id.
+     * @return The requested object of type clazz
+     */
+    public <T> Response findById(Class<T> clazz, String id) {
+        T item = em.find(clazz, id);
+        if (item == null) {
+            return new Response(false, 600, null);
+        }
+        return new Response(true, 200, item);
+    }
+
     public Response create(Object object) {
         if (!(object instanceof LZusatzWert)) {
             return new Response(false, 602, object);
@@ -65,7 +121,6 @@
         return response;
     }
 
-    @Override
     public Response update(Object object) {
         if (!(object instanceof LZusatzWert)) {
             return new Response(false, 602, object);
@@ -99,7 +154,6 @@
         return response;
     }
 
-    @Override
     public Response delete(Object object) {
         if (!(object instanceof LZusatzWert)) {
             return new Response(false, 602, null);
--- a/src/main/java/de/intevation/lada/data/OrtRepository.java	Wed Jul 03 12:21:20 2013 +0200
+++ b/src/main/java/de/intevation/lada/data/OrtRepository.java	Wed Jul 03 15:54:00 2013 +0200
@@ -1,24 +1,82 @@
 package de.intevation.lada.data;
 
+import java.util.List;
+
 import javax.ejb.EJBTransactionRolledbackException;
+import javax.enterprise.context.ApplicationScoped;
 import javax.inject.Inject;
 import javax.inject.Named;
 import javax.persistence.EntityExistsException;
+import javax.persistence.EntityManager;
 import javax.persistence.TransactionRequiredException;
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Root;
 
 import de.intevation.lada.manage.Manager;
 import de.intevation.lada.model.Ort;
 import de.intevation.lada.rest.Response;
 
+@ApplicationScoped
 @Named("ortrepository")
-public class OrtRepository
-extends Repository
+public class OrtRepository implements Repository
 {
+    /**
+     * The entitymanager managing the data.
+     */
+    @Inject
+    private EntityManager em;
+
     @Inject
     @Named("datamanager")
     private Manager manager;
 
-    @Override
+    public EntityManager getEntityManager() {
+        return this.em;
+    }
+
+    /**
+     * Filter object list by the given criteria.
+     *
+     * @param criteria
+     * @return List of objects.
+     */
+    public <T> Response filter(CriteriaQuery<T> filter) {
+        List<T> result = em.createQuery(filter).getResultList();
+        return new Response(true, 200, result);
+    }
+
+
+    /**
+     * Get all objects of type <link>clazz</link>from database.
+     *
+     * @param clazz The class type.
+     * @return List of objects.
+     */
+    public <T> Response findAll(Class<T> clazz) {
+        CriteriaBuilder builder = em.getCriteriaBuilder();
+        CriteriaQuery<T> criteria = builder.createQuery(clazz);
+        Root<T> member = criteria.from(clazz);
+        criteria.select(member);
+        List<T> result = em.createQuery(criteria).getResultList();
+        return new Response(true, 200, result);
+    }
+
+    /**
+     * Find a single object identified by its id.
+     * 
+     * @param clazz The class type.
+     * @param id The object id.
+     * @return The requested object of type clazz
+     */
+    public <T> Response findById(Class<T> clazz, String id) {
+        T item = em.find(clazz, id);
+        if (item == null) {
+            return new Response(false, 600, null);
+        }
+        return new Response(true, 200, item);
+    }
+
     public Response create(Object object) {
         if (!(object instanceof Ort)) {
             return new Response(false, 602, object);
@@ -39,7 +97,6 @@
         }
     }
 
-    @Override
     public Response update(Object object) {
         if (!(object instanceof Ort)) {
             return new Response(false, 602, object);
@@ -69,7 +126,6 @@
         return response;
     }
 
-    @Override
     public Response delete(Object object) {
         if (!(object instanceof Ort)) {
             return new Response(false, 602, null);
@@ -89,5 +145,4 @@
         }
         return response;
     }
-
-}
+}
\ No newline at end of file
--- a/src/main/java/de/intevation/lada/data/QueryBuilder.java	Wed Jul 03 12:21:20 2013 +0200
+++ b/src/main/java/de/intevation/lada/data/QueryBuilder.java	Wed Jul 03 15:54:00 2013 +0200
@@ -5,8 +5,6 @@
 import javax.persistence.EntityManager;
 import javax.persistence.criteria.CriteriaBuilder;
 import javax.persistence.criteria.CriteriaQuery;
-import javax.persistence.criteria.Expression;
-import javax.persistence.criteria.Order;
 import javax.persistence.criteria.Predicate;
 import javax.persistence.criteria.Root;
 
@@ -106,7 +104,7 @@
             this.query.orderBy(this.builder.desc(this.root.get(id)));
         }
     }
-    
+
     public QueryBuilder<T> getEmptyBuilder(){
         QueryBuilder<T> copy = new QueryBuilder<T>(manager, clazz);
         copy.builder = this.builder;
--- a/src/main/java/de/intevation/lada/data/ReadOnlyRepository.java	Wed Jul 03 12:21:20 2013 +0200
+++ b/src/main/java/de/intevation/lada/data/ReadOnlyRepository.java	Wed Jul 03 15:54:00 2013 +0200
@@ -1,27 +1,80 @@
 package de.intevation.lada.data;
 
-import javax.enterprise.context.RequestScoped;
+import java.util.List;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
 import javax.inject.Named;
+import javax.persistence.EntityManager;
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Root;
 
 import de.intevation.lada.rest.Response;
 
-@RequestScoped
+@ApplicationScoped
 @Named("readonlyrepository")
-public class ReadOnlyRepository
-extends Repository
+public class ReadOnlyRepository implements Repository
 {
+    /**
+     * The entitymanager managing the data.
+     */
+    @Inject
+    private EntityManager em;
 
-    @Override
+    public EntityManager getEntityManager() {
+        return this.em;
+    }
+
+    /**
+     * Filter object list by the given criteria.
+     *
+     * @param criteria
+     * @return List of objects.
+     */
+    public <T> Response filter(CriteriaQuery<T> filter) {
+        List<T> result = em.createQuery(filter).getResultList();
+        return new Response(true, 200, result);
+    }
+
+    /**
+     * Get all objects of type <link>clazz</link>from database.
+     *
+     * @param clazz The class type.
+     * @return List of objects.
+     */
+    public <T> Response findAll(Class<T> clazz) {
+        CriteriaBuilder builder = em.getCriteriaBuilder();
+        CriteriaQuery<T> criteria = builder.createQuery(clazz);
+        Root<T> member = criteria.from(clazz);
+        criteria.select(member);
+        List<T> result = em.createQuery(criteria).getResultList();
+        return new Response(true, 200, result);
+    }
+
+    /**
+     * Find a single object identified by its id.
+     * 
+     * @param clazz The class type.
+     * @param id The object id.
+     * @return The requested object of type clazz
+     */
+    public <T> Response findById(Class<T> clazz, String id) {
+        T item = em.find(clazz, id);
+        if (item == null) {
+            return new Response(false, 600, null);
+        }
+        return new Response(true, 200, item);
+    }
+
     public Response create(Object object) {
         return null;
     }
 
-    @Override
     public Response update(Object object) {
         return null;
     }
 
-    @Override
     public Response delete(Object object) {
         return null;
     }
--- a/src/main/java/de/intevation/lada/data/Repository.java	Wed Jul 03 12:21:20 2013 +0200
+++ b/src/main/java/de/intevation/lada/data/Repository.java	Wed Jul 03 15:54:00 2013 +0200
@@ -1,13 +1,7 @@
 package de.intevation.lada.data;
 
-import java.util.List;
-
-import javax.enterprise.context.RequestScoped;
-import javax.inject.Inject;
 import javax.persistence.EntityManager;
-import javax.persistence.criteria.CriteriaBuilder;
 import javax.persistence.criteria.CriteriaQuery;
-import javax.persistence.criteria.Root;
 
 import de.intevation.lada.rest.Response;
 
@@ -17,64 +11,19 @@
  * 
  * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a>
  */
-@RequestScoped
-public abstract class Repository
+public interface Repository
 {
-    /**
-     * The entitymanager managing the data.
-     */
-    @Inject
-    private EntityManager em;
-
-    public abstract Response create(Object object);
-
-    public abstract Response update(Object object);
-
-    public abstract Response delete(Object object);
-
-    /**
-     * Filter object list by the given criteria.
-     *
-     * @param criteria
-     * @return List of objects.
-     */
-    public <T> Response filter(CriteriaQuery<T> filter) {
-        List<T> result = em.createQuery(filter).getResultList();
-        return new Response(true, 200, result);
-    }
-
+    public Response create(Object object);
 
-    /**
-     * Get all objects of type <link>clazz</link>from database.
-     *
-     * @param clazz The class type.
-     * @return List of objects.
-     */
-    public <T> Response findAll(Class<T> clazz) {
-        CriteriaBuilder builder = em.getCriteriaBuilder();
-        CriteriaQuery<T> criteria = builder.createQuery(clazz);
-        Root<T> member = criteria.from(clazz);
-        criteria.select(member);
-        List<T> result = em.createQuery(criteria).getResultList();
-        return new Response(true, 200, result);
-    }
+    public Response update(Object object);
 
-    /**
-     * Find a single object identified by its id.
-     * 
-     * @param clazz The class type.
-     * @param id The object id.
-     * @return The requested object of type clazz
-     */
-    public <T> Response findById(Class<T> clazz, String id) {
-        T item = em.find(clazz, id);
-        if (item == null) {
-            return new Response(false, 600, null);
-        }
-        return new Response(true, 200, item);
-    }
+    public Response delete(Object object);
 
-    public EntityManager getEntityManager() {
-        return this.em;
-    }
-}
+    public <T> Response filter(CriteriaQuery<T> filter);
+
+    public <T> Response findAll(Class<T> clazz);
+
+    public <T> Response findById(Class<T> clazz, String id);
+
+    public EntityManager getEntityManager();
+}
\ No newline at end of file
--- a/src/main/java/de/intevation/lada/utils/Resources.java	Wed Jul 03 12:21:20 2013 +0200
+++ b/src/main/java/de/intevation/lada/utils/Resources.java	Wed Jul 03 15:54:00 2013 +0200
@@ -29,7 +29,7 @@
 public class Resources {
 
     @Produces
-    @PersistenceContext
+    @PersistenceContext(unitName = "primary")
     private EntityManager em;
 
     @Produces
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)