changeset 6402:da1d1df9ab23

Datacage: Stop execution of dc:container-context earlier if there are nor results at all.
author Sascha L. Teichmann <teichmann@intevation.de>
date Sat, 22 Jun 2013 00:13:52 +0200
parents f369d69e3488
children 2d538e01da7c
files artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/Builder.java
diffstat 1 files changed, 21 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/Builder.java	Sat Jun 22 00:03:18 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/Builder.java	Sat Jun 22 00:13:52 2013 +0200
@@ -269,6 +269,13 @@
                 return;
             }
 
+            Collection<?> collection = (Collection<?>)c;
+
+            // only descent if there are results
+            if (collection.isEmpty()) {
+                return;
+            }
+
             String [] columnNames = new String[properties.length];
             for (int i = 0; i < columnNames.length; ++i) {
                 columnNames[i] = properties[i][1];
@@ -276,7 +283,7 @@
 
             ResultData rd = new ResultData(columnNames);
 
-            for (Object obj: (Collection<?>)c) {
+            for (Object obj: collection) {
                 Object [] row = new Object[properties.length];
                 for (int i = 0; i < properties.length; ++i) {
                     row[i] = getProperty(obj, properties[i][0]);
@@ -284,24 +291,21 @@
                 rd.add(row);
             }
 
-            // only descent if there are results
-            if (!rd.isEmpty()) {
-                // A bit of a fake because the data is not from a
-                // real connection.
-                NamedConnection connection = connectionsStack.isEmpty()
-                    ? connections.get(0)
-                    : connectionsStack.peek().getA();
+            // A bit of a fake because the data is not from a
+            // real connection.
+            NamedConnection connection = connectionsStack.isEmpty()
+                ? connections.get(0)
+                : connectionsStack.peek().getA();
 
-                connectionsStack.push(
-                    new Pair<NamedConnection, ResultData>(connection, rd));
-                try {
-                    for (int i = 0, S = subs.getLength(); i < S; ++i) {
-                        build(parent, subs.item(i));
-                    }
+            connectionsStack.push(
+                new Pair<NamedConnection, ResultData>(connection, rd));
+            try {
+                for (int i = 0, S = subs.getLength(); i < S; ++i) {
+                    build(parent, subs.item(i));
                 }
-                finally {
-                    connectionsStack.pop();
-                }
+            }
+            finally {
+                connectionsStack.pop();
             }
         }
 

http://dive4elements.wald.intevation.org