changeset 1214:6e6134bf1d6d

Avoid fetching the whole table from DB if we don't need it at all.
author Tom Gottfried <tom@intevation.de>
date Thu, 08 Dec 2016 14:59:02 +0100
parents aed3332cfacc
children 6e393b614edf
files src/main/java/de/intevation/lada/rest/stamm/OrtService.java
diffstat 1 files changed, 6 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/de/intevation/lada/rest/stamm/OrtService.java	Thu Dec 08 14:47:21 2016 +0100
+++ b/src/main/java/de/intevation/lada/rest/stamm/OrtService.java	Thu Dec 08 14:59:02 2016 +0100
@@ -8,6 +8,7 @@
 package de.intevation.lada.rest.stamm;
 
 import java.util.List;
+import java.util.ArrayList;
 
 import javax.enterprise.context.RequestScoped;
 import javax.inject.Inject;
@@ -112,7 +113,6 @@
         @Context UriInfo info
     ) {
         MultivaluedMap<String, String> params = info.getQueryParameters();
-        List<Ort> orte = repository.getAllPlain(Ort.class, "stamm");
         if (params.containsKey("ortId")) {
             Integer id;
             try {
@@ -131,6 +131,8 @@
                     Ort.class));
             return new Response(true, 200, o);
         }
+
+        List<Ort> orte = new ArrayList<Ort>();
         if (params.containsKey("qid")) {
             Integer id = null;
             try {
@@ -169,6 +171,9 @@
 
             orte = repository.filterPlain(builder.getQuery(), "stamm");
         }
+        else {
+            orte = repository.getAllPlain(Ort.class, "stamm");
+        }
 
         int size = orte.size();
         if (params.containsKey("start") && params.containsKey("limit")) {
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)