[Dive4elements-commits] [PATCH] Datacage: Stop execution of dc:container-context earlier if there are nor results at all

Wald Commits scm-commit at wald.intevation.org
Sat Jun 22 00:14:01 CEST 2013


# HG changeset patch
# User Sascha L. Teichmann <teichmann at intevation.de>
# Date 1371852832 -7200
# Node ID da1d1df9ab23e58c76739a6cbf22494732af1f71
# Parent  f369d69e34888a03b5622afb01a7376e67c7d634
Datacage: Stop execution of dc:container-context earlier if there are nor results at all.

diff -r f369d69e3488 -r da1d1df9ab23 artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/Builder.java
--- 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();
             }
         }
 


More information about the Dive4elements-commits mailing list