[teiid-commits] teiid SVN: r2086 - in trunk/client/src: test/java/org/teiid/client/plan and 1 other directory.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Fri Apr 30 10:22:37 EDT 2010


Author: shawkins
Date: 2010-04-30 10:22:36 -0400 (Fri, 30 Apr 2010)
New Revision: 2086

Modified:
   trunk/client/src/main/java/org/teiid/client/plan/PlanNode.java
   trunk/client/src/test/java/org/teiid/client/plan/TestPlanNode.java
Log:
TEIID-908 fixing issue with an empty property list and adding javadocs

Modified: trunk/client/src/main/java/org/teiid/client/plan/PlanNode.java
===================================================================
--- trunk/client/src/main/java/org/teiid/client/plan/PlanNode.java	2010-04-28 18:35:59 UTC (rev 2085)
+++ trunk/client/src/main/java/org/teiid/client/plan/PlanNode.java	2010-04-30 14:22:36 UTC (rev 2086)
@@ -28,6 +28,7 @@
 import java.io.ObjectOutput;
 import java.io.StringWriter;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.LinkedList;
 import java.util.List;
 
@@ -41,10 +42,20 @@
 
 import com.metamatrix.core.util.ExternalizeUtil;
 
+/**
+ * A PlanNode represents part of processing plan tree.  For relational plans 
+ * child PlanNodes may be either subqueries or nodes that feed tuples into the
+ * parent. For procedure plans child PlanNodes will be processing instructions,
+ * which can in turn contain other relational or procedure plans.
+ */
 @XmlType
 @XmlRootElement(name="node")
 public class PlanNode implements Externalizable {
 
+	/**
+	 * A Property is a named value of a {@link PlanNode} that may be
+	 * another {@link PlanNode} or a non-null list of values.
+	 */
 	@XmlType(name = "property")
 	public static class Property implements Externalizable {
 		@XmlAttribute
@@ -138,6 +149,9 @@
     
     public void addProperty(String pname, List<String> value) {
     	Property p = new Property(pname);
+    	if (value == null) {
+    		value = Collections.emptyList();
+    	}
     	p.setValues(value);
     	this.properties.add(p);
     }
@@ -148,6 +162,11 @@
     	this.properties.add(p);
     }
     
+    /**
+     * Converts this PlanNode to XML. See the JAXB bindings for the
+     * document form.
+     * @return an XML document of this PlanNode
+     */
     public String toXml() throws JAXBException {
     	JAXBContext jc = JAXBContext.newInstance(new Class<?>[] {PlanNode.class});
 		Marshaller marshaller = jc.createMarshaller();
@@ -164,9 +183,6 @@
     	return builder.toString();
     }
     
-    /* 
-     * @see com.metamatrix.jdbc.plan.PlanVisitor#visitNode(com.metamatrix.jdbc.plan.PlanNode)
-     */
     protected void visitNode(PlanNode node, int nodeLevel, StringBuilder text) {
         for(int i=0; i<nodeLevel; i++) {
             text.append("  "); //$NON-NLS-1$
@@ -203,10 +219,12 @@
             	text.append(p.getValues().get(i));
                 text.append("\n"); //$NON-NLS-1$
 			}
-        } else {
+        } else if (p.getValues().size() == 1) {
         	text.append(":"); //$NON-NLS-1$
         	text.append(p.getValues().get(0));
         	text.append("\n"); //$NON-NLS-1$
+        } else {
+        	text.append("\n"); //$NON-NLS-1$
         }
     }
     

Modified: trunk/client/src/test/java/org/teiid/client/plan/TestPlanNode.java
===================================================================
--- trunk/client/src/test/java/org/teiid/client/plan/TestPlanNode.java	2010-04-28 18:35:59 UTC (rev 2085)
+++ trunk/client/src/test/java/org/teiid/client/plan/TestPlanNode.java	2010-04-30 14:22:36 UTC (rev 2086)
@@ -23,6 +23,7 @@
 package org.teiid.client.plan;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 
 import junit.framework.TestCase;
@@ -55,17 +56,17 @@
         List<String> crits = new ArrayList<String>();
         crits.add("Item.ID = History.ID"); //$NON-NLS-1$
         child.addProperty("Criteria", crits); //$NON-NLS-1$
-        
+        child.addProperty("Other", new ArrayList<String>()); //$NON-NLS-1$
         map.addProperty("child", child); //$NON-NLS-1$
         return map;
     }
 
     public void testXml() throws Exception {
-        assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<node name=\"x\">\n    <property name=\"test\">\n        <value></value>\n    </property>\n    <property name=\"string\">\n        <value>string</value>\n    </property>\n    <property name=\"list&lt;string&gt;\">\n        <value>item1</value>\n        <value>item2</value>\n        <value>item3</value>\n    </property>\n    <property name=\"child\">\n        <node name=\"y\">\n            <property name=\"outputCols\">\n                <value>Name (string)</value>\n                <value>Year (integer)</value>\n            </property>\n            <property name=\"Join Type\">\n                <value>INNER JOIN</value>\n            </property>\n            <property name=\"Criteria\">\n                <value>Item.ID = History.ID</value>\n            </property>\n        </node>\n    </property>\n</node>\n", example1().toXml()); //$NON-NLS-1$
+        assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<node name=\"x\">\n    <property name=\"test\">\n        <value></value>\n    </property>\n    <property name=\"string\">\n        <value>string</value>\n    </property>\n    <property name=\"list&lt;string&gt;\">\n        <value>item1</value>\n        <value>item2</value>\n        <value>item3</value>\n    </property>\n    <property name=\"child\">\n        <node name=\"y\">\n            <property name=\"outputCols\">\n                <value>Name (string)</value>\n                <value>Year (integer)</value>\n            </property>\n            <property name=\"Join Type\">\n                <value>INNER JOIN</value>\n            </property>\n            <property name=\"Criteria\">\n                <value>Item.ID = History.ID</value>\n            </property>\n            <property name=\"Other\"/>\n        </node>\n    </property>\n</node>\n", example1().toXml()); //$NON-NLS-1$
     }
 
     public void testText() throws Exception {
-        assertEquals("x\n  + test:\n  + string:string\n  + list<string>:\n    0: item1\n    1: item2\n    2: item3\n  + child:\n    y\n      + outputCols:\n        0: Name (string)\n        1: Year (integer)\n      + Join Type:INNER JOIN\n      + Criteria:Item.ID = History.ID\n", example1().toString()); //$NON-NLS-1$
+        assertEquals("x\n  + test:\n  + string:string\n  + list<string>:\n    0: item1\n    1: item2\n    2: item3\n  + child:\n    y\n      + outputCols:\n        0: Name (string)\n        1: Year (integer)\n      + Join Type:INNER JOIN\n      + Criteria:Item.ID = History.ID\n      + Other\n", example1().toString()); //$NON-NLS-1$
     }
     
 }



More information about the teiid-commits mailing list