johng 01/07/30 10:34:51
Modified: java/src/org/apache/xalan/lib/sql ObjectArray.java
SQLDocument.java SQLErrorDocument.java
XConnection.java
Log:
Added the original pquery and streaming mode functionality
Submitted by: John Gentilin
Revision Changes Path
1.3 +32 -0
xml-xalan/java/src/org/apache/xalan/lib/sql/ObjectArray.java
Index: ObjectArray.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/lib/sql/ObjectArray.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ObjectArray.java 2001/07/22 15:33:36 1.2
+++ ObjectArray.java 2001/07/30 17:34:51 1.3
@@ -53,6 +53,7 @@
m_minArraySize = size;
m_currentArray = new _ObjectArray(m_minArraySize);
}
+
/**
* @param idx Index of the Object in the Array
* @return
@@ -80,6 +81,37 @@
return m_currentArray.objects[arrayOffset];
}
}
+
+ /**
+ * @param idx Index of the Object in the Array
+ * @param obj, The value to set in the Array
+ * @return
+ */
+ public void setAt( final int idx, final Object obj )
+ {
+ int arrayIndx = idx / m_minArraySize;
+ int arrayOffset = idx - (arrayIndx * m_minArraySize);
+
+ //
+ // If the array has been off loaded to the Vector Storage them
+ // grab it from there.
+ if (arrayIndx < m_Arrays.size())
+ {
+ _ObjectArray a = (_ObjectArray)m_Arrays.elementAt(arrayIndx);
+ a.objects[arrayOffset] = obj;
+ }
+ else
+ {
+ // We must be in the current array, so pull it from there
+
+ // %REVIEW% We may want to check to see if arrayIndx is only
+ // one freater that the m_Arrays.size(); This code is safe but
+ // will repete if the index is greater than the array size.
+ m_currentArray.objects[arrayOffset] = obj;
+ }
+ }
+
+
/**
* @param o Object to be appended to the Array
1.13 +114 -1217
xml-xalan/java/src/org/apache/xalan/lib/sql/SQLDocument.java
Index: SQLDocument.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/lib/sql/SQLDocument.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- SQLDocument.java 2001/07/24 13:01:50 1.12
+++ SQLDocument.java 2001/07/30 17:34:51 1.13
@@ -60,63 +60,26 @@
package org.apache.xalan.lib.sql;
-import org.apache.xml.dtm.DTMManager;
-import org.apache.xml.dtm.DTMWSFilter;
-import org.apache.xml.utils.XMLString;
-import org.apache.xml.utils.XMLStringFactory;
-import org.w3c.dom.NodeList;
-import java.sql.ResultSet;
-import org.apache.xml.dtm.*;
-import org.apache.xml.dtm.ref.*;
-import org.xml.sax.ext.DeclHandler;
-import org.xml.sax.ErrorHandler;
-import org.xml.sax.DTDHandler;
-import org.xml.sax.EntityResolver;
-import org.xml.sax.ext.LexicalHandler;
-import org.xml.sax.ContentHandler;
-import org.apache.xml.dtm.ref.DTMDefaultBaseIterators;
-import org.xml.sax.ext.*;
-import org.xml.sax.*;
-import org.apache.xml.utils.SuballocatedIntVector;
-import org.apache.xpath.XPathContext;
-import org.apache.xalan.extensions.ExpressionContext;
+import org.apache.xml.dtm.DTMManager;
+import org.apache.xml.dtm.DTM;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
-import org.w3c.dom.Node;
-
-import java.io.IOException;
-import java.io.File;
-import java.io.PrintStream;
-import java.io.FileOutputStream;
/**
* The SQL Document is the main controlling class the executesa SQL Query
*/
-public class SQLDocument extends DTMDefaultBaseIterators
+public class SQLDocument extends DTMDocument
{
- public interface CharacterNodeHandler
- {
- public void characters(Node node)
- throws org.xml.sax.SAXException;
- }
+ private boolean DEBUG = true;
- private boolean DEBUG = false;
-
private static final String S_NAMESPACE =
"http://xml.apache.org/xalan/SQLExtension";
- private static final String S_ATTRIB_NOT_SUPPORTED="Not Supported";
- private static final String S_ISTRUE="true";
- private static final String S_ISFALSE="false";
-
- private static final String S_DOCUMENT = "#root";
- private static final String S_TEXT_NODE = "#text";
- private static final String S_ELEMENT_NODE = "#element";
private static final String S_COLUMN_HEADER = "column-header";
private static final String S_ROW_SET = "row-set";
@@ -140,9 +103,6 @@
private static final String S_ISWRITEABLE = "writable";
private static final String S_ISSEARCHABLE = "searchable";
- private int m_Document_TypeID = 0;
- private int m_TextNode_TypeID = 0;
-
private int m_ColumnHeader_TypeID = 0;
private int m_RowSet_TypeID = 0;
private int m_Row_TypeID = 0;
@@ -187,27 +147,6 @@
private ResultSet m_ResultSet = null;
/**
- * Store the SQL Data in this growable array
- */
- private ObjectArray m_ObjectArray = new ObjectArray();
-
- /**
- * For each element node, there can be zero or more attributes. If
Attributes
- * are assigned, the first attribute for that element will be use here.
- * Subsequent elements will use the m_nextsib, m_prevsib array. The sibling
- * arrays are not meeant to hold indexes to attribute information but as
- * long as there is not direct connection back into the main DTM tree
- * we should be OK.
- */
- protected SuballocatedIntVector m_attribute;
-
- /**
- * The Document Index will most likely be 0, but we will reference it
- * by variable in case that paradigm falls through.
- */
- private int m_DocumentIdx;
-
- /**
* As the column header array is built, keep the node index
* for each Column.
*
@@ -239,25 +178,34 @@
*/
private int m_LastRowIdx = DTM.NULL;
+ /**
+ * Streaming Mode Control, In Streaming mode we reduce the memory
+ * footprint since we only use a single row instance.
+ */
+
+ private boolean m_StreamingMode = true;
+
public SQLDocument(
DTMManager mgr, int ident,
- Connection con, Statement stmt, ResultSet data)
+ Connection con, Statement stmt, ResultSet data,
+ boolean streamingMode)
throws SQLException
{
- super(mgr, null, ident,
- null, mgr.getXMLStringFactory(), true);
+ super(mgr, ident);
m_Connection = con;
m_Statement = stmt;
m_ResultSet = data;
-
- m_attribute = new SuballocatedIntVector(m_initialblocksize);
+ m_StreamingMode = streamingMode;
createExpandedNameTable();
extractSQLMetaData(m_ResultSet.getMetaData());
- // Let's see what we have
- // dumpDTM();
+ // Only grab the first row, subsequent rows will be
+ // fetched on demand.
+ // We need to do this here so at least on row is set up
+ // to measure when we are actually reading rows.
+ addRowToDTMFromResultSet();
}
@@ -566,190 +514,66 @@
m_expandedNameTable.getExpandedTypeID(S_NAMESPACE, S_ISSEARCHABLE,
DTM.ATTRIBUTE_NODE);
}
- /**
- * A common routine that allocates an Object from the Object Array.
- * One of the common bugs in this code was to allocate an Object and
- * not incerment m_size, using this method will assure that function.
- */
- private int allocateNodeObject(Object o)
- {
- // Need to keep this counter going even if we don't use it.
- m_size++;
- return m_ObjectArray.append(o);
- }
-
- private int addElementWithData(Object o, int level, int extendedType, int
parent, int prevsib)
- {
- int elementIdx = addElement(level,extendedType,parent,prevsib);
-
- int data = allocateNodeObject(o);
- m_firstch.setElementAt(data,elementIdx);
-
- m_exptype.setElementAt(m_TextNode_TypeID, data);
- // m_level.setElementAt((byte)(level), data);
- m_parent.setElementAt(elementIdx, data);
-
- m_prevsib.setElementAt(DTM.NULL, data);
- m_nextsib.setElementAt(DTM.NULL, data);
- m_attribute.setElementAt(DTM.NULL, data);
- m_firstch.setElementAt(DTM.NULL, data);
-
- return elementIdx;
- }
-
- private int addElement(int level, int extendedType, int parent, int
prevsib)
- {
- int node = DTM.NULL;
-
- try
- {
- // Add the Node and adjust its Extended Type
- node = allocateNodeObject(S_ELEMENT_NODE);
-
- m_exptype.setElementAt(extendedType, node);
- m_nextsib.setElementAt(DTM.NULL, node);
- m_prevsib.setElementAt(prevsib, node);
-
- m_parent.setElementAt(parent, node);
- m_firstch.setElementAt(DTM.NULL, node);
- // m_level.setElementAt((byte)level, node);
- m_attribute.setElementAt(DTM.NULL, node);
-
- if (prevsib != DTM.NULL)
- {
- // If the previous sibling is already assigned, then we are
- // inserting a value into the chain.
- if (m_nextsib.elementAt(prevsib) != DTM.NULL)
- m_nextsib.setElementAt(m_nextsib.elementAt(prevsib), node);
-
- // Tell the proevious sibling that they have a new bother/sister.
- m_nextsib.setElementAt(node, prevsib);
- }
-
- // So if we have a valid parent and the new node ended up being first
- // in the list, i.e. no prevsib, then set the new node up as the
- // first child of the parent. Since we chained the node in the list,
- // there should be no reason to worry about the current first child
- // of the parent node.
- if ((parent != DTM.NULL) && (m_prevsib.elementAt(node) == DTM.NULL))
- {
- m_firstch.setElementAt(node, parent);
- }
- }
- catch(Exception e)
- {
- // Let's just return DTM.NULL now
-// System.err.println("====================");
-// e.printStackTrace(System.err);
-// System.err.println("====================");
- error("Error in addElement: "+e.getMessage());
- }
-
- return node;
- }
/**
- * Link an attribute to a node, if the node already has one or more
- * attributes assigned, then just link this one to the attribute list.
- * The first attribute is attached to the Parent Node (pnode) through the
- * m_attribute array, subsequent attributes are linked through the
- * m_prevsib, m_nextsib arrays.
- *
+ * Pull a record from the result set and map it to a DTM based ROW
+ * If we are in Streaming mode, then only create a single row and
+ * keep copying the data into the same row. This will keep the memory
+ * footprint constint independant of the RecordSet Size. If we are not
+ * in Streaming mode then create ROWS for the whole tree.
*/
- private int addAttributeToNode(
- Object o, int extendedType, int pnode)
+ private boolean addRowToDTMFromResultSet()
{
-
- int attrib = DTM.NULL;
- int prevsib = DTM.NULL;
- int lastattrib = DTM.NULL;
- int value = DTM.NULL;
-
try
- {
- // Add the Node and adjust its Extended Type
- attrib = allocateNodeObject(o);
-
- m_attribute.setElementAt(DTM.NULL, attrib);
- m_exptype.setElementAt(extendedType, attrib);
- // m_level.setElementAt((byte)0, attrib);
-
- // Clear the sibling references
- m_nextsib.setElementAt(DTM.NULL, attrib);
- m_prevsib.setElementAt(DTM.NULL,attrib);
- // Set the parent, although the was we are using attributes
- // in the SQL extension this reference will more than likly
- // be wrong
- m_parent.setElementAt(pnode, attrib);
- m_firstch.setElementAt(DTM.NULL, attrib);
-
- if (m_attribute.elementAt(pnode) != DTM.NULL)
- {
- // OK, we already have an attribute assigned to this
- // Node, Insert us into the head of the list.
- lastattrib = m_attribute.elementAt(pnode);
- m_nextsib.setElementAt(lastattrib, attrib);
- m_prevsib.setElementAt(attrib, lastattrib);
- }
- // Okay set the new attribute up as the first attribute
- // for the node.
- m_attribute.setElementAt(attrib, pnode);
- }
- catch(Exception e)
{
-// System.err.println("=================");
-// e.printStackTrace(System.err);
-// System.err.println("=================");
- // Let's just return DTM.NULL now
- error("Error in addAttributeToNode: "+e.getMessage());
- }
+ // Check to see if all the data has been read from the Query.
+ // If we are at the end the signal that event
+ if ( ! m_ResultSet.next())
+ {
+ // In Streaming mode, the current ROW will always point back
+ // to itself until all the data was read. Once the Query is
+ // empty then point the next row to DTM.NULL so that the stream
+ // ends.
- return attrib;
- }
+ if (m_StreamingMode)
+ {
+ // We are at the end, so let's untie the mark
+ m_nextsib.setElementAt(DTM.NULL, m_LastRowIdx);
+ }
- /**
- * Allow two nodes to share the same set of attributes. There may be some
- * problems because the parent of any attribute will be the original node
- * they were assigned to. Need to see how the attribute walker works, then
- * we should be able to fake it out.
- */
- private void cloneAttributeFromNode(int toNode, int fromNode)
- {
- try
- {
- if (m_attribute.elementAt(toNode) != DTM.NULL)
- {
- error("Cloneing Attributes, where from Node already had addtibures
assigned");
+ return false;
}
- m_attribute.setElementAt(m_attribute.elementAt(fromNode), toNode);
- }
- catch(Exception e)
- {
- // Let's just return DTM.NULL now
- error("Cloning attributes");
- }
- }
-
- private boolean addRowToDTMFromResultSet()
- {
- try
- {
- if ( ! m_ResultSet.next()) return false;
-
// If this is the first time here, start the new level
if (m_FirstRowIdx == DTM.NULL)
{
m_FirstRowIdx =
addElement(2, m_Row_TypeID, m_RowSetIdx,
m_ColHeadersIdx[m_ColCount-1]);
m_LastRowIdx = m_FirstRowIdx;
+
+ if (m_StreamingMode)
+ {
+ // Let's tie the rows together until the end.
+ m_nextsib.setElementAt(m_LastRowIdx, m_LastRowIdx);
+ }
+
}
else
{
- m_LastRowIdx = addElement(3, m_Row_TypeID, m_RowSetIdx,
m_LastRowIdx);
+ //
+ // If we are in Streaming mode, then only use a single row instance
+ if (! m_StreamingMode)
+ {
+ m_LastRowIdx = addElement(3, m_Row_TypeID, m_RowSetIdx,
m_LastRowIdx);
+ }
}
+
+ // If we are not in streaming mode, this will always be DTM.NULL
+ // If we are in streaming mode, it will only be DTM.NULL the first time
+ int colID = _firstch(m_LastRowIdx);
- int colID = DTM.NULL;
+ // Keep Track of who our parent was when adding new col objects.
+ int pcolID = DTM.NULL;
// Columns in JDBC Start at 1 and go to the Extent
for (int i=1; i<= m_ColCount; i++)
@@ -757,12 +581,48 @@
// Just grab the Column Object Type, we will convert it to a string
// later.
Object o = m_ResultSet.getObject(i);
- colID = addElementWithData(o,3,m_Col_TypeID, m_LastRowIdx, colID);
- cloneAttributeFromNode(colID, m_ColHeadersIdx[i-1]);
- }
+
+ // Create a new column object if one does not exist.
+ // In Streaming mode, this mechinism will reuse the column
+ // data the second and subsequent row accesses.
+ if (colID == DTM.NULL)
+ {
+ pcolID = addElementWithData(o,3,m_Col_TypeID, m_LastRowIdx,
pcolID);
+ cloneAttributeFromNode(pcolID, m_ColHeadersIdx[i-1]);
+ }
+ else
+ {
+ // We must be in streaming mode, so let's just replace the data
+ // If the firstch was not set then we have a major error
+ int dataIdent = _firstch(colID);
+ if (dataIdent == DTM.NULL)
+ {
+ error("Streaming Mode, Data Error");
+ }
+ else
+ {
+ m_ObjectArray.setAt(dataIdent, o);
+ }
+ } // If
+
+ // In streaming mode, this will be !DTM.NULL
+ // So if the elements were already established then we
+ // should be able to walk them in order.
+ if (colID != DTM.NULL)
+ {
+ colID = _nextsib(colID);
+ }
+
+ } // For Col Loop
}
catch(Exception e)
{
+ if (DEBUG)
+ {
+ System.out.println(
+ "SQL Error Fetching next row [" + e.getLocalizedMessage() + "]");
+ }
+
error("SQL Error Fetching next row [" + e.getLocalizedMessage() + "]");
}
@@ -803,85 +663,6 @@
}
}
- public int getFirstAttribute(int parm1)
- {
- if (DEBUG) System.out.println("getFirstAttribute("+
(parm1&NODEIDENTITYBITS)+")");
- int nodeIdx = parm1 & NODEIDENTITYBITS;
- if (nodeIdx != DTM.NULL) return m_attribute.elementAt(nodeIdx) |
m_dtmIdent;
- else return DTM.NULL;
- }
-
- /**
- * @param parm1
- * @return
- */
- public String getNodeValue( int parm1 )
- {
- if (DEBUG) System.out.println("getNodeValue(" + parm1 + ")");
- try
- {
- Object o = m_ObjectArray.getAt(parm1 & NODEIDENTITYBITS);
- if (o != null)
- {
- return o.toString();
- }
- else
- {
- return "";
- }
- }
- catch(Exception e)
- {
- error("Getting String Value");
- return null;
- }
- }
-
-
- /**
- * @param parm1
- * @return
- */
- public XMLString getStringValue( int parm1 )
- {
- if (DEBUG) System.out.println("getStringValue(" + parm1 + ")");
- try
- {
- Object o = m_ObjectArray.getAt(parm1 & NODEIDENTITYBITS);
- if (o != null)
- {
- return m_xstrf.newstr(o.toString());
- }
- else
- {
- return m_xstrf.emptystr();
- }
- }
- catch(Exception e)
- {
- error("Getting String Value");
- return null;
- }
- }
-
-
- public int getNextAttribute(int parm1)
- {
- if (DEBUG) System.out.println("getNextAttribute(" + parm1 + ")");
- int nodeIdx = parm1 & NODEIDENTITYBITS;
- if (nodeIdx != DTM.NULL) return m_nextsib.elementAt(nodeIdx) |
m_dtmIdent;
- else return DTM.NULL;
- }
-
-
- /**
- * @return
- */
- protected int getNumberOfNodes( )
- {
- if (DEBUG) System.out.println("getNumberOfNodes()");
- return m_size;
- }
/**
* @return
@@ -889,918 +670,34 @@
protected boolean nextNode( )
{
if (DEBUG) System.out.println("nextNode()");
- return addRowToDTMFromResultSet();
- }
-
-
- public void dumpDTM()
- {
try
- {
-// File f = new File("DTMDump"+((Object)this).hashCode()+".txt");
- File f = new File("DTMDump.txt");
- System.err.println("Dumping... "+f.getAbsolutePath());
- PrintStream ps = new PrintStream(new FileOutputStream(f));
-
- while (nextNode()){}
-
- int nRecords = m_size;
-
- ps.println("Total nodes: " + nRecords);
-
- for (int i = 0; i < nRecords; i++)
- {
- ps.println("=========== " + i + " ===========");
- ps.println("NodeName: " + getNodeName(i));
- ps.println("NodeNameX: " + getNodeNameX(i));
- ps.println("LocalName: " + getLocalName(i));
- ps.println("NamespaceURI: " + getNamespaceURI(i));
- ps.println("Prefix: " + getPrefix(i));
-
- int exTypeID = getExpandedTypeID(i);
-
- ps.println("Expanded Type ID: "
- + Integer.toHexString(exTypeID));
-
- int type = getNodeType(i);
- String typestring;
-
- switch (type)
- {
- case DTM.ATTRIBUTE_NODE :
- typestring = "ATTRIBUTE_NODE";
- break;
- case DTM.CDATA_SECTION_NODE :
- typestring = "CDATA_SECTION_NODE";
- break;
- case DTM.COMMENT_NODE :
- typestring = "COMMENT_NODE";
- break;
- case DTM.DOCUMENT_FRAGMENT_NODE :
- typestring = "DOCUMENT_FRAGMENT_NODE";
- break;
- case DTM.DOCUMENT_NODE :
- typestring = "DOCUMENT_NODE";
- break;
- case DTM.DOCUMENT_TYPE_NODE :
- typestring = "DOCUMENT_NODE";
- break;
- case DTM.ELEMENT_NODE :
- typestring = "ELEMENT_NODE";
- break;
- case DTM.ENTITY_NODE :
- typestring = "ENTITY_NODE";
- break;
- case DTM.ENTITY_REFERENCE_NODE :
- typestring = "ENTITY_REFERENCE_NODE";
- break;
- case DTM.NAMESPACE_NODE :
- typestring = "NAMESPACE_NODE";
- break;
- case DTM.NOTATION_NODE :
- typestring = "NOTATION_NODE";
- break;
- case DTM.NULL :
- typestring = "NULL";
- break;
- case DTM.PROCESSING_INSTRUCTION_NODE :
- typestring = "PROCESSING_INSTRUCTION_NODE";
- break;
- case DTM.TEXT_NODE :
- typestring = "TEXT_NODE";
- break;
- default :
- typestring = "Unknown!";
- break;
- }
-
- ps.println("Type: " + typestring);
-
- int firstChild = _firstch(i);
-
- if (DTM.NULL == firstChild)
- ps.println("First child: DTM.NULL");
- else if (NOTPROCESSED == firstChild)
- ps.println("First child: NOTPROCESSED");
- else
- ps.println("First child: " + firstChild);
-
- int prevSibling = _prevsib(i);
-
- if (DTM.NULL == prevSibling)
- ps.println("Prev sibling: DTM.NULL");
- else if (NOTPROCESSED == prevSibling)
- ps.println("Prev sibling: NOTPROCESSED");
- else
- ps.println("Prev sibling: " + prevSibling);
-
- int nextSibling = _nextsib(i);
-
- if (DTM.NULL == nextSibling)
- ps.println("Next sibling: DTM.NULL");
- else if (NOTPROCESSED == nextSibling)
- ps.println("Next sibling: NOTPROCESSED");
- else
- ps.println("Next sibling: " + nextSibling);
-
- int parent = _parent(i);
-
- if (DTM.NULL == parent)
- ps.println("Parent: DTM.NULL");
- else if (NOTPROCESSED == parent)
- ps.println("Parent: NOTPROCESSED");
- else
- ps.println("Parent: " + parent);
-
- int level = _level(i);
-
- ps.println("Level: " + level);
- ps.println("Node Value: " + getNodeValue(i));
- ps.println("String Value: " + getStringValue(i));
-
- ps.println("First Attribute Node: " + m_attribute.elementAt(i));
- }
-
- }
- catch(IOException ioe)
- {
- ioe.printStackTrace(System.err);
- System.exit(-1);
- }
- }
-
-
- /**
- * Retrieve the text content of a DOM subtree, appending it into a
- * user-supplied FastStringBuffer object. Note that attributes are
- * not considered part of the content of an element.
- * <p>
- * There are open questions regarding whitespace stripping.
- * Currently we make no special effort in that regard, since the standard
- * DOM doesn't yet provide DTD-based information to distinguish
- * whitespace-in-element-context from genuine #PCDATA. Note that we
- * should probably also consider xml:space if/when we address this.
- * DOM Level 3 may solve the problem for us.
- * <p>
- * %REVIEW% Note that as a DOM-level operation, it can be argued that this
- * routine _shouldn't_ perform any processing beyond what the DOM already
- * does, and that whitespace stripping and so on belong at the DTM level.
- * If you want a stripped DOM view, wrap DTM2DOM around DOM2DTM.
- *
- * @param node Node whose subtree is to be walked, gathering the
- * contents of all Text or CDATASection nodes.
- * @param buf FastStringBuffer into which the contents of the text
- * nodes are to be concatenated.
- */
- protected static void dispatchNodeData(Node node,
- org.xml.sax.ContentHandler ch,
- int depth)
- throws org.xml.sax.SAXException
- {
-
- switch (node.getNodeType())
{
- case Node.DOCUMENT_FRAGMENT_NODE :
- case Node.DOCUMENT_NODE :
- case Node.ELEMENT_NODE :
- {
- for (Node child = node.getFirstChild(); null != child;
- child = child.getNextSibling())
- {
- dispatchNodeData(child, ch, depth+1);
- }
- }
- break;
- case Node.PROCESSING_INSTRUCTION_NODE : // %REVIEW%
- case Node.COMMENT_NODE :
- if(0 != depth)
- break;
- // NOTE: Because this operation works in the DOM space, it does
_not_ attempt
- // to perform Text Coalition. That should only be done in DTM space.
- case Node.TEXT_NODE :
- case Node.CDATA_SECTION_NODE :
- case Node.ATTRIBUTE_NODE :
- String str = node.getNodeValue();
- if(ch instanceof CharacterNodeHandler)
- {
- ((CharacterNodeHandler)ch).characters(node);
- }
- else
- {
- ch.characters(str.toCharArray(), 0, str.length());
- }
- break;
-// /* case Node.PROCESSING_INSTRUCTION_NODE :
-// // warning(XPATHErrorResources.WG_PARSING_AND_PREPARING);
-// break; */
- default :
- // ignore
- break;
+ // return m_ResultSet.isAfterLast();
+ return false;
}
- }
-
- /*********************************************************************/
- /*********************************************************************/
- /******************* End of Functions we Wrote ***********************/
- /*********************************************************************/
- /*********************************************************************/
-
-
- /**
- * For the moment all the run time properties are ignored by this
- * class.
- *
- * @param property a <code>String</code> value
- * @param value an <code>Object</code> value
- */
- public void setProperty(String property, Object value)
- {
- }
-
- /**
- * No source information is available for DOM2DTM, so return
- * <code>null</code> here.
- *
- * @param node an <code>int</code> value
- * @return null
- */
- public javax.xml.transform.SourceLocator getSourceLocatorFor(int node)
- {
- return null;
- }
-
- /**
- * @param parm1
- * @return
- */
- protected int getNextNodeIdentity( int parm1 )
- {
- if (DEBUG) System.out.println("getNextNodeIdenty(" + parm1 + ")");
- return DTM.NULL;
- }
-
- /**
- * @param parm1
- * @param parm2
- * @param parm3
- * @return
- */
- public int getAttributeNode( int parm1, String parm2, String parm3 )
- {
- if (DEBUG)
+ catch(Exception e)
{
- System.out.println(
- "getAttributeNode(" +
- parm1 + "," +
- parm2 + "," +
- parm3 + ")");
+ return false;
}
- return DTM.NULL;
}
- /**
- * @param parm1
- * @return
- */
- public String getLocalName( int parm1 )
+ protected int _nextsib(int identity)
{
- int exID = this.getExpandedTypeID( parm1 & NODEIDENTITYBITS );
-
- if (DEBUG)
- {
- DEBUG = false;
- System.out.print("getLocalName(" + parm1 + ") -> ");
- System.out.println("..." + getLocalNameFromExpandedNameID(exID) );
- DEBUG = true;
- }
-
- return getLocalNameFromExpandedNameID(exID);
- }
+ // If we are asking for the next row and we have not
+ // been there yet then let's see if we can get another
+ // row from the ResultSet.
+ //
- /**
- * @param parm1
- * @return
- */
- public String getNodeName( int parm1 )
- {
- int exID = this.getExpandedTypeID( parm1 & NODEIDENTITYBITS );
- if (DEBUG)
+ int id = _exptype(identity);
+ if (
+ ( id == m_Row_TypeID) &&
+ (identity >= m_LastRowIdx))
{
- DEBUG = false;
- System.out.print("getLocalName(" + parm1 + ") -> ");
- System.out.println("..." + getLocalNameFromExpandedNameID(exID) );
- DEBUG = true;
+ if (DEBUG) System.out.println("reading from the ResultSet");
+ addRowToDTMFromResultSet();
}
- return getLocalNameFromExpandedNameID(exID);
- }
-
- /**
- * @param parm1
- * @return
- */
- public boolean isAttributeSpecified( int parm1 )
- {
- if (DEBUG) System.out.println("isAttributeSpecified(" + parm1 + ")");
- return false;
- }
-
- /**
- * @param parm1
- * @return
- */
- public String getUnparsedEntityURI( String parm1 )
- {
- if (DEBUG) System.out.println("getUnparsedEntityURI(" + parm1 + ")");
- return "";
- }
- /**
- * @return
- */
- public DTDHandler getDTDHandler( )
- {
- if (DEBUG) System.out.println("getDTDHandler()");
- return null;
+ return super._nextsib(identity);
}
-
- /**
- * @param parm1
- * @return
- */
- public String getPrefix( int parm1 )
- {
- if (DEBUG) System.out.println("getPrefix(" + parm1 + ")");
- return "";
- }
-
- /**
- * @return
- */
- public EntityResolver getEntityResolver( )
- {
- if (DEBUG) System.out.println("getEntityResolver()");
- return null;
- }
-
- /**
- * @return
- */
- public String getDocumentTypeDeclarationPublicIdentifier( )
- {
- if (DEBUG) System.out.println("get_DTD_PubId()");
- return "";
- }
-
- /**
- * @return
- */
- public LexicalHandler getLexicalHandler( )
- {
- if (DEBUG) System.out.println("getLexicalHandler()");
- return null;
- }
- /**
- * @return
- */
- public boolean needsTwoThreads( )
- {
- if (DEBUG) System.out.println("needsTwoThreads()");
- return false;
- }
-
- /**
- * @return
- */
- public ContentHandler getContentHandler( )
- {
- if (DEBUG) System.out.println("getContentHandler()");
- return null;
- }
-
- /**
- * @param parm1
- * @param parm2
- * @return
- * @throws org.xml.sax.SAXException
- */
- public void dispatchToEvents( int parm1, ContentHandler parm2 )
- throws org.xml.sax.SAXException
- {
- if (DEBUG)
- {
- System.out.println(
- "dispathcToEvents(" +
- parm1 + "," +
- parm2 + ")");
- }
- return;
- }
-
- /**
- * @param parm1
- * @return
- */
- public String getNamespaceURI( int parm1 )
- {
- if (DEBUG) System.out.println("getNamespaceURI(" +parm1+")");
- return "";
- }
-
- /**
- * @param parm1
- * @param parm2
- * @param parm3
- * @return
- * @throws org.xml.sax.SAXException
- */
- public void dispatchCharactersEvents(
- int nodeHandle, org.xml.sax.ContentHandler ch,
- boolean normalize)
- throws org.xml.sax.SAXException
- {
- if (DEBUG)
- {
- System.out.println("dispatchCharacterEvents(" +
- nodeHandle + "," +
- ch + "," +
- normalize + ")");
- }
-
- if(normalize)
- {
- XMLString str = getStringValue(nodeHandle);
- str = str.fixWhiteSpace(true, true, false);
- str.dispatchCharactersEvents(ch);
- }
- else
- {
- int type = getNodeType(nodeHandle);
- Node node = getNode(nodeHandle);
- dispatchNodeData(node, ch, 0);
- }
- }
-
- /**
- * Event overriding for Debug
- */
-
- public boolean supportsPreStripping()
- {
- if (DEBUG) System.out.println("supportsPreStripping()");
- return super.supportsPreStripping();
- }
-
- protected int _exptype(int parm1)
- {
- if (DEBUG) System.out.println("_exptype(" + parm1 + ")");
- return super._exptype( parm1);
- }
-
- protected SuballocatedIntVector findNamespaceContext(int parm1)
- {
- if (DEBUG) System.out.println("SuballocatedIntVector(" + parm1 + ")");
- return super.findNamespaceContext( parm1);
- }
-
- protected int _prevsib(int parm1)
- {
- if (DEBUG) System.out.println("_prevsib(" + parm1+ ")");
- return super._prevsib( parm1);
- }
-
-
- protected short _type(int parm1)
- {
- if (DEBUG) System.out.println("_type(" + parm1 + ")");
- return super._type( parm1);
- }
-
- public Node getNode(int parm1)
- {
- if (DEBUG) System.out.println("getNode(" + parm1 + ")");
- return super.getNode( parm1);
- }
-
- public int getPreviousSibling(int parm1)
- {
- if (DEBUG) System.out.println("getPrevSib(" + parm1 + ")");
- return super.getPreviousSibling( parm1);
- }
-
- public String getDocumentStandalone(int parm1)
- {
- if (DEBUG) System.out.println("getDOcStandAlone(" + parm1 + ")");
- return super.getDocumentStandalone( parm1);
- }
-
- public String getNodeNameX(int parm1)
- {
- if (DEBUG) System.out.println("getNodeNameX(" + parm1 + ")");
- //return super.getNodeNameX( parm1);
- return getNodeName(parm1);
-
- }
-
- public void setFeature(String parm1, boolean parm2)
- {
- if (DEBUG)
- {
- System.out.println(
- "setFeature(" +
- parm1 + "," +
- parm2 + ")");
- }
- super.setFeature( parm1, parm2);
- }
-
- protected int _parent(int parm1)
- {
- if (DEBUG) System.out.println("_parent(" + parm1 + ")");
- return super._parent( parm1);
- }
-
- protected void indexNode(int parm1, int parm2)
- {
- if (DEBUG) System.out.println("indexNode("+parm1+","+parm2+")");
- super.indexNode( parm1, parm2);
- }
-
- protected boolean getShouldStripWhitespace()
- {
- if (DEBUG) System.out.println("getShouldStripWS()");
- return super.getShouldStripWhitespace();
- }
-
- protected void popShouldStripWhitespace()
- {
- if (DEBUG) System.out.println("popShouldStripWS()");
- super.popShouldStripWhitespace();
- }
-
- public boolean isNodeAfter(int parm1, int parm2)
- {
- if (DEBUG) System.out.println("isNodeAfter(" + parm1 + "," + parm2 +
")");
- return super.isNodeAfter( parm1, parm2);
- }
-
- public int getNamespaceType(int parm1)
- {
- if (DEBUG) System.out.println("getNamespaceType(" + parm1 + ")");
- return super.getNamespaceType( parm1);
- }
-
- protected int _level(int parm1)
- {
- if (DEBUG) System.out.println("_level(" + parm1 + ")");
- return super._level( parm1);
- }
-
-
- protected void pushShouldStripWhitespace(boolean parm1)
- {
- if (DEBUG) System.out.println("push_ShouldStripWS(" + parm1 + ")");
- super.pushShouldStripWhitespace( parm1);
- }
-
- public String getDocumentVersion(int parm1)
- {
- if (DEBUG) System.out.println("getDocVer("+parm1+")");
- return super.getDocumentVersion( parm1);
- }
-
- public boolean isSupported(String parm1, String parm2)
- {
- if (DEBUG) System.out.println("isSupported("+parm1+","+parm2+")");
- return super.isSupported( parm1, parm2);
- }
-
-
- protected void setShouldStripWhitespace(boolean parm1)
- {
- if (DEBUG) System.out.println("set_ShouldStripWS("+parm1+")");
- super.setShouldStripWhitespace( parm1);
- }
-
-
- protected void ensureSizeOfIndex(int parm1, int parm2)
- {
- if (DEBUG) System.out.println("ensureSizeOfIndex("+parm1+","+parm2+")");
- super.ensureSizeOfIndex( parm1, parm2);
- }
-
- protected void ensureSize(int parm1)
- {
- if (DEBUG) System.out.println("ensureSize("+parm1+")");
-
- // IntVectors in DTMDefaultBase are now self-sizing, and ensureSize()
- // is being dropped.
- //super.ensureSize( parm1);
- }
-
- public String getDocumentEncoding(int parm1)
- {
- if (DEBUG) System.out.println("getDocumentEncoding("+parm1+")");
- return super.getDocumentEncoding( parm1);
- }
-
- public void appendChild(int parm1, boolean parm2, boolean parm3)
- {
- if (DEBUG)
- {
- System.out.println(
- "appendChild(" +
- parm1 + "," +
- parm2 + "," +
- parm3 + ")");
- }
- super.appendChild( parm1, parm2, parm3);
- }
-
- public short getLevel(int parm1)
- {
- if (DEBUG) System.out.println("getLevel("+parm1+")");
- return super.getLevel( parm1);
- }
-
- public String getDocumentBaseURI()
- {
- if (DEBUG) System.out.println("getDocBaseURI()");
- return super.getDocumentBaseURI();
- }
-
- public int getNextNamespaceNode(int parm1, int parm2, boolean parm3)
- {
- if (DEBUG)
- {
- System.out.println(
- "getNextNamesapceNode(" +
- parm1 + "," +
- parm2 + "," +
- parm3 + ")");
- }
- return super.getNextNamespaceNode( parm1, parm2, parm3);
- }
-
- public void appendTextChild(String parm1)
- {
- if (DEBUG) System.out.println("appendTextChild(" + parm1 + ")");
- super.appendTextChild( parm1);
- }
-
- protected int findGTE(int[] parm1, int parm2, int parm3, int parm4)
- {
- if (DEBUG)
- {
- System.out.println(
- "findGTE("+
- parm1 + "," +
- parm2 + "," +
- parm3 + ")");
- }
- return super.findGTE( parm1, parm2, parm3, parm4);
- }
-
- public int getFirstNamespaceNode(int parm1, boolean parm2)
- {
- if (DEBUG) System.out.println("getFirstNamespaceNode()");
- return super.getFirstNamespaceNode( parm1, parm2);
- }
-
- public int getStringValueChunkCount(int parm1)
- {
- if (DEBUG) System.out.println("getStringChunkCount(" + parm1 + ")");
- return super.getStringValueChunkCount( parm1);
- }
-
- public int getLastChild(int parm1)
- {
- if (DEBUG) System.out.println("getLastChild(" + parm1 + ")");
- return super.getLastChild( parm1);
- }
-
- public boolean hasChildNodes(int parm1)
- {
- if (DEBUG) System.out.println("hasChildNodes(" + parm1 + ")");
- return super.hasChildNodes( parm1);
- }
-
- public short getNodeType(int parm1)
- {
- if (DEBUG)
- {
- DEBUG=false;
- System.out.print("getNodeType(" + (parm1 & NODEIDENTITYBITS) + ") ");
- int exID = this.getExpandedTypeID( parm1 & NODEIDENTITYBITS );
- String name = getLocalNameFromExpandedNameID(exID);
- System.out.println(
- ".. Node name [" + name + "]" +
- "[" + getNodeType( parm1) + "]");
-
- DEBUG=true;
- }
-
- return super.getNodeType( parm1);
- }
-
- public boolean isCharacterElementContentWhitespace(int parm1)
- {
- if (DEBUG) System.out.println("isCharacterElementContentWhitespace(" +
parm1 +")");
- return super.isCharacterElementContentWhitespace( parm1);
- }
-
- public int getFirstChild(int parm1)
- {
- if (DEBUG) System.out.println("getFirstChild(" + parm1 + ")");
- return super.getFirstChild( parm1);
- }
-
- public String getDocumentSystemIdentifier(int parm1)
- {
- if (DEBUG) System.out.println("getDocSysID(" + parm1 + ")");
- return super.getDocumentSystemIdentifier( parm1);
- }
-
- protected void declareNamespaceInContext(int parm1, int parm2)
- {
- if (DEBUG)
System.out.println("declareNamespaceContext("+parm1+","+parm2+")");
- super.declareNamespaceInContext( parm1, parm2);
- }
-
- public String getNamespaceFromExpandedNameID(int parm1)
- {
- if (DEBUG)
- {
- DEBUG = false;
- System.out.print("getNamespaceFromExpandedNameID("+parm1+")");
- System.out.println("..." + super.getNamespaceFromExpandedNameID(
parm1) );
- DEBUG = true;
- }
- return super.getNamespaceFromExpandedNameID( parm1);
- }
-
- public String getLocalNameFromExpandedNameID(int parm1)
- {
- if (DEBUG)
- {
- DEBUG = false;
- System.out.print("getLocalNameFromExpandedNameID("+parm1+")");
- System.out.println("..." + super.getLocalNameFromExpandedNameID(
parm1));
- DEBUG = true;
- }
- return super.getLocalNameFromExpandedNameID( parm1);
- }
-
- public int getExpandedTypeID(int parm1)
- {
- if (DEBUG) System.out.println("getExpandedTypeID("+parm1+")");
- return super.getExpandedTypeID( parm1);
- }
-
- public int getDocument()
- {
- if (DEBUG) System.out.println("getDocument()");
- return super.getDocument();
- }
-
-
- protected int findInSortedSuballocatedIntVector(SuballocatedIntVector
parm1, int parm2)
- {
- if (DEBUG)
- {
- System.out.println(
- "findInSortedSubAlloctedVector(" +
- parm1 + "," +
- parm2 + ")");
- }
- return super.findInSortedSuballocatedIntVector( parm1, parm2);
- }
-
- public boolean isDocumentAllDeclarationsProcessed(int parm1)
- {
- if (DEBUG) System.out.println("isDocumentAllDeclProc("+parm1+")");
- return super.isDocumentAllDeclarationsProcessed( parm1);
- }
-
- protected void error(String parm1)
- {
- if (DEBUG) System.out.println("error("+parm1+")");
- super.error( parm1);
- }
-
-
- protected int _firstch(int parm1)
- {
- if (DEBUG) System.out.println("_firstch("+parm1+")");
- return super._firstch( parm1);
- }
-
- public int getOwnerDocument(int parm1)
- {
- if (DEBUG) System.out.println("getOwnerDoc("+parm1+")");
- return super.getOwnerDocument( parm1);
- }
-
- protected int _nextsib(int parm1)
- {
- if (DEBUG) System.out.println("_nextSib("+parm1+")");
- return super._nextsib( parm1);
- }
-
- public int getNextSibling(int parm1)
- {
- if (DEBUG) System.out.println("getNextSibling("+parm1+")");
- return super.getNextSibling( parm1);
- }
-
-
- public boolean getDocumentAllDeclarationsProcessed()
- {
- if (DEBUG) System.out.println("getDocAllDeclProc()");
- return super.getDocumentAllDeclarationsProcessed();
- }
-
- public int getParent(int parm1)
- {
- if (DEBUG) System.out.println("getParent("+parm1+")");
- return super.getParent( parm1);
- }
-
- public int getExpandedTypeID(String parm1, String parm2, int parm3)
- {
- if (DEBUG) System.out.println("getExpandedTypeID()");
- return super.getExpandedTypeID( parm1, parm2, parm3);
- }
-
- public void setDocumentBaseURI(String parm1)
- {
- if (DEBUG) System.out.println("setDocBaseURI()");
- super.setDocumentBaseURI( parm1);
- }
-
- public char[] getStringValueChunk(int parm1, int parm2, int[] parm3)
- {
- if (DEBUG)
- {
- System.out.println("getStringChunkValue(" +
- parm1 + "," +
- parm2 + ")");
- }
- return super.getStringValueChunk( parm1, parm2, parm3);
- }
-
- public DTMAxisTraverser getAxisTraverser(int parm1)
- {
- if (DEBUG) System.out.println("getAxixTraverser("+parm1+")");
- return super.getAxisTraverser( parm1);
- }
-
- public DTMAxisIterator getTypedAxisIterator(int parm1, int parm2)
- {
- if (DEBUG)
System.out.println("getTypedAxisIterator("+parm1+","+parm2+")");
- return super.getTypedAxisIterator( parm1, parm2);
- }
-
- public DTMAxisIterator getAxisIterator(int parm1)
- {
- if (DEBUG) System.out.println("getAxisIterator("+parm1+")");
- return super.getAxisIterator( parm1);
- }
- /**
- * @param parm1
- * @return
- */
- public int getElementById( String parm1 )
- {
- if (DEBUG) System.out.println("getElementByID("+parm1+")");
- return DTM.NULL;
- }
-
- /**
- * @return
- */
- public DeclHandler getDeclHandler( )
- {
- if (DEBUG) System.out.println("getDeclHandler()");
- return null;
- }
-
- /**
- * @return
- */
- public ErrorHandler getErrorHandler( )
- {
- if (DEBUG) System.out.println("getErrorHandler()");
- return null;
- }
-
- /**
- * @return
- */
- public String getDocumentTypeDeclarationSystemIdentifier( )
- {
- if (DEBUG) System.out.println("get_DTD-SID()");
- return null;
- }
-
}
1.3 +6 -263
xml-xalan/java/src/org/apache/xalan/lib/sql/SQLErrorDocument.java
Index: SQLErrorDocument.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/lib/sql/SQLErrorDocument.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- SQLErrorDocument.java 2001/07/12 20:02:45 1.2
+++ SQLErrorDocument.java 2001/07/30 17:34:51 1.3
@@ -61,283 +61,26 @@
package org.apache.xalan.lib.sql;
import org.apache.xml.dtm.DTMManager;
-import org.apache.xml.dtm.DTMWSFilter;
-import org.apache.xml.utils.XMLString;
-import org.apache.xml.utils.XMLStringFactory;
-import org.w3c.dom.NodeList;
-import java.sql.ResultSet;
-import org.apache.xml.dtm.*;
-import org.apache.xml.dtm.ref.*;
-import org.xml.sax.ext.DeclHandler;
-import org.xml.sax.ErrorHandler;
-import org.xml.sax.DTDHandler;
-import org.xml.sax.EntityResolver;
-import org.xml.sax.ext.LexicalHandler;
-import org.xml.sax.ContentHandler;
-import org.apache.xml.dtm.ref.DTMDefaultBaseIterators;
-import org.xml.sax.ext.*;
-import org.xml.sax.*;
-import org.apache.xml.utils.*;
-
import java.sql.SQLException;
/**
* The SQL Document is the main controlling class the executesa SQL Query
*/
-public class SQLErrorDocument extends DTMDefaultBaseIterators
+public class SQLErrorDocument extends DTMDocument
{
/**
- */
- public SQLErrorDocument(SQLException error )
- {
- super(null, null, 0, null, null, true);
- }
-
-
- /**
- */
- public SQLErrorDocument(Exception error )
- {
- super(null, null, 0, null, null, true);
- }
-
-
- /**
- * @param parm1
- * @return
- */
- protected int getNextNodeIdentity( int parm1 )
- {
- return 0;
- }
-
- /**
- * @param parm1
- * @param parm2
- * @param parm3
- * @return
- */
- public int getAttributeNode( int parm1, String parm2, String parm3 )
- {
- return 0;
- }
-
- /**
- * @param parm1
- * @return
- */
- public String getLocalName( int parm1 )
- {
- return "";
- }
-
- /**
- * @param parm1
- * @return
- */
- public String getNodeName( int parm1 )
- {
- return "";
- }
-
- /**
- * @param parm1
- * @return
- */
- public int getElementById( String parm1 )
- {
- return 0;
- }
-
- /**
- * @return
- */
- public DeclHandler getDeclHandler( )
- {
- return null;
- }
-
- /**
- * @return
- */
- public ErrorHandler getErrorHandler( )
- {
- return null;
- }
-
- /**
- * @return
- */
- public String getDocumentTypeDeclarationSystemIdentifier( )
- {
- return null;
- }
-
- /**
- * @return
- */
- protected int getNumberOfNodes( )
- {
- return 0;
- }
-
-
- /**
- * @param parm1
- * @return
- */
- public String getNodeValue( int parm1 )
- {
- return "";
- }
-
- /**
- * @param parm1
- * @return
- */
- public boolean isAttributeSpecified( int parm1 )
- {
- return false;
- }
-
- /**
- * @param parm1
- * @return
- */
- public String getUnparsedEntityURI( String parm1 )
- {
- return "";
- }
-
- /**
- * @return
- */
- public DTDHandler getDTDHandler( )
- {
- return null;
- }
-
- /**
- * @param parm1
- * @return
- */
- public String getPrefix( int parm1 )
- {
- return "";
- }
-
- /**
- * @return
*/
- public EntityResolver getEntityResolver( )
+ public SQLErrorDocument(DTMManager mgr, int ident, SQLException error )
{
- return null;
+ super(mgr, ident);
}
- /**
- * @return
- */
- public String getDocumentTypeDeclarationPublicIdentifier( )
- {
- return "";
- }
-
- /**
- * @return
- */
- protected boolean nextNode( )
- {
- return false;
- }
/**
- * @return
*/
- public LexicalHandler getLexicalHandler( )
+ public SQLErrorDocument(DTMManager mgr, int ident, Exception error )
{
- return null;
+ super(mgr, ident);
}
-
- /**
- * @param parm1
- * @return
- */
- public XMLString getStringValue( int parm1 )
- {
- return null;
- }
-
- /**
- * @return
- */
- public boolean needsTwoThreads( )
- {
- return false;
- }
-
- /**
- * @return
- */
- public ContentHandler getContentHandler( )
- {
- return null;
- }
-
- /**
- * @param parm1
- * @param parm2
- * @return
- * @throws org.xml.sax.SAXException
- */
- public void dispatchToEvents( int parm1, ContentHandler parm2 )throws
org.xml.sax.SAXException
- {
- return;
- }
-
- /**
- * @param parm1
- * @return
- */
- public String getNamespaceURI( int parm1 )
- {
- return "";
- }
-
- /**
- * @param parm1
- * @param parm2
- * @param parm3
- * @return
- * @throws org.xml.sax.SAXException
- */
- public void dispatchCharactersEvents( int parm1, ContentHandler parm2,
boolean parm3 )throws org.xml.sax.SAXException
- {
- return;
- }
-
-
- /**
- * For the moment all the run time properties are ignored by this
- * class.
- *
- * @param property a <code>String</code> value
- * @param value an <code>Object</code> value
- */
- public void setProperty(String property, Object value)
- {
- }
-
- /**
- * No source information is available for DOM2DTM, so return
- * <code>null</code> here.
- *
- * @param node an <code>int</code> value
- * @return null
- */
- public javax.xml.transform.SourceLocator getSourceLocatorFor(int node)
- {
- return null;
- }
-
-}
+}
\ No newline at end of file
1.17 +336 -63
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.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- XConnection.java 2001/07/15 19:22:42 1.16
+++ XConnection.java 2001/07/30 17:34:51 1.17
@@ -60,29 +60,35 @@
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.SQLException;
+import java.sql.Statement;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.Date;
+import java.sql.Timestamp;
+import java.sql.Time;
+
import java.util.Properties;
import java.util.Vector;
import java.util.StringTokenizer;
+
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.traversal.NodeIterator;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
-import org.w3c.dom.*;
-import java.util.*;
-import java.sql.*;
+import java.util.Vector;
+import java.util.Enumeration;
-import org.apache.xml.dtm.DTMIterator;
-import org.apache.xml.dtm.DTMAxisIterator;
-import org.apache.xml.dtm.DTM;
-import org.apache.xalan.extensions.ExpressionContext;
+import java.math.BigDecimal;
+import org.apache.xml.dtm.DTM;
import org.apache.xml.dtm.DTMManager;
import org.apache.xml.dtm.ref.DTMManagerDefault;
import org.apache.xpath.XPathContext;
+import org.apache.xalan.extensions.ExpressionContext;
+
/**
* An XSLT extension that allows a stylesheet to
* access JDBC data. From the stylesheet perspective,
@@ -161,6 +167,15 @@
private boolean m_IsDefaultPool = false;
/**
+ * This flag will be used to indicate to the SQLDocument to use
+ * Streaming mode. Streeaming Mode will reduce the memory footprint
+ * to a fixed amount but will not let you traverse the tree more than
+ * once since the Row data will be reused for every Row in the Query.
+ *
+ */
+ private boolean m_IsStreamingEnabled = false;
+
+ /**
*/
public XConnection( )
{
@@ -173,26 +188,26 @@
/**
* @param ConnPoolName
*/
- public XConnection( String ConnPoolName )
+ public XConnection(ExpressionContext exprContext, String ConnPoolName )
{
- connect(ConnPoolName);
+ connect(exprContext, ConnPoolName);
}
/**
* @param driver
* @param dbURL
*/
- public XConnection( String driver, String dbURL )
+ public XConnection(ExpressionContext exprContext, String driver, String
dbURL )
{
- connect(driver, dbURL);
+ connect(exprContext, driver, dbURL);
}
/**
* @param list
*/
- public XConnection( NodeList list )
+ public XConnection(ExpressionContext exprContext, NodeList list )
{
- connect(list);
+ connect(exprContext, list);
}
/**
@@ -201,9 +216,9 @@
* @param user
* @param password
*/
- public XConnection( String driver, String dbURL, String user, String
password )
+ public XConnection(ExpressionContext exprContext, String driver, String
dbURL, String user, String password )
{
- connect(driver, dbURL, user, password);
+ connect(exprContext, driver, dbURL, user, password);
}
/**
@@ -211,9 +226,10 @@
* @param dbURL
* @param protocolElem
*/
- public XConnection( String driver, String dbURL, Element protocolElem )
+ public XConnection(
+ ExpressionContext exprContext, String driver, String dbURL, Element
protocolElem )
{
- connect(driver, dbURL, protocolElem);
+ connect(exprContext, driver, dbURL, protocolElem);
}
@@ -222,7 +238,7 @@
* @param ConnPoolName
* @return
*/
- public XConnection connect( String ConnPoolName )
+ public XConnection connect(ExpressionContext exprContext, String
ConnPoolName )
{
try
{
@@ -237,7 +253,7 @@
// }
catch (Exception e)
{
- m_Error = new SQLErrorDocument(e);
+ buildErrorDocument(exprContext, e);
return null;
}
@@ -249,7 +265,7 @@
* @param dbURL database URL of the form jdbc:subprotocol:subname.
* @return
*/
- public XConnection connect( String driver, String dbURL )
+ public XConnection connect(ExpressionContext exprContext, String driver,
String dbURL )
{
try
{
@@ -258,12 +274,12 @@
}
catch(SQLException e)
{
- m_Error = new SQLErrorDocument(e);
+ buildErrorDocument(exprContext, e);
return null;
}
catch (Exception e)
{
- m_Error = new SQLErrorDocument(e);
+ buildErrorDocument(exprContext, e);
return null;
}
}
@@ -272,7 +288,7 @@
* @param protocolElem
* @return
*/
- public XConnection connect( Element protocolElem )
+ public XConnection connect(ExpressionContext exprContext, Element
protocolElem )
{
try
{
@@ -281,12 +297,12 @@
}
catch(SQLException e)
{
- m_Error = new SQLErrorDocument(e);
+ buildErrorDocument(exprContext, e);
return null;
}
catch (Exception e)
{
- m_Error = new SQLErrorDocument(e);
+ buildErrorDocument(exprContext, e);
return null;
}
}
@@ -295,7 +311,7 @@
* @param list
* @return
*/
- public XConnection connect( NodeList list )
+ public XConnection connect(ExpressionContext exprContext, NodeList list )
{
try
{
@@ -304,12 +320,12 @@
}
catch(SQLException e)
{
- m_Error = new SQLErrorDocument(e);
+ buildErrorDocument(exprContext, e);
return null;
}
catch (Exception e)
{
- m_Error = new SQLErrorDocument(e);
+ buildErrorDocument(exprContext, e);
return null;
}
}
@@ -322,7 +338,9 @@
* @param password connection password.
* @return
*/
- public XConnection connect( String driver, String dbURL, String user,
String password )
+ public XConnection connect(
+ ExpressionContext exprContext,
+ String driver, String dbURL, String user, String password )
{
try
{
@@ -336,12 +354,12 @@
}
catch(SQLException e)
{
- m_Error = new SQLErrorDocument(e);
+ buildErrorDocument(exprContext, e);
return null;
}
catch (Exception e)
{
- m_Error = new SQLErrorDocument(e);
+ buildErrorDocument(exprContext, e);
return null;
}
}
@@ -355,7 +373,9 @@
* normally including at least "user" and "password".
* @return
*/
- public XConnection connect( String driver, String dbURL, Element
protocolElem )
+ public XConnection connect(
+ ExpressionContext exprContext,
+ String driver, String dbURL, Element protocolElem )
{
try
{
@@ -374,12 +394,12 @@
}
catch(SQLException e)
{
- m_Error = new SQLErrorDocument(e);
+ buildErrorDocument(exprContext, e);
return null;
}
catch (Exception e)
{
- m_Error = new SQLErrorDocument(e);
+ buildErrorDocument(exprContext, e);
return null;
}
}
@@ -579,7 +599,8 @@
DTMManagerDefault mgrDefault = (DTMManagerDefault) mgr;
int dtmIdent = mgrDefault.getFirstFreeDTMID();
- SQLDocument doc = new SQLDocument(mgr, dtmIdent << 20 , con, stmt,
rs);
+ SQLDocument doc =
+ new SQLDocument(mgr, dtmIdent << 20 , con, stmt, rs,
m_IsStreamingEnabled);
if (null != doc)
{
if (DEBUG) System.out.println("..returning Document");
@@ -597,15 +618,15 @@
return null;
}
}
-// catch(SQLException e)
-// {
-// m_Error = new SQLErrorDocument(e);
-// return null;
-// }
+ catch(SQLException e)
+ {
+ buildErrorDocument(exprContext, e);
+ return null;
+ }
catch (Exception e)
{
if (DEBUG) System.out.println("exception in query()");
- m_Error = new SQLErrorDocument(e);
+ buildErrorDocument(exprContext, e);
return null;
}
finally
@@ -625,21 +646,62 @@
* @link org.apache.xalan.lib.sql.RowSet RowSet},
* a row-set element.
*/
- public DTMIterator pquery( String queryString )
+ public DTM pquery(ExpressionContext exprContext, String queryString )
{
try
{
+ int indx;
+
+ Connection con = m_ConnectionPool.getConnection();
+ PreparedStatement stmt = con.prepareStatement(queryString);
+
+ if (DEBUG) System.out.println("..building Prepared Statement");
+
+ Enumeration enum = m_ParameterList.elements();
+ indx = 1;
+ while (enum.hasMoreElements())
+ {
+ QueryParameter qp = (QueryParameter) enum.nextElement();
+ setParameter(indx, stmt, qp);
+ indx++;
+ }
+
+ ResultSet rs = stmt.executeQuery();
+
+ if (DEBUG) System.out.println("..creatingSQLDocument");
+
+ DTMManager mgr =
+ ((XPathContext.XPathExpressionContext)exprContext).getDTMManager();
+ DTMManagerDefault mgrDefault = (DTMManagerDefault) mgr;
+ int dtmIdent = mgrDefault.getFirstFreeDTMID();
+
+ SQLDocument doc =
+ new SQLDocument(mgr, dtmIdent << 20 , con, stmt, rs,
m_IsStreamingEnabled);
+ if (null != doc)
+ {
+ if (DEBUG) System.out.println("..returning Document");
+
+ // Register our document
+ mgrDefault.addDTM(doc, dtmIdent);
+
+ // also keep a local reference
+ m_OpenSQLDocuments.addElement(doc);
+ return doc;
+ }
+ else
+ {
+ // Build Error Doc, BAD Result Set
+ return null;
+ }
+ }
+ catch(SQLException e)
+ {
+ buildErrorDocument(exprContext, e);
return null;
- //return new XStatement(this, queryString, m_ParameterList);
}
-// catch(SQLException e)
-// //{
-// m_Error = new SQLErrorDocument(e);
-// return null;
-// }
catch (Exception e)
{
- m_Error = new SQLErrorDocument(e);
+ buildErrorDocument(exprContext, e);
return null;
}
}
@@ -661,12 +723,11 @@
* the parameter types will be used to overload the current types
* in the current parameter list.
*/
- public DTMIterator pquery( String queryString, String typeInfo )
+ public DTM pquery(ExpressionContext exprContext, String queryString,
String typeInfo)
{
try
{
- int indx = 0;
- QueryParameter param = null;
+ int indx;
// Parse up the parameter types that were defined
// with the query
@@ -676,27 +737,70 @@
// parameter list. If there are more types than parameters
// ignore for now, a more meaningfull error should occur
// when the actual query is executed.
+ indx = 0;
while (plist.hasMoreTokens())
{
String value = plist.nextToken();
- param = (QueryParameter) m_ParameterList.elementAt(indx);
- if ( null != param )
+ QueryParameter qp = (QueryParameter) m_ParameterList.elementAt(indx);
+ if ( null != qp )
{
- param.setType(value);
+ qp.setType(value);
}
+
+ indx++;
}
+ Connection con = m_ConnectionPool.getConnection();
+ PreparedStatement stmt = con.prepareStatement(queryString);
+
+ if (DEBUG) System.out.println("..building Prepared Statement");
+
+ Enumeration enum = m_ParameterList.elements();
+ indx = 1;
+ while (enum.hasMoreElements())
+ {
+ QueryParameter qp = (QueryParameter) enum.nextElement();
+ setParameter(indx, stmt, qp);
+ indx++;
+ }
+
+
+ ResultSet rs = stmt.executeQuery();
+
+ if (DEBUG) System.out.println("..creatingSQLDocument");
+
+ DTMManager mgr =
+ ((XPathContext.XPathExpressionContext)exprContext).getDTMManager();
+ DTMManagerDefault mgrDefault = (DTMManagerDefault) mgr;
+ int dtmIdent = mgrDefault.getFirstFreeDTMID();
+
+ SQLDocument doc =
+ new SQLDocument(mgr, dtmIdent << 20 , con, stmt, rs,
m_IsStreamingEnabled);
+ if (null != doc)
+ {
+ if (DEBUG) System.out.println("..returning Document");
+
+ // Register our document
+ mgrDefault.addDTM(doc, dtmIdent);
+
+ // also keep a local reference
+ m_OpenSQLDocuments.addElement(doc);
+ return doc;
+ }
+ else
+ {
+ // Build Error Doc, BAD Result Set
+ return null;
+ }
+ }
+ catch(SQLException e)
+ {
+ buildErrorDocument(exprContext, e);
return null;
- // return new XStatement(this, queryString, m_ParameterList);
}
-// catch(SQLException e)
-// {
-// m_Error = new SQLErrorDocument(e);
-// return null;
-// }
catch (Exception e)
{
- m_Error = new SQLErrorDocument(e);
+ buildErrorDocument(exprContext, e);
return null;
}
}
@@ -864,6 +968,37 @@
m_ConnectionPool.setPoolEnabled(false);
}
+
+ /**
+ * Control how the SQL Document uses memory. In Streaming Mode,
+ * memory consumption is greatly reduces so you can have queries
+ * of unlimited size but it will not let you traverse the data
+ * more than once.
+ */
+ public void enableStreamingMode( )
+ {
+
+ if (DEBUG)
+ System.out.println("Enabling Streaming Mode");
+
+ m_IsStreamingEnabled = true;
+ }
+
+ /**
+ * Control how the SQL Document uses memory. In Streaming Mode,
+ * memory consumption is greatly reduces so you can have queries
+ * of unlimited size but it will not let you traverse the data
+ * more than once.
+ */
+ public void disableStreamingMode( )
+ {
+
+ if (DEBUG)
+ System.out.println("Disable Streaming Mode");
+
+ m_IsStreamingEnabled = false;
+ }
+
/**
* Close the connection to the data source.
*/
@@ -887,11 +1022,149 @@
}
/**
+ * Close the connection to the data source. Only close the connections
+ * for a single document.
+ */
+ public void close(SQLDocument sqldoc)throws SQLException
+ {
+ if (DEBUG)
+ System.out.println("Entering XConnection.close");
+
+ int size = m_OpenSQLDocuments.size();
+
+ for(int x=0; x<size; x++)
+ {
+ SQLDocument d = (SQLDocument) m_OpenSQLDocuments.elementAt(x);
+ if (d == sqldoc)
+ {
+ d.close();
+ m_OpenSQLDocuments.removeElementAt(x);
+ }
+ }
+ }
+
+ /**
+ * Set the parameter for a Prepared Statement
+ *
+ */
+ public void setParameter(int pos, PreparedStatement stmt, QueryParameter p)
+ throws SQLException
+ {
+ String type = p.getType();
+ if (type.equalsIgnoreCase("string"))
+ {
+ stmt.setString(pos, p.getValue());
+ }
+
+ if (type.equalsIgnoreCase("bigdecimal"))
+ {
+ stmt.setBigDecimal(pos, new BigDecimal(p.getValue()));
+ }
+
+ if (type.equalsIgnoreCase("boolean"))
+ {
+ Integer i = new Integer( p.getValue() );
+ boolean b = ((i.intValue() != 0) ? false : true);
+ stmt.setBoolean(pos, b);
+ }
+
+ if (type.equalsIgnoreCase("bytes"))
+ {
+ stmt.setBytes(pos, p.getValue().getBytes());
+ }
+
+ if (type.equalsIgnoreCase("date"))
+ {
+ stmt.setDate(pos, Date.valueOf(p.getValue()));
+ }
+
+ if (type.equalsIgnoreCase("double"))
+ {
+ Double d = new Double(p.getValue());
+ stmt.setDouble(pos, d.doubleValue() );
+ }
+
+ if (type.equalsIgnoreCase("float"))
+ {
+ Float f = new Float(p.getValue());
+ stmt.setFloat(pos, f.floatValue());
+ }
+
+ if (type.equalsIgnoreCase("long"))
+ {
+ Long l = new Long(p.getValue());
+ stmt.setLong(pos, l.longValue());
+ }
+
+ if (type.equalsIgnoreCase("short"))
+ {
+ Short s = new Short(p.getValue());
+ stmt.setShort(pos, s.shortValue());
+ }
+
+ if (type.equalsIgnoreCase("time"))
+ {
+ stmt.setTime(pos, Time.valueOf(p.getValue()) );
+ }
+
+ if (type.equalsIgnoreCase("timestamp"))
+ {
+
+ stmt.setTimestamp(pos, Timestamp.valueOf(p.getValue()) );
+ }
+
+ }
+
+ private void buildErrorDocument(ExpressionContext exprContext,
SQLException excp)
+ {
+ try
+ {
+ DTMManager mgr =
+ ((XPathContext.XPathExpressionContext)exprContext).getDTMManager();
+ DTMManagerDefault mgrDefault = (DTMManagerDefault) mgr;
+ int dtmIdent = mgrDefault.getFirstFreeDTMID();
+
+ m_Error = new SQLErrorDocument(mgr, dtmIdent, excp);
+
+ }
+ catch(Exception e)
+ {
+ m_Error = null;
+ }
+ }
+
+ private void buildErrorDocument(ExpressionContext exprContext, Exception
excp)
+ {
+ try
+ {
+ DTMManager mgr =
+ ((XPathContext.XPathExpressionContext)exprContext).getDTMManager();
+ DTMManagerDefault mgrDefault = (DTMManagerDefault) mgr;
+ int dtmIdent = mgrDefault.getFirstFreeDTMID();
+
+ m_Error = new SQLErrorDocument(mgr, dtmIdent, excp);
+
+ }
+ catch(Exception e)
+ {
+ m_Error = null;
+ }
+ }
+
+ /**
* @return
*/
protected void finalize( )
{
if (DEBUG) System.out.println("In XConnection, finalize");
+ try
+ {
+ close();
+ }
+ catch(Exception e)
+ {
+ // Empty We are final Anyway
+ }
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]