[Lada-commits] [PATCH 04 of 10] Added methods to get plain objects

Wald Commits scm-commit at wald.intevation.org
Thu Nov 12 12:20:12 CET 2015


# HG changeset patch
# User Raimund Renkert <raimund.renkert at intevation.de>
# Date 1447326731 -3600
# Node ID d49ac8d5f3f79915ea45186af0cc7ef079b956a1
# Parent  00c44ac5ca9c56b00691f9ff6c16c94763df6ae3
Added methods to get plain objects.

diff -r 00c44ac5ca9c -r d49ac8d5f3f7 src/main/java/de/intevation/lada/util/data/ReadOnlyRepository.java
--- 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);
+    }
 }
diff -r 00c44ac5ca9c -r d49ac8d5f3f7 src/main/java/de/intevation/lada/util/data/Repository.java
--- 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);


More information about the Lada-commits mailing list