db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r1494115 - in /db/derby/code/trunk/java/engine/org/apache/derby: iapi/sql/ impl/sql/execute/
Date Tue, 18 Jun 2013 12:29:59 GMT
Author: rhillegas
Date: Tue Jun 18 12:29:58 2013
New Revision: 1494115

URL: http://svn.apache.org/r1494115
Log:
DERBY-6266: Add ability to print Derby execution ResultSet graph as xml.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/ResultSet.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/BasicNoPutResultSetImpl.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DependentResultSet.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/HashScanResultSet.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/LastIndexKeyResultSet.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/NoRowsResultSetImpl.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/ScanResultSet.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/TableScanResultSet.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/TemporaryRowHolderResultSet.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/ResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/ResultSet.java?rev=1494115&r1=1494114&r2=1494115&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/ResultSet.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/ResultSet.java Tue Jun 18 12:29:58
2013
@@ -29,6 +29,7 @@ import org.apache.derby.iapi.sql.Row;
 
 import java.sql.Timestamp;
 import java.sql.SQLWarning;
+import org.w3c.dom.Element;
 
 /**
  * The ResultSet interface provides a method to tell whether a statement
@@ -347,4 +348,18 @@ public interface ResultSet
 		this result set. The warnings are cleared once this call returns.
 	*/
 	public SQLWarning getWarnings();
+    
+	/**
+	 * <p>
+     * Produce an xml image of this ResultSet and its descendant ResultSets.
+     * Appends an element to the parentNode and returns the appended element.
+     * </p>
+     *
+     * @param   parentNode  Node to put content into.
+     * @param   tag             Element tag for content
+     *
+     * @return  the content as an element with the given tag name
+	 */
+	public Element toXML( Element parentNode, String tag ) throws Exception;
+
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/BasicNoPutResultSetImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/BasicNoPutResultSetImpl.java?rev=1494115&r1=1494114&r2=1494115&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/BasicNoPutResultSetImpl.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/BasicNoPutResultSetImpl.java
Tue Jun 18 12:29:58 2013
@@ -21,8 +21,13 @@
 
 package org.apache.derby.impl.sql.execute;
 
+import java.lang.reflect.Field;
 import java.sql.SQLWarning;
 import java.sql.Timestamp;
+import java.util.Arrays;
+import java.util.ArrayList;
+import java.util.Comparator;
+import org.w3c.dom.Element;
 
 import org.apache.derby.iapi.error.StandardException;
 import org.apache.derby.iapi.reference.SQLState;
@@ -1043,4 +1048,82 @@ implements NoPutResultSet
 		warnings = null;
 		return w;
 	}
+
+    public Element toXML( Element parentNode, String tag ) throws Exception
+    {
+        return childrenToXML( toXML( parentNode, tag, this ), this );
+    }
+
+    /**
+     * <p>
+     * Pretty-print a ResultSet as an xml child of a parent node.
+     * Return the node representing the ResultSet child.
+     * </p>
+     */
+    public  static  Element    toXML( Element parentNode, String childTag, ResultSet rs )
throws Exception
+    {
+        String  childClassName = rs.getClass().getName();
+        String  typeAttribute = childClassName.substring( childClassName.lastIndexOf( "."
) + 1 );
+        Element result = parentNode.getOwnerDocument().createElement( childTag );
+        result.setAttribute( "type", typeAttribute );
+
+        parentNode.appendChild( result );
+        return result;
+    }
+
+    /**
+     * <p>
+     * Pretty-print the inner ResultSet fields inside an outer ResultSet.
+     * Returns the outerNode.
+     * </p>
+     */
+    public  static  Element    childrenToXML
+        ( Element outerNode, ResultSet outerRS ) throws Exception
+    {
+        ArrayList<Field>    fieldList = new ArrayList<Field>();
+        findResultSetFields( fieldList, outerRS.getClass() );
+
+        //
+        // Get a array of all the ResultSet fields inside the outerRS,
+        // ordered by field name.
+        //
+        Field[] fields = new Field[ fieldList.size() ];
+        fieldList.toArray( fields );
+        Arrays.sort( fields, new FieldComparator() );
+
+        // Add those fields as children of the outer element.
+        for ( Field field : fields )
+        {
+            ResultSet   innerRS = (ResultSet) field.get( outerRS );
+
+            if ( innerRS != null) { innerRS.toXML( outerNode, field.getName() ); }
+        }
+
+        return outerNode;
+    }
+
+    /**
+     * <p>
+     * Find all fields of type ResultSet.
+     * </p>
+     */
+    private static  void    findResultSetFields( ArrayList<Field> fieldList, Class<?>
klass )
+        throws Exception
+    {
+        if ( klass == null ) { return; }
+        
+        Field[] fields = klass.getDeclaredFields();
+
+        for ( Field field : fields )
+        {
+            if ( ResultSet.class.isAssignableFrom( field.getType() ) ) { fieldList.add( field
); }
+        }
+
+        findResultSetFields( fieldList, klass.getSuperclass() );
+    }
+
+    public  static  final   class   FieldComparator implements Comparator<Field>
+    {
+        public  int compare( Field left, Field right ) { return left.getName().compareTo(
right.getName() ); }
+    }
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DependentResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DependentResultSet.java?rev=1494115&r1=1494114&r2=1494115&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DependentResultSet.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DependentResultSet.java
Tue Jun 18 12:29:58 2013
@@ -23,6 +23,7 @@ package org.apache.derby.impl.sql.execut
 
 import java.util.Properties;
 import java.util.Vector;
+import org.w3c.dom.Element;
 
 import org.apache.derby.iapi.error.StandardException;
 import org.apache.derby.iapi.reference.SQLState;
@@ -94,9 +95,7 @@ class DependentResultSet extends ScanRes
 	protected int startSearchOperator;
 	protected int stopSearchOperator;
 	protected Qualifier[][] qualifiers;
-	public String tableName;
 	public String userSuppliedOptimizerOverrides;
-	public String indexName;
 	protected boolean runTimeStatisticsOn;
 	public int rowsPerRead;
 	public boolean forUpdate;
@@ -693,6 +692,7 @@ class DependentResultSet extends ScanRes
 		String idt = "";
 		return idt + MessageService.getTextMessage(SQLState.LANG_NONE);
 	}
+
 }
 
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/HashScanResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/HashScanResultSet.java?rev=1494115&r1=1494114&r2=1494115&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/HashScanResultSet.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/HashScanResultSet.java
Tue Jun 18 12:29:58 2013
@@ -82,9 +82,7 @@ public class HashScanResultSet extends S
 	private int initialCapacity;
 	private float loadFactor;
 	private int maxCapacity;
-	public String tableName;
 	public String userSuppliedOptimizerOverrides;
-	public String indexName;
 	public boolean forUpdate;
 	private boolean runTimeStatisticsOn;
 	public int[] keyColumns;

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/LastIndexKeyResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/LastIndexKeyResultSet.java?rev=1494115&r1=1494114&r2=1494115&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/LastIndexKeyResultSet.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/LastIndexKeyResultSet.java
Tue Jun 18 12:29:58 2013
@@ -43,9 +43,7 @@ class LastIndexKeyResultSet extends Scan
 	protected int startSearchOperator;
 	protected int stopSearchOperator;
 	protected Qualifier[][] qualifiers;
-	public String tableName;
 	public String userSuppliedOptimizerOverrides;
-	public String indexName;
 	protected boolean runTimeStatisticsOn;
 
 	// Run time statistics

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/NoRowsResultSetImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/NoRowsResultSetImpl.java?rev=1494115&r1=1494114&r2=1494115&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/NoRowsResultSetImpl.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/NoRowsResultSetImpl.java
Tue Jun 18 12:29:58 2013
@@ -23,6 +23,7 @@ package org.apache.derby.impl.sql.execut
 
 import java.sql.SQLWarning;
 import java.sql.Timestamp;
+import org.w3c.dom.Element;
 
 import org.apache.derby.iapi.error.StandardException;
 import org.apache.derby.iapi.reference.SQLState;
@@ -766,4 +767,9 @@ abstract class NoRowsResultSetImpl imple
 		return null;
 	}
 
+    public Element toXML( Element parentNode, String tag ) throws Exception
+    {
+        return BasicNoPutResultSetImpl.childrenToXML( BasicNoPutResultSetImpl.toXML( parentNode,
tag, this ), this );
+    }
+
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/ScanResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/ScanResultSet.java?rev=1494115&r1=1494114&r2=1494115&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/ScanResultSet.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/ScanResultSet.java Tue
Jun 18 12:29:58 2013
@@ -19,6 +19,8 @@
 
 package org.apache.derby.impl.sql.execute;
 
+import org.w3c.dom.Element;
+
 import org.apache.derby.iapi.error.StandardException;
 import org.apache.derby.iapi.services.io.FormatableBitSet;
 import org.apache.derby.iapi.services.sanity.SanityManager;
@@ -88,6 +90,9 @@ abstract class ScanResultSet extends NoP
      */
     protected final FormatableBitSet accessedCols;
 
+	public String tableName;
+	public String indexName;
+
     /**
      * Construct a <code>ScanResultSet</code>.
      *
@@ -245,4 +250,13 @@ abstract class ScanResultSet extends NoP
         candidate.resetRowArray();
         super.close();
     }
+    
+    public Element toXML( Element parentNode, String tag ) throws Exception
+    {
+        Element myNode = super.toXML( parentNode, tag );
+        if ( tableName != null ) { myNode.setAttribute( "tableName", tableName ); }
+        if ( indexName != null ) { myNode.setAttribute( "indexName", indexName ); }
+        
+        return myNode;
+    }
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/TableScanResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/TableScanResultSet.java?rev=1494115&r1=1494114&r2=1494115&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/TableScanResultSet.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/TableScanResultSet.java
Tue Jun 18 12:29:58 2013
@@ -72,9 +72,7 @@ class TableScanResultSet extends ScanRes
 	protected GeneratedMethod stopKeyGetter;
 	protected int stopSearchOperator;
 	public    Qualifier[][] qualifiers;
-	public String tableName;
 	public String userSuppliedOptimizerOverrides;
-	public String indexName;
 	protected boolean runTimeStatisticsOn;
     protected int[] indexCols;		//index keys base column position array
 	public int rowsPerRead;

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/TemporaryRowHolderResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/TemporaryRowHolderResultSet.java?rev=1494115&r1=1494114&r2=1494115&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/TemporaryRowHolderResultSet.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/TemporaryRowHolderResultSet.java
Tue Jun 18 12:29:58 2013
@@ -23,6 +23,7 @@ package org.apache.derby.impl.sql.execut
 
 import java.sql.SQLWarning;
 import java.sql.Timestamp;
+import org.w3c.dom.Element;
 
 import org.apache.derby.iapi.error.StandardException;
 import org.apache.derby.iapi.services.io.FormatableBitSet;
@@ -1349,4 +1350,10 @@ class TemporaryRowHolderResultSet implem
 	public final Activation getActivation() {
 		return holder.activation;
 	}
+    
+    public Element toXML( Element parentNode, String tag ) throws Exception
+    {
+        return BasicNoPutResultSetImpl.childrenToXML( BasicNoPutResultSetImpl.toXML( parentNode,
tag, this ), this );
+    }
+
 }



Mime
View raw message