You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by jo...@apache.org on 2001/04/19 01:24:54 UTC

cvs commit: xml-xalan/java/src/org/apache/xalan/lib/sql Column.java ColumnAttribute.java ColumnData.java ColumnHeader.java Row.java RowSet.java StreamableNode.java XConnection.java XStatement.java

johng       01/04/18 16:24:53

  Modified:    java/src/org/apache/xalan/lib/sql Column.java
                        ColumnAttribute.java ColumnData.java
                        ColumnHeader.java Row.java RowSet.java
                        StreamableNode.java XConnection.java
                        XStatement.java
  Log:
  Support for Streamable Mode- John Gentilin
  
  Revision  Changes    Path
  1.6       +15 -11    xml-xalan/java/src/org/apache/xalan/lib/sql/Column.java
  
  Index: Column.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/lib/sql/Column.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Column.java	2001/02/21 14:05:41	1.5
  +++ Column.java	2001/04/18 23:24:49	1.6
  @@ -2,7 +2,7 @@
    * The Apache Software License, Version 1.1
    *
    *
  - * Copyright (c) 1999 The Apache Software Foundation.  All rights 
  + * Copyright (c) 1999 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -10,7 +10,7 @@
    * are met:
    *
    * 1. Redistributions of source code must retain the above copyright
  - *    notice, this list of conditions and the following disclaimer. 
  + *    notice, this list of conditions and the following disclaimer.
    *
    * 2. Redistributions in binary form must reproduce the above copyright
    *    notice, this list of conditions and the following disclaimer in
  @@ -18,7 +18,7 @@
    *    distribution.
    *
    * 3. The end-user documentation included with the redistribution,
  - *    if any, must include the following acknowledgment:  
  + *    if any, must include the following acknowledgment:
    *       "This product includes software developed by the
    *        Apache Software Foundation (http://www.apache.org/)."
    *    Alternately, this acknowledgment may appear in the software itself,
  @@ -26,7 +26,7 @@
    *
    * 4. The names "Xalan" and "Apache Software Foundation" must
    *    not be used to endorse or promote products derived from this
  - *    software without prior written permission. For written 
  + *    software without prior written permission. For written
    *    permission, please contact apache@apache.org.
    *
    * 5. Products derived from this software may not be called "Apache",
  @@ -64,6 +64,7 @@
   import java.sql.ResultSet;
   import java.sql.ResultSetMetaData;
   
  +
   /**
    * <meta name="usage" content="experimental"/>
    * Represents a col node from a row node.
  @@ -81,7 +82,7 @@
     private static final boolean DEBUG = false;
   
     /** Column data          */
  -  ColumnData m_text;
  +  ColumnData m_text = null;
   
     /**
      * Constructor Column
  @@ -93,14 +94,18 @@
      * @param metadata Meta data (column header).
      */
     public Column(XStatement statement, Row parent, int columnIndex,
  -                ResultSetMetaData metadata)
  +                ResultSetMetaData metadata, ResultSet resultSet)
     {
   
       super(statement);
   
       m_columnIndex = columnIndex;
       m_parent = parent;
  -    m_text = null;
  +
  +    // Get the column data right away so it is not lost when
  +    // streamable mode is turned off.
  +    // JCG 4/1/2001
  +    m_text = new ColumnData(statement, this, resultSet);
     }
   
     /**
  @@ -127,16 +132,15 @@
      * Return the col text node (the column value).
      *
      * @return the column value
  +   * @throws Exception, Let all errors be handled by the XConnection
      */
     public Node getFirstChild()
  +    throws DOMException
     {
   
       if (DEBUG)
         System.out.println("In Column.getFirstChild");
   
  -    if (null == m_text)
  -      m_text = new ColumnData(this.getXStatement(), this);
  -
       return m_text;
     }
   
  @@ -159,7 +163,7 @@
     /**
      * The parent node of col is a row.
      *
  -   * @return The parent node of this column 
  +   * @return The parent node of this column
      */
     public Node getParentNode()
     {
  
  
  
  1.9       +16 -8     xml-xalan/java/src/org/apache/xalan/lib/sql/ColumnAttribute.java
  
  Index: ColumnAttribute.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/lib/sql/ColumnAttribute.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- ColumnAttribute.java	2001/02/21 14:05:41	1.8
  +++ ColumnAttribute.java	2001/04/18 23:24:49	1.9
  @@ -2,7 +2,7 @@
    * The Apache Software License, Version 1.1
    *
    *
  - * Copyright (c) 1999 The Apache Software Foundation.  All rights 
  + * Copyright (c) 1999 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -10,7 +10,7 @@
    * are met:
    *
    * 1. Redistributions of source code must retain the above copyright
  - *    notice, this list of conditions and the following disclaimer. 
  + *    notice, this list of conditions and the following disclaimer.
    *
    * 2. Redistributions in binary form must reproduce the above copyright
    *    notice, this list of conditions and the following disclaimer in
  @@ -18,7 +18,7 @@
    *    distribution.
    *
    * 3. The end-user documentation included with the redistribution,
  - *    if any, must include the following acknowledgment:  
  + *    if any, must include the following acknowledgment:
    *       "This product includes software developed by the
    *        Apache Software Foundation (http://www.apache.org/)."
    *    Alternately, this acknowledgment may appear in the software itself,
  @@ -26,7 +26,7 @@
    *
    * 4. The names "Xalan" and "Apache Software Foundation" must
    *    not be used to endorse or promote products derived from this
  - *    software without prior written permission. For written 
  + *    software without prior written permission. For written
    *    permission, please contact apache@apache.org.
    *
    * 5. Products derived from this software may not be called "Apache",
  @@ -69,6 +69,8 @@
   
   import org.apache.xalan.res.XSLTErrorResources;
   
  +
  +
   /**
    * <meta name="usage" content="experimental"/>
    * Represents a column attribute on a column-header element.
  @@ -380,7 +382,7 @@
     }
   
     /**
  -   * Return Specified 
  +   * Return Specified
      *
      *
      * @return true
  @@ -402,7 +404,7 @@
     }
   
     /**
  -   * Return column value 
  +   * Return column value
      *
      *
      * @return column value
  @@ -458,6 +460,12 @@
       {
         return "SQL ERROR!";
       }
  +    catch(Exception e)
  +    {
  +      // Catch all other execptions also
  +      // JCG 4/1/2001
  +      return "Attribute Not Supported";
  +    }
     }
   
     /**
  @@ -485,7 +493,7 @@
     }
   
     /**
  -   * Get parent node 
  +   * Get parent node
      *
      *
      * @return null
  @@ -498,7 +506,7 @@
     /**
      * Return Node.ATTRIBUTE_NODE.
      *
  -   * @return ATTRIBUTE_NODE type 
  +   * @return ATTRIBUTE_NODE type
      */
     public short getNodeType()
     {
  
  
  
  1.7       +68 -90    xml-xalan/java/src/org/apache/xalan/lib/sql/ColumnData.java
  
  Index: ColumnData.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/lib/sql/ColumnData.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ColumnData.java	2001/02/21 14:05:41	1.6
  +++ ColumnData.java	2001/04/18 23:24:50	1.7
  @@ -2,7 +2,7 @@
    * The Apache Software License, Version 1.1
    *
    *
  - * Copyright (c) 1999 The Apache Software Foundation.  All rights 
  + * Copyright (c) 1999 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -10,7 +10,7 @@
    * are met:
    *
    * 1. Redistributions of source code must retain the above copyright
  - *    notice, this list of conditions and the following disclaimer. 
  + *    notice, this list of conditions and the following disclaimer.
    *
    * 2. Redistributions in binary form must reproduce the above copyright
    *    notice, this list of conditions and the following disclaimer in
  @@ -18,7 +18,7 @@
    *    distribution.
    *
    * 3. The end-user documentation included with the redistribution,
  - *    if any, must include the following acknowledgment:  
  + *    if any, must include the following acknowledgment:
    *       "This product includes software developed by the
    *        Apache Software Foundation (http://www.apache.org/)."
    *    Alternately, this acknowledgment may appear in the software itself,
  @@ -26,7 +26,7 @@
    *
    * 4. The names "Xalan" and "Apache Software Foundation" must
    *    not be used to endorse or promote products derived from this
  - *    software without prior written permission. For written 
  + *    software without prior written permission. For written
    *    permission, please contact apache@apache.org.
    *
    * 5. Products derived from this software may not be called "Apache",
  @@ -75,8 +75,15 @@
   {
   
     /** The column for which this is the data          */
  -  Column m_parent;
  +  Column  m_parent;
   
  +  /**
  +   * The value of this Column, this value is set inside the
  +   * constructor
  +   */
  +  String  m_Data;
  +
  +
     /** Flag for debug mode         */
     private static final boolean DEBUG = false;
   
  @@ -86,13 +93,36 @@
      *
      * @param statement Owning document
      * @param parent Owning column
  +   * @throws SQLException, make the Column Class deal with the problem
  +   *
      */
  -  public ColumnData(XStatement statement, Column parent)
  +  public ColumnData(XStatement statement, Column parent, ResultSet resultSet)
     {
   
       super(statement);
  -
       m_parent = parent;
  +
  +    try
  +    {
  +      int columnIndex = m_parent.m_columnIndex;
  +
  +      if (DEBUG)
  +          System.out.println("In ColumnData.constructor, columnIndex: "
  +                           + columnIndex);
  +
  +
  +      if (columnIndex < m_parent.m_parent.m_childCount)
  +      {
  +        m_Data = resultSet.getString(columnIndex + 1);
  +      }
  +    }
  +    catch(SQLException e)
  +    {
  +      m_Data = null;
  +    }
  +
  +    // Always make the column Data equal a valid value
  +    if (null == m_Data) m_Data = "";
     }
   
     /**
  @@ -105,60 +135,23 @@
       return Node.TEXT_NODE;
     }
   
  -  /**
  -   * splitText - not supported
  -   *
  -   *
  -   * @param offset Offset where to split text
  -   *
  -   * @return null
  -   *
  -   * @throws DOMException
  -   */
  -  public Text splitText(int offset) throws DOMException
  -  {
  -
  -    error(XSLTErrorResources.ER_FUNCTION_NOT_SUPPORTED);
  -
  -    return null;
  -  }
   
     /**
  -   * Return the value for this col element text node. I.e., return a String representation
  +   * Return the value for this col element text node.
  +   * I.e., return a String representation
      * of the data for this column in the current row.
      *
      * @return the data for this column
      *
  -   * @throws DOMException
      */
  -  public String getData() throws DOMException
  +  public String getData()
     {
  -
  -    try
  -    {
  -      ResultSet rs = this.getXStatement().getResultSet();
  -      int columnIndex = m_parent.m_columnIndex;
  -
  -      if (DEBUG)
  -        System.out.println("In ColumnData.getData, columnIndex: "
  -                           + columnIndex);
  -
  -      if (columnIndex < m_parent.m_parent.m_childCount)
  -      {
  -        String s = rs.getString(columnIndex + 1);
  -        return (null != s) ? s : "";
  -      }
  -      else
  -        return "";
  -    }
  -    catch (SQLException sqle)
  -    {
  -      return "";
  -    }
  +    return m_Data;
     }
   
     /**
  -   * Return the value for this col element text node. I.e., return a String representation
  +   * Return the value for this col element text node.
  +   * I.e., return a String representation
      * of the data for this column in the current row.
      * Calls @link #getNodeValue() getNodeValue()}.
      *
  @@ -179,98 +172,83 @@
      *
      * @return Number of characters in data
      */
  +
     public int getLength()
     {
  -
  -    String s = getData();
  -
  -    return (null != s) ? s.length() : 0;
  +    return m_Data.length();
     }
   
     /**
  -   * substringData - Not supported.
      *
  +   * substringData
  +   *
      * @param offset Starting offset of substring
  -   * @param count Number of characters isn substring 
  +   * @param count Number of characters in substring
      *
  -   * @return null
  +   * @return String
      *
  -   * @throws DOMException
      */
  -  public String substringData(int offset, int count) throws DOMException
  +  public String substringData(int offset, int count)
     {
  -
  -    error(XSLTErrorResources.ER_FUNCTION_NOT_SUPPORTED);
  -
  -    return null;
  +    return m_Data.substring(offset, offset+count);
     }
   
     /**
  -   * Not supported.
  +   * Append Data to the Column Data
      *
  -   * @param arg
  +   * @param arg String data to append
      *
  -   * @throws DOMException
      */
  -  public void appendData(String arg) throws DOMException
  +  public void appendData(String arg)
     {
  -    error(XSLTErrorResources.ER_FUNCTION_NOT_SUPPORTED);
  +    StringBuffer s = new StringBuffer(m_Data);
  +    s.append(arg);
  +    m_Data = s.toString();
     }
   
     /**
  -   * Not supported.
      *
  +   * Insert data into the Column Data
  +   *
      * @param offset
      * @param arg
      *
  -   * @throws DOMException
      */
  -  public void insertData(int offset, String arg) throws DOMException
  +  public void insertData(int offset, String arg)
     {
  -    error(XSLTErrorResources.ER_FUNCTION_NOT_SUPPORTED);
  +    StringBuffer s = new StringBuffer(m_Data);
  +    s.insert(offset, arg.getBytes());
  +    m_Data = s.toString();
     }
   
     /**
  -   * Not supported.
  +   * Delete Content from the Column Data
      *
      * @param offset
      * @param count
      *
  -   * @throws DOMException
      */
  -  public void deleteData(int offset, int count) throws DOMException
  +  public void deleteData(int offset, int count)
     {
  -    error(XSLTErrorResources.ER_FUNCTION_NOT_SUPPORTED);
     }
   
     /**
  -   * Not supported.
  -   *
      * @param offset
      * @param count
      * @param arg
      *
  -   * @throws DOMException
      */
  -  public void replaceData(int offset, int count, String arg)
  -          throws DOMException
  +  public void replaceData(int start, int rSize, String str)
     {
  -    error(XSLTErrorResources.ER_FUNCTION_NOT_SUPPORTED);
     }
   
     /**
  -   * Not supported.
  -   *
      * @param data
      *
  -   * @throws DOMException
      */
  -  public void setData(String data) throws DOMException
  +  public void setData(String data)
     {
  -
  -    // TODO: It would be cool to make this callable, to set 
  -    // a value in the database.
  -    error(XSLTErrorResources.ER_FUNCTION_NOT_SUPPORTED);
  +    m_Data = data;
     }
   
     /**
  
  
  
  1.7       +27 -34    xml-xalan/java/src/org/apache/xalan/lib/sql/ColumnHeader.java
  
  Index: ColumnHeader.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/lib/sql/ColumnHeader.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ColumnHeader.java	2001/02/21 14:05:41	1.6
  +++ ColumnHeader.java	2001/04/18 23:24:50	1.7
  @@ -2,7 +2,7 @@
    * The Apache Software License, Version 1.1
    *
    *
  - * Copyright (c) 1999 The Apache Software Foundation.  All rights 
  + * Copyright (c) 1999 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -10,7 +10,7 @@
    * are met:
    *
    * 1. Redistributions of source code must retain the above copyright
  - *    notice, this list of conditions and the following disclaimer. 
  + *    notice, this list of conditions and the following disclaimer.
    *
    * 2. Redistributions in binary form must reproduce the above copyright
    *    notice, this list of conditions and the following disclaimer in
  @@ -18,7 +18,7 @@
    *    distribution.
    *
    * 3. The end-user documentation included with the redistribution,
  - *    if any, must include the following acknowledgment:  
  + *    if any, must include the following acknowledgment:
    *       "This product includes software developed by the
    *        Apache Software Foundation (http://www.apache.org/)."
    *    Alternately, this acknowledgment may appear in the software itself,
  @@ -26,7 +26,7 @@
    *
    * 4. The names "Xalan" and "Apache Software Foundation" must
    *    not be used to endorse or promote products derived from this
  - *    software without prior written permission. For written 
  + *    software without prior written permission. For written
    *    permission, please contact apache@apache.org.
    *
    * 5. Products derived from this software may not be called "Apache",
  @@ -61,6 +61,8 @@
   import org.w3c.dom.DOMException;
   import org.w3c.dom.NamedNodeMap;
   
  +import org.apache.xpath.patterns.NodeTest;
  +
   import java.sql.ResultSetMetaData;
   import java.sql.SQLException;
   
  @@ -140,41 +142,32 @@
       if (DEBUG)
         System.out.println("In ColumnHeader.getNextSibling");
   
  -    // try
  +    NodeTest nt = this.getNodeTest();
  +    if ((null == nt) || nt.getNamespace() == null)
       {
  -      org.apache.xpath.patterns.NodeTest nt = this.getNodeTest();
  -      if ((null == nt) || nt.getNamespace() == null)
  +      if (
  +        (null == nt) ||
  +        nt.getLocalName().equals(XStatement.S_COLUMNHEADERNAME))
         {
  -        if ((null == nt) || nt.getLocalName().equals(
  -                XStatement.S_COLUMNHEADERNAME))
  -        {
  -          int nextIndex = m_columnIndex + 1;
  -
  -          if (nextIndex < m_parent.m_columnHeaders.length)
  -          {
  -            if (null == m_parent.m_columnHeaders[nextIndex])
  -              m_parent.m_columnHeaders[nextIndex] =
  -                new ColumnHeader(getXStatement(), m_parent, nextIndex,
  -                                 m_metaData);
  +        int nextIndex = m_columnIndex + 1;
   
  -            return m_parent.m_columnHeaders[nextIndex];
  -          }
  -          else if(nt == null)
  +        if (nextIndex < m_parent.m_columnHeaders.length)
  +        {
  +          if (null == m_parent.m_columnHeaders[nextIndex])
             {
  -            return new Row(getXStatement(), m_parent);
  +            m_parent.m_columnHeaders[nextIndex] =
  +              new ColumnHeader(getXStatement(),m_parent,nextIndex,m_metaData);
             }
  -          else
  -            return null;
  +          return m_parent.m_columnHeaders[nextIndex];
           }
  +        else if(nt == null)
  +        {
  +          return new Row(getXStatement(), m_parent, null);
  +        }
  +        else return null;
         }
       }
   
  -    // catch(SQLException sqle)
  -    {
  -
  -      // diagnostics?
  -    }
  -
       return null;
     }
   
  @@ -271,7 +264,7 @@
      *
      * @param name Attribute name
      *
  -   * @return Attribute with given name or null if not found 
  +   * @return Attribute with given name or null if not found
      */
     public Node getNamedItem(String name)
     {
  @@ -294,7 +287,7 @@
      *
      * @param index Index of attribut to get
      *
  -   * @return Attribute node at given index or null if not found  
  +   * @return Attribute node at given index or null if not found
      */
     public Node item(int index)
     {
  @@ -360,7 +353,7 @@
     }
   
     /**
  -   * Remove an attribute - Not supported 
  +   * Remove an attribute - Not supported
      *
      *
      * @param name
  @@ -378,7 +371,7 @@
     }
   
     /**
  -   * Set namespaced attribute - Not supported 
  +   * Set namespaced attribute - Not supported
      *
      *
      * @param arg
  
  
  
  1.9       +89 -70    xml-xalan/java/src/org/apache/xalan/lib/sql/Row.java
  
  Index: Row.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/lib/sql/Row.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- Row.java	2001/02/21 14:05:41	1.8
  +++ Row.java	2001/04/18 23:24:50	1.9
  @@ -2,7 +2,7 @@
    * The Apache Software License, Version 1.1
    *
    *
  - * Copyright (c) 1999 The Apache Software Foundation.  All rights 
  + * Copyright (c) 1999 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -10,7 +10,7 @@
    * are met:
    *
    * 1. Redistributions of source code must retain the above copyright
  - *    notice, this list of conditions and the following disclaimer. 
  + *    notice, this list of conditions and the following disclaimer.
    *
    * 2. Redistributions in binary form must reproduce the above copyright
    *    notice, this list of conditions and the following disclaimer in
  @@ -18,7 +18,7 @@
    *    distribution.
    *
    * 3. The end-user documentation included with the redistribution,
  - *    if any, must include the following acknowledgment:  
  + *    if any, must include the following acknowledgment:
    *       "This product includes software developed by the
    *        Apache Software Foundation (http://www.apache.org/)."
    *    Alternately, this acknowledgment may appear in the software itself,
  @@ -26,7 +26,7 @@
    *
    * 4. The names "Xalan" and "Apache Software Foundation" must
    *    not be used to endorse or promote products derived from this
  - *    software without prior written permission. For written 
  + *    software without prior written permission. For written
    *    permission, please contact apache@apache.org.
    *
    * 5. Products derived from this software may not be called "Apache",
  @@ -60,12 +60,12 @@
   import org.w3c.dom.Document;
   import org.w3c.dom.DOMException;
   
  -import org.apache.xml.utils.UnImplNode;
   
   import java.sql.ResultSet;
   import java.sql.ResultSetMetaData;
   import java.sql.SQLException;
   import java.sql.ResultSet;
  +import org.apache.xml.utils.*;
   
   /**
    * <meta name="usage" content="experimental"/>
  @@ -86,11 +86,11 @@
     /** Meta data           */
     ResultSetMetaData m_metadata;
   
  -  /** Flag for whether this is streamable           */
  -  boolean m_isStreamable = false;
  -
     /** Next row          */
  -  Row m_next;  // normally null, if streamable.
  +  Row m_nextNode = null;  // normally null, if streamable.
  +
  +  /** Previous Node */
  +  Row m_prevNode = null;  // normally null, if streamable.
   
     /** Flag for DEBUG mode        */
     private static final boolean DEBUG = false;
  @@ -104,34 +104,19 @@
      *
      * @param statement Owning document
      * @param parent parent node, a row-set
  +   *
      */
  -  public Row(XStatement statement, RowSet parent)
  +  public Row(XStatement statement, RowSet parent, Row prev)
     {
  -
       super(statement);
   
  -    try
  -    {
  -      m_parent = parent;
  +    if (DEBUG) System.out.println("In Row.constructor");
   
  -      XStatement xstatement = this.getXStatement();
  -      ResultSet resultSet = xstatement.getResultSet();
  -      ResultSetMetaData metadata = resultSet.getMetaData();
  +    m_parent = parent;
  +    m_prevNode = prev;
   
  -      m_metadata = metadata;
  -      m_childCount = metadata.getColumnCount();
  -      m_columns = new Column[m_childCount];
  -
  -      for (int i = 0; i < m_childCount; i++)
  -      {
  -        m_columns[i] = new Column(xstatement, this, i, metadata);
  -      }
  -    }
  -    catch (SQLException sqle)
  -    {
  +    populateColumnData();
   
  -      // diagnostics?
  -    }
     }
   
     // ===== Element implementation =====
  @@ -164,80 +149,85 @@
      */
     public Node getFirstChild()
     {
  +    if (DEBUG) System.out.println("In Row.getFirstChild");
   
  -    if (DEBUG)
  -      System.out.println("In Row.getFirstChild");
  -
  -    if (this.hasChildNodes())
  -      return m_columns[0];
  -    else
  -      return null;
  +    if (hasChildNodes()) return m_columns[0];
  +    else return null;
     }
   
     /**
  -   * Return next row in the row-set. Use the same Row object over and over
  -   * if the row-set is streamable.
  +   * Return next row in the row-set.
  +   *
  +   * Use the same Row object over and over if the row-set is streamable.
      *
      * @return next row in the row-set or null if none
  +   * @throws Exception, Force the XConnection to handle all errors
      */
     public Node getNextSibling()
  +    throws DOMException
     {
   
       if (DEBUG)
       {
  -      System.out.print("In Row.getNextSibling");
  -      System.out.flush();
  +      System.out.println("In Row.getNextSibling");
       }
   
  -    XStatement xstatement = this.getXStatement();
  -    ResultSet resultSet = xstatement.getResultSet();
  -
       try
       {
  -      if (m_isStreamable)
  +      XStatement xstatement = this.getXStatement();
  +      ResultSet resultSet = xstatement.getResultSet();
  +
  +      if (xstatement.getShouldCacheNodes() == false)
         {
           if (resultSet.next())
  +        {
  +
  +          // Freshen our place in line
  +          incermentOrderIndex();
  +          // Get new data, even though we are streamable
  +          // we need to be up-to-date
  +          populateColumnData();
  +
             return this;
  +
  +        }
           else
  -          return null;
  +        {
  +          // We are at the end of the streamable line
  +         return null;
  +        }
         }
         else
         {
  -        if (null == m_next)
  +        // We are not in streamable mode any more, if we have already
  +        // been here, then lets just return what we already have
  +        if (null == m_nextNode)
           {
  -          try
  -          {
  -            if (resultSet.next())
  -              m_next = new Row(getXStatement(), m_parent);
  -          }
  -          catch (SQLException sqle)
  +          if (resultSet.next())
             {
  -
  -            // Diagnostics?
  +            m_nextNode = new Row(getXStatement(), m_parent, this);
             }
           }
   
  -        if (DEBUG)
  -        {
  -          System.out.println(": m_next: " + m_next);
  -          System.out.flush();
  -
  -          // Exception e = new Exception();
  -          // e.printStackTrace();
  -        }
  -
  -        return m_next;
  +        if (DEBUG) System.out.println(": m_next: " + m_nextNode);
  +        return m_nextNode;
         }
       }
  -    catch (SQLException sqle)
  +    catch(SQLException e)
       {
  -
  -      // Diagnostics?
  -      return null;
  +      throw new DOMException(DOMException.SYNTAX_ERR, e.getLocalizedMessage());
       }
     }
   
     /**
  +   * Allow us to walk back up the tree
  +   */
  +  public Node getPreviousSibling()
  +  {
  +    return m_prevNode;
  +  }
  +
  +  /**
      * Return the RowSet parent.
      *
      * @return The parent node (RowSet) of this row.
  @@ -261,8 +251,37 @@
     {
   
       if (DEBUG)
  -      System.out.println("In Row.hasChildNodes");
  +      System.out.println("In Row.hasChildNodes " + m_childCount);
   
       return (m_childCount > 0);
     }
  +
  +
  +  private void populateColumnData()
  +  {
  +    try
  +    {
  +      XStatement xstatement = getXStatement();
  +      ResultSet resultSet = xstatement.getResultSet();
  +
  +      ResultSetMetaData metadata = resultSet.getMetaData();
  +      m_metadata = metadata;
  +
  +      m_childCount = metadata.getColumnCount();
  +      m_columns = new Column[m_childCount];
  +
  +      // Use the same columns array, from Row to Row the columns
  +      // count should not change.
  +
  +      for (int i = 0; i < m_childCount; i++)
  +      {
  +        m_columns[i] = new Column(xstatement, this, i, metadata, resultSet);
  +      }
  +    }
  +    catch(SQLException e)
  +    {
  +      if (DEBUG) System.out.println("Error Populating Column Data");
  +    }
  +  }
  +
   }
  
  
  
  1.7       +120 -52   xml-xalan/java/src/org/apache/xalan/lib/sql/RowSet.java
  
  Index: RowSet.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/lib/sql/RowSet.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- RowSet.java	2001/02/21 14:05:41	1.6
  +++ RowSet.java	2001/04/18 23:24:50	1.7
  @@ -2,7 +2,7 @@
    * The Apache Software License, Version 1.1
    *
    *
  - * Copyright (c) 1999 The Apache Software Foundation.  All rights 
  + * Copyright (c) 1999 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -10,7 +10,7 @@
    * are met:
    *
    * 1. Redistributions of source code must retain the above copyright
  - *    notice, this list of conditions and the following disclaimer. 
  + *    notice, this list of conditions and the following disclaimer.
    *
    * 2. Redistributions in binary form must reproduce the above copyright
    *    notice, this list of conditions and the following disclaimer in
  @@ -18,7 +18,7 @@
    *    distribution.
    *
    * 3. The end-user documentation included with the redistribution,
  - *    if any, must include the following acknowledgment:  
  + *    if any, must include the following acknowledgment:
    *       "This product includes software developed by the
    *        Apache Software Foundation (http://www.apache.org/)."
    *    Alternately, this acknowledgment may appear in the software itself,
  @@ -26,7 +26,7 @@
    *
    * 4. The names "Xalan" and "Apache Software Foundation" must
    *    not be used to endorse or promote products derived from this
  - *    software without prior written permission. For written 
  + *    software without prior written permission. For written
    *    permission, please contact apache@apache.org.
    *
    * 5. Products derived from this software may not be called "Apache",
  @@ -64,6 +64,8 @@
   import java.sql.ResultSet;
   import java.sql.ResultSetMetaData;
   
  +import org.apache.xpath.patterns.NodeTest;
  +
   /**
    * <meta name="usage" content="experimental"/>
    * This class represents the row-set StreamableNode, a "streamable" holder
  @@ -71,9 +73,14 @@
    */
   public class RowSet extends StreamableNode
   {
  +  /** Let's keep track of the branch we are on */
  +  private static final int  ROWSET_POS_NONE = 0;
  +  private static final int  ROWSET_POS_COLHDR = 1;
  +  private static final int  ROWSET_POS_ROW = 2;
  +  private int               m_RowSetPos;
   
     /** Array of column headers in this row-set          */
  -  ColumnHeader[] m_columnHeaders;
  +  ColumnHeader[] m_columnHeaders = null;
   
     /** First row in this row-set          */
     Row m_firstrow;
  @@ -90,6 +97,41 @@
     public RowSet(XStatement statement)
     {
       super(statement);
  +
  +    m_RowSetPos = ROWSET_POS_NONE;
  +
  +    // Make sure we always populate the column headers
  +    // If we do not iterate over the COlumn Headers, and ask
  +    // for a column attribute, we will fail. So we need to
  +    // populate this array now.
  +    // Changed 3/15/01 JCG
  +    try
  +    {
  +      if (null == m_columnHeaders)
  +      {
  +        ResultSetMetaData metaData = statement.m_resultSet.getMetaData();
  +        int columnCount = metaData.getColumnCount();
  +
  +        // If we have actuall requested a set of columns and we
  +        // have not been here before, then get all the column
  +        // headers to build our list of attributes
  +        if (columnCount > 0)
  +        {
  +          m_columnHeaders = new ColumnHeader[columnCount];
  +
  +          // Populate the column Header Array
  +          for (int x =0; x< columnCount; x++)
  +          {
  +            m_columnHeaders[x] =
  +              new ColumnHeader(getXStatement(), this, x,  metaData);
  +          }
  +        }
  +      }
  +    }
  +    catch(SQLException e)
  +    {
  +      m_columnHeaders = null;
  +    }
     }
   
     // ===== Element implementation =====
  @@ -104,72 +146,90 @@
       return XStatement.S_DOCELEMENTNAME;
     }
   
  -  /**
  -   * The first time the client asks for a column-header element, instantiate an array of ColumnHeaders
  -   * (1 per column), and return the ColumnHeader for the first row.
  -   * @return ColumnHeader Node for first row or null.
  -   */
     public Node getFirstChild()
     {
   
       if (DEBUG)
         System.out.println("In RowSet.getFirstChild");
   
  +    NodeTest nt = this.getNodeTest();
  +
  +      // If we are asking for the Column Header branch of the Node Tree
  +      // or if we are asking for any branch (nt == null) then we will
  +      // return the First Column Header Node
  +    if ((null == nt) ||
  +      nt.getLocalName().equals(XStatement.S_COLUMNHEADERNAME))
  +    {
  +      m_RowSetPos = ROWSET_POS_COLHDR;
  +      return getFirstColHdr();
  +    }
  +    //
  +    // If we ask for the Row Branch directly then return the
  +    // first row. If we have been here before and we are in
  +    // streamable mode then return null, we can re-traverse
  +    // the Result Set in Streamable Mode.
  +    //
  +    // Suppporting JDBC scrollable cursors may change that
  +    // though.
  +    //
  +    else if (nt.getLocalName().equals(XStatement.S_ROWNAME))
  +    {
  +      m_RowSetPos = ROWSET_POS_ROW;
  +      return getFirstRow();
  +    }
  +
  +    return null;
  +  }
  +
  +  private Node getFirstColHdr()
  +  {
  +    if (null != m_columnHeaders) return m_columnHeaders[0];
  +    else return null;
  +  }
  +
  +  private Node getFirstRow()
  +  {
  +    XStatement statement = getXStatement();
  +
       try
       {
  -      org.apache.xpath.patterns.NodeTest nt = this.getNodeTest();
  -      if ((null == nt) || nt.getNamespace() == null)
  +      if (null == m_firstrow)
         {
  -        if ((null == nt) || nt.getLocalName().equals(
  -                XStatement.S_COLUMNHEADERNAME))
  +        // If there was no data, then return null for the query
  +        ResultSet resultSet = getXStatement().getResultSet();
  +        if (resultSet.next())
           {
  -          if (null == m_columnHeaders)
  -          {
  -            ResultSetMetaData metaData =
  -              getXStatement().m_resultSet.getMetaData();
  -            int columnCount = metaData.getColumnCount();
  -
  -            if (columnCount > 0)
  -            {
  -              m_columnHeaders = new ColumnHeader[columnCount];
  -              m_columnHeaders[0] = new ColumnHeader(getXStatement(), this, 0,
  -                                                    metaData);
  -
  -              return m_columnHeaders[0];
  -            }
  -            else
  -              return null;
  -          }
  -          else
  -            return m_columnHeaders[0];
  +          m_firstrow = new Row(getXStatement(), this, null);
           }
  -        else if (nt.getLocalName().equals(
  -                XStatement.S_ROWNAME))
  +        else
           {
  -          if (null == m_firstrow)
  -          {
  -            m_firstrow = new Row(getXStatement(), this);
  -          }
  -
  -          return m_firstrow;
  +          m_firstrow = null;
           }
  -        else
  -          return null;
         }
         else
  -        return null;
  +      {
  +        // We have been here before, then don't allow
  +        // use to re-traverse the query.
  +        //
  +        // We could just re-issue the query ??
  +        if (statement.getShouldCacheNodes() == false)
  +        {
  +          // Streaming is off, so let's prevent another walk through
  +          return null;
  +        }
  +      }
       }
  -    catch (SQLException sqle)
  +    catch(SQLException e)
       {
  -
  -      // diagnostics?
  +      // Something went wrong, just return null
         return null;
       }
  -  }
   
  +    return m_firstrow;
  +  }
   
     /**
  -   * getNextSibling - This always returns null.
  +   * getNextSibling
      *
      * @return null
      */
  @@ -179,7 +239,15 @@
       if (DEBUG)
         System.out.println("In RowSet.getNextSibling");
   
  -    return null;
  +    switch (m_RowSetPos)
  +    {
  +      case ROWSET_POS_NONE:
  +        return getFirstColHdr();
  +      case ROWSET_POS_COLHDR:
  +        return getFirstRow();
  +      default:
  +        return null;
  +    }
     }
   
     /**
  @@ -193,14 +261,14 @@
       if (DEBUG)
         System.out.println("In RowSet.getParentNode");
   
  -    return this.getXStatement();
  +    return getXStatement();
     }
   
     /**
      * Tell if there are any children of the document,
      * which is always true.
      *
  -   * @return True  
  +   * @return True
      */
     public boolean hasChildNodes()
     {
  
  
  
  1.11      +30 -30    xml-xalan/java/src/org/apache/xalan/lib/sql/StreamableNode.java
  
  Index: StreamableNode.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/lib/sql/StreamableNode.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- StreamableNode.java	2001/02/21 14:05:41	1.10
  +++ StreamableNode.java	2001/04/18 23:24:51	1.11
  @@ -2,7 +2,7 @@
    * The Apache Software License, Version 1.1
    *
    *
  - * Copyright (c) 1999 The Apache Software Foundation.  All rights 
  + * Copyright (c) 1999 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -10,7 +10,7 @@
    * are met:
    *
    * 1. Redistributions of source code must retain the above copyright
  - *    notice, this list of conditions and the following disclaimer. 
  + *    notice, this list of conditions and the following disclaimer.
    *
    * 2. Redistributions in binary form must reproduce the above copyright
    *    notice, this list of conditions and the following disclaimer in
  @@ -18,7 +18,7 @@
    *    distribution.
    *
    * 3. The end-user documentation included with the redistribution,
  - *    if any, must include the following acknowledgment:  
  + *    if any, must include the following acknowledgment:
    *       "This product includes software developed by the
    *        Apache Software Foundation (http://www.apache.org/)."
    *    Alternately, this acknowledgment may appear in the software itself,
  @@ -26,7 +26,7 @@
    *
    * 4. The names "Xalan" and "Apache Software Foundation" must
    *    not be used to endorse or promote products derived from this
  - *    software without prior written permission. For written 
  + *    software without prior written permission. For written
    *    permission, please contact apache@apache.org.
    *
    * 5. Products derived from this software may not be called "Apache",
  @@ -80,7 +80,7 @@
     private XStatement m_statement;
   
     /**
  -   * Get XStatement (owning document) 
  +   * Get XStatement (owning document)
      *
      *
      * @return owning document
  @@ -91,7 +91,7 @@
     }
   
     /**
  -   * Check if a given feature is supported 
  +   * Check if a given feature is supported
      *
      *
      * @param feature Feature to check
  @@ -127,13 +127,8 @@
      */
     public StreamableNode(XStatement statement)
     {
  -
       m_statement = statement;
  -
  -    if (null != statement)
  -    {
  -      m_orderIndex = m_statement.getAndIncrementNodeCounter();
  -    }
  +    incermentOrderIndex();
     }
   
     /**
  @@ -148,7 +143,7 @@
     }
   
     /**
  -   * Get Owner Document 
  +   * Get Owner Document
      *
      *
      * @return owner document
  @@ -199,10 +194,10 @@
     }
   
     /**
  -   * Get list of attributes 
  +   * Get list of attributes
      *
      *
  -   * @return the list of attributes for this node, itself  
  +   * @return the list of attributes for this node, itself
      */
     public NamedNodeMap getAttributes()
     {
  @@ -210,7 +205,7 @@
     }
   
     /**
  -   * Get the attribute with the given name - Not implemented 
  +   * Get the attribute with the given name - Not implemented
      *
      *
      * @param name attribute name to get
  @@ -223,7 +218,7 @@
     }
   
     /**
  -   * Return the attribute at the given index - Not implemented 
  +   * Return the attribute at the given index - Not implemented
      *
      *
      * @param index Index of attribute to get
  @@ -236,7 +231,7 @@
     }
   
     /**
  -   * The number of attributes for this node - Not implemented 
  +   * The number of attributes for this node - Not implemented
      *
      *
      * @return 0
  @@ -247,7 +242,7 @@
     }
   
     /**
  -   * Get the attribute with the given namespaced name - Not implemented 
  +   * Get the attribute with the given namespaced name - Not implemented
      *
      *
      * @param namespaceURI Namespace URI of the attribute to get
  @@ -261,7 +256,7 @@
     }
   
     /**
  -   * Set the given attribute - Not supported 
  +   * Set the given attribute - Not supported
      *
      *
      * @param arg attribute node
  @@ -279,7 +274,7 @@
     }
   
     /**
  -   * Remove the attribute with the given name - Not supported 
  +   * Remove the attribute with the given name - Not supported
      *
      *
      * @param name Attribute name
  @@ -297,7 +292,7 @@
     }
   
     /**
  -   * Set the attribute with the given namespaced name - Not supported 
  +   * Set the attribute with the given namespaced name - Not supported
      *
      *
      * @param arg Attriute node
  @@ -347,16 +342,21 @@
   
       if (-1 == m_orderIndex)
       {
  -      if (null != m_statement)
  -      {
  -        m_orderIndex = m_statement.getAndIncrementNodeCounter();
  -      }
  -      else
  -        m_orderIndex = 0;  // ?
  +      incermentOrderIndex();
       }
  +
  +//    if (DEBUG)
  +//      System.out.println(" Returning UID: "+m_orderIndex);
   
  -    // System.out.println(" Returning UID: "+m_orderIndex);
  -    // System.out.flush();
       return m_orderIndex;
  +  }
  +
  +  public void incermentOrderIndex()
  +  {
  +    if (null != m_statement)
  +    {
  +      m_orderIndex = m_statement.getAndIncrementNodeCounter();
  +    }
  +    else m_orderIndex = 0;
     }
   }
  
  
  
  1.12      +33 -4     xml-xalan/java/src/org/apache/xalan/lib/sql/XConnection.java
  
  Index: XConnection.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/lib/sql/XConnection.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- XConnection.java	2001/04/18 20:20:38	1.11
  +++ XConnection.java	2001/04/18 23:24:51	1.12
  @@ -125,8 +125,12 @@
      * For PreparedStatements, we need a place to
      * to store the parameters in a vector.
      */
  -   public Vector        m_ParameterList = new Vector();
  +   private Vector        m_ParameterList = new Vector();
   
  +  /**
  +   * Determine if we will build an in-memory copy of the SQL Data
  +   */
  +  private boolean      m_ShouldCacheNodes = true;
   
     // The original constructors will be kept around for backwards
     // compatibility. Future Stylesheets should use the approaite
  @@ -540,7 +544,7 @@
     {
       try
       {
  -      return new XStatement(this, queryString);
  +      return new XStatement(this, queryString, m_ShouldCacheNodes);
       }
       catch(SQLException e)
       {
  @@ -581,7 +585,9 @@
     {
       try
       {
  -      return new XStatement(this, queryString, m_ParameterList);
  +      return new XStatement(
  +        this, queryString,
  +        m_ParameterList, m_ShouldCacheNodes);
       }
       catch(SQLException e)
       {
  @@ -637,7 +643,9 @@
           }
         }
   
  -      return new XStatement(this, queryString, m_ParameterList);
  +      return new XStatement(
  +        this, queryString,
  +        m_ParameterList, m_ShouldCacheNodes);
       }
       catch(SQLException e)
       {
  @@ -805,6 +813,17 @@
     }
   
     /**
  +   *
  +   * Clear the parameter list for the Prameter based
  +   * queries. Allows for XConnection reuse.
  +   *
  +   */
  +  public void clearParameters()
  +  {
  +    m_ParameterList.removeAllElements();
  +  }
  +
  +  /**
      * Close the connection to the data source.
      *
      *
  @@ -836,6 +855,16 @@
   
       if (DEBUG)
         System.out.println("Exiting XConnection.close");
  +  }
  +
  +  public void enableCacheNodes()
  +  {
  +    m_ShouldCacheNodes = true;
  +  }
  +
  +  public void disableCacheNodes()
  +  {
  +    m_ShouldCacheNodes = false;
     }
   
     protected void finalize()
  
  
  
  1.13      +43 -9     xml-xalan/java/src/org/apache/xalan/lib/sql/XStatement.java
  
  Index: XStatement.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/lib/sql/XStatement.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- XStatement.java	2001/03/15 17:50:05	1.12
  +++ XStatement.java	2001/04/18 23:24:51	1.13
  @@ -93,7 +93,7 @@
   {
   
     /** Flag for DEBUG mode          */
  -  private static final boolean DEBUG = false; 
  +  private static final boolean DEBUG = false;
   
     /**
      * Ths JDBC Statement that is used for the query.
  @@ -105,8 +105,10 @@
     private PreparedStatement m_pstatement;
   
     /** Node counter          */
  -  private int m_nodeCounter = 0;
  +  private int               m_nodeCounter = 0;
   
  +  private boolean           m_ShouldCacheNodes = true;
  +
     /**
      * Get And Increment Node Counter
      *
  @@ -184,14 +186,22 @@
      *
      * @throws SQLException
      */
  -  public XStatement(XConnection connection, String queryString)
  -          throws SQLException
  +  public XStatement(
  +      XConnection connection,
  +      String queryString,
  +      boolean shouldCacheNodes)
  +      throws SQLException
     {
   
       super(null);
   
       if (DEBUG)
  +    {
         System.out.println("In XStatement constructor");
  +      System.out.println("Query = " + queryString);
  +    }
  +
  +    m_ShouldCacheNodes = shouldCacheNodes;
   
       // The SQL statement which lets us execute commands against the connection.
       m_xconnection = connection;
  @@ -207,8 +217,12 @@
         System.out.println("Exiting XStatement constructor");
     }
   
  -  public XStatement(XConnection connection, String queryString, Vector pList)
  -          throws SQLException
  +  public XStatement(
  +      XConnection connection,
  +      String queryString,
  +      Vector pList,
  +      boolean shouldCacheNodes)
  +      throws SQLException
     {
   
       super(null);
  @@ -216,6 +230,9 @@
       if (DEBUG)
         System.out.println("In XStatement constructor for pquery");
   
  +
  +    m_ShouldCacheNodes = shouldCacheNodes;
  +
       // The SQL statement which lets us execute commands against the connection.
       m_xconnection = connection;
       m_queryString = queryString;
  @@ -520,7 +537,14 @@
   
       try
       {
  -      if ((this.getNodeTest().getNamespace() == null)
  +
  +      if (getNodeTest() == null)
  +      {
  +        // We are not searching for any thing so return the row-set
  +        return m_rowset;
  +      }
  +
  +      if ((getNodeTest().getNamespace() == null)
                 && (this.getNodeTest().getLocalName().equals(S_DOCELEMENTNAME)))
           return m_rowset;
         else
  @@ -611,15 +635,24 @@
     }
   
     /**
  -   * Set whether nodes should be cached - not implemented
      *
  +   * Determines if the data returned from the SQL Query should
  +   * be used to build an in memory model of a DOM. If not, only
  +   * the current row will be avaiable. Otherwise, build a memory
  +   * model but that model will only be built up as the rows are
  +   * traversed.
      *
      * @param b Flag indicating whether nodes should be cached
  +   *
      */
     public void setShouldCacheNodes(boolean b)
     {
  +    m_ShouldCacheNodes = b;
  +  }
   
  -    // Set streamable?
  +  public boolean getShouldCacheNodes()
  +  {
  +    return m_ShouldCacheNodes;
     }
   
     /**
  @@ -726,4 +759,5 @@
     {
       m_last = last;
     }
  +
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org