changeset 770:d49ac8d5f3f7

Added methods to get plain objects.
author Raimund Renkert <raimund.renkert@intevation.de>
date Thu, 12 Nov 2015 12:12:11 +0100
parents 00c44ac5ca9c
children 244c54d16957
files src/main/java/de/intevation/lada/util/data/ReadOnlyRepository.java src/main/java/de/intevation/lada/util/data/Repository.java
diffstat 2 files changed, 43 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/de/intevation/lada/util/data/ReadOnlyRepository.java	Thu Nov 12 12:11:43 2015 +0100
+++ b/src/main/java/de/intevation/lada/util/data/ReadOnlyRepository.java	Thu Nov 12 12:12:11 2015 +0100
@@ -151,4 +151,33 @@
     public EntityManager entityManager(String dataSource) {
         return transaction.entityManager(dataSource);
     }
+
+    @Override
+    public <T> List<T> filterPlain(CriteriaQuery<T> filter, String dataSource) {
+        return transaction.entityManager(dataSource).createQuery(filter).getResultList();
+    }
+
+    @Override
+    public <T> List<T> filterPlain(CriteriaQuery<T> filter, int size,
+            int start, String dataSource) {
+        List<T> result =
+            transaction.entityManager(dataSource).createQuery(filter).getResultList();
+        if (size > 0 && start > -1) {
+            return result.subList(start, size + start);
+        }
+        return result;
+    }
+
+    @Override
+    public <T> List<T> getAllPlain(Class<T> clazz, String dataSource) {
+        EntityManager manager = transaction.entityManager(dataSource);
+        QueryBuilder<T> builder =
+            new QueryBuilder<T>(manager, clazz);
+        return manager.createQuery(builder.getQuery()).getResultList();
+    }
+
+    @Override
+    public <T> T getByIdPlain(Class<T> clazz, Object id, String dataSource) {
+        return transaction.entityManager(dataSource).find(clazz, id);
+    }
 }
--- a/src/main/java/de/intevation/lada/util/data/Repository.java	Thu Nov 12 12:11:43 2015 +0100
+++ b/src/main/java/de/intevation/lada/util/data/Repository.java	Thu Nov 12 12:12:11 2015 +0100
@@ -7,6 +7,8 @@
  */
 package de.intevation.lada.util.data;
 
+import java.util.List;
+
 import javax.persistence.EntityManager;
 import javax.persistence.Query;
 import javax.persistence.criteria.CriteriaQuery;
@@ -29,16 +31,28 @@
 
     public <T> Response filter(CriteriaQuery<T> filter, String dataSource);
 
+    public <T> List<T> filterPlain(CriteriaQuery<T> filter, String dataSource);
+
     public <T> Response filter(
         CriteriaQuery<T> filter,
         int size,
         int start,
         String dataSource);
 
+    public <T> List<T> filterPlain(
+        CriteriaQuery<T> filter,
+        int size,
+        int start,
+        String dataSource);
+
     public <T> Response getAll(Class<T> clazz, String dataSource);
 
+    public <T> List<T> getAllPlain(Class<T> clazz, String dataSource);
+
     public <T> Response getById(Class<T> clazz, Object id, String dataSource);
 
+    public <T> T getByIdPlain(Class<T> clazz, Object id, String dataSource);
+
     public Query queryFromString(String sql, String dataSource);
 
     public EntityManager entityManager(String dataSource);
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)