uk.org.ogsadai.common
Class WebRowSetXMLStreamToResultSetForwardOnly

java.lang.Object
  |
  +--org.xml.sax.helpers.DefaultHandler
        |
        +--uk.org.ogsadai.common.WebRowSetXMLStreamToResultSet
              |
              +--uk.org.ogsadai.common.WebRowSetXMLStreamToResultSetForwardOnly
All Implemented Interfaces:
org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler, java.sql.ResultSet

public class WebRowSetXMLStreamToResultSetForwardOnly
extends WebRowSetXMLStreamToResultSet

This is a "Forward Only" implementation of the WebRowSetXMLStreamToResultSet adapter class. Thus, the previous(), beforeFirst(), afterLast(), first() and last() methods are unsupported.

This implementation can handle arbitrarily large WebRowSet XML documents. This is achieved by parsing the XML document in a streaming fashion as demanded by calls to the next() method.

Note that this requires an extra thread to be created and all the inter-thread communication means that the time to parse an entire WebRowSet is roughly double the time that the alternative scrollable implementation takes. However, the disadvantage of using the scrollable implementation is that it can only cope with relatively small result sets.

Since this implementation uses a separate thread to parse the WebRowSet XML document, it is important that clients call the terminate() method to perform the necessary clean-up if the ResultSet is no longer required after having only partially parsed the WebRowSet.

Author:
The OGSA-DAI Project Team

Field Summary
 
Fields inherited from class uk.org.ogsadai.common.WebRowSetXMLStreamToResultSet
BASE_STATE, COL, COL_OLD, COL_STATE, COLCOUNT, COLCOUNT_STATE, COLDEFN, COLDEFN_STATE, DATA, DATA_STATE, EMPTY_BLOB, EMPTY_STRING, mCharDataBuffer, mColumnCount, mCommencedParsing, mCurrentColumn, mCurrentElement, mCurrentRow, mCursor, mDataInput, METADATA, METADATA_STATE, mLastColumnRead, mMetaData, mParser, mState, NULL, NULL_STATE, PROPERTIES, PROPERTIES_STATE, ROW, ROW_OLD, ROW_STATE, ROWSET, ROWSET_OLD, ROWSET_STATE
 
Fields inherited from interface java.sql.ResultSet
CLOSE_CURSORS_AT_COMMIT, CONCUR_READ_ONLY, CONCUR_UPDATABLE, FETCH_FORWARD, FETCH_REVERSE, FETCH_UNKNOWN, HOLD_CURSORS_OVER_COMMIT, TYPE_FORWARD_ONLY, TYPE_SCROLL_INSENSITIVE, TYPE_SCROLL_SENSITIVE
 
Constructor Summary
WebRowSetXMLStreamToResultSetForwardOnly(BlockReader reader)
          Constructor which initialises but does not commence parsing.
WebRowSetXMLStreamToResultSetForwardOnly(BlockReader reader, boolean parseNow)
          Constructor with an option to start parsing now.
 
Method Summary
 boolean absolute(int row)
           
 void afterLast()
           
 void beforeFirst()
           
 void characters(char[] ch, int start, int length)
           
 void close()
          Implementation of the ResultSet.close() method.
 void endElement(java.lang.String uri, java.lang.String localName, java.lang.String qName)
          Note that this method is called from within the parser thread.
 void finalize()
          Calls terminate() to perform the necessary clean-up.
 boolean first()
           
protected  java.lang.String getColumnString(int columnIndex)
           
 int getRow()
           
 int getType()
           
 boolean isAfterLast()
           
 boolean isBeforeFirst()
           
 boolean isFirst()
           
 boolean isLast()
           
 boolean last()
           
 boolean next()
           
 void parse()
          Method parse.
 boolean previous()
           
 boolean relative(int row)
           
 void startElement(java.lang.String uri, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes attr)
           
 void terminate()
          Kill the parser thread by interrupting it.
 
Methods inherited from class uk.org.ogsadai.common.WebRowSetXMLStreamToResultSet
cancelRowUpdates, clearWarnings, create, deleteRow, findColumn, getArray, getArray, getAsciiStream, getAsciiStream, getBigDecimal, getBigDecimal, getBigDecimal, getBigDecimal, getBinaryStream, getBinaryStream, getBlob, getBlob, getBoolean, getBoolean, getByte, getByte, getBytes, getBytes, getCharacterStream, getCharacterStream, getClob, getClob, getColumnStringNumeric, getConcurrency, getCursorName, getDate, getDate, getDate, getDate, getDouble, getDouble, getFetchDirection, getFetchSize, getFloat, getFloat, getInt, getInt, getLong, getLong, getMetaData, getObject, getObject, getObject, getObject, getRef, getRef, getShort, getShort, getStatement, getString, getString, getTime, getTime, getTime, getTime, getTimestamp, getTimestamp, getTimestamp, getTimestamp, getUnicodeStream, getUnicodeStream, getURL, getURL, getWarnings, insertRow, moveToCurrentRow, moveToInsertRow, refreshRow, rowDeleted, rowInserted, rowUpdated, setFetchDirection, setFetchSize, updateArray, updateArray, updateAsciiStream, updateAsciiStream, updateBigDecimal, updateBigDecimal, updateBinaryStream, updateBinaryStream, updateBlob, updateBlob, updateBoolean, updateBoolean, updateByte, updateByte, updateBytes, updateBytes, updateCharacterStream, updateCharacterStream, updateClob, updateClob, updateDate, updateDate, updateDouble, updateDouble, updateFloat, updateFloat, updateInt, updateInt, updateLong, updateLong, updateNull, updateNull, updateObject, updateObject, updateObject, updateObject, updateRef, updateRef, updateRow, updateShort, updateShort, updateString, updateString, updateTime, updateTime, updateTimestamp, updateTimestamp, wasNull
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endDocument, endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WebRowSetXMLStreamToResultSetForwardOnly

public WebRowSetXMLStreamToResultSetForwardOnly(BlockReader reader)
Constructor which initialises but does not commence parsing. When using this constructor, you need to call the parse() method in order to commence parsing of the WebRowSet XML data.

Parameters:
reader - the WebRowSet XML data stream

WebRowSetXMLStreamToResultSetForwardOnly

public WebRowSetXMLStreamToResultSetForwardOnly(BlockReader reader,
                                                boolean parseNow)
                                         throws org.xml.sax.SAXException,
                                                java.io.IOException
Constructor with an option to start parsing now. This constructor calls the parse() method after initialisation iff parseNow is true.

Parameters:
reader - the WebRowSet XML data stream
parseNow - true iff the parse() should be invoked after initialisation
Throws:
org.xml.sax.SAXException - if parseNow is true and if there is a problem whilst parsing the XML data
java.io.IOException - if parseNow is true and any IO error occurs
Method Detail

finalize

public void finalize()
              throws java.lang.Throwable
Calls terminate() to perform the necessary clean-up.

Overrides:
finalize in class java.lang.Object
java.lang.Throwable

close

public void close()
           throws java.sql.SQLException
Implementation of the ResultSet.close() method. This method calls the terminate() method to ensure that Threads created by this class are cleaned up.

Specified by:
close in interface java.sql.ResultSet
Overrides:
close in class WebRowSetXMLStreamToResultSet
java.sql.SQLException
See Also:
WebRowSetXMLStreamToResultSet.close()

parse

public void parse()
           throws org.xml.sax.SAXException,
                  java.io.IOException
Method parse.

Overrides:
parse in class WebRowSetXMLStreamToResultSet
Throws:
java.io.IOException - if any IO error occurs
org.xml.sax.SAXException - if there is a problem whilst parsing the XML data

terminate

public void terminate()
Kill the parser thread by interrupting it. The PausableInputStream will catch the InterruptedException and cease its parsing.

Overrides:
terminate in class WebRowSetXMLStreamToResultSet

startElement

public void startElement(java.lang.String uri,
                         java.lang.String localName,
                         java.lang.String qName,
                         org.xml.sax.Attributes attr)
Specified by:
startElement in interface org.xml.sax.ContentHandler
Specified by:
startElement in class WebRowSetXMLStreamToResultSet
See Also:
ContentHandler.startElement(String, String, String, Attributes)

endElement

public void endElement(java.lang.String uri,
                       java.lang.String localName,
                       java.lang.String qName)
                throws org.xml.sax.SAXException
Note that this method is called from within the parser thread.

Specified by:
endElement in interface org.xml.sax.ContentHandler
Specified by:
endElement in class WebRowSetXMLStreamToResultSet
org.xml.sax.SAXException
See Also:
ContentHandler.endElement(String, String, String)

characters

public void characters(char[] ch,
                       int start,
                       int length)
Specified by:
characters in interface org.xml.sax.ContentHandler
Specified by:
characters in class WebRowSetXMLStreamToResultSet
See Also:
ContentHandler.characters(char[], int, int)

getColumnString

protected java.lang.String getColumnString(int columnIndex)
                                    throws java.sql.SQLException
Specified by:
getColumnString in class WebRowSetXMLStreamToResultSet
java.sql.SQLException

getType

public int getType()
            throws java.sql.SQLException
Specified by:
getType in interface java.sql.ResultSet
Specified by:
getType in class WebRowSetXMLStreamToResultSet
java.sql.SQLException
See Also:
ResultSet.getType()

next

public boolean next()
             throws java.sql.SQLException
Specified by:
next in interface java.sql.ResultSet
Specified by:
next in class WebRowSetXMLStreamToResultSet
java.sql.SQLException
See Also:
ResultSet.next()

previous

public boolean previous()
                 throws java.sql.SQLException
Specified by:
previous in interface java.sql.ResultSet
Specified by:
previous in class WebRowSetXMLStreamToResultSet
java.sql.SQLException
See Also:
ResultSet.previous()

absolute

public boolean absolute(int row)
                 throws java.sql.SQLException
Specified by:
absolute in interface java.sql.ResultSet
Specified by:
absolute in class WebRowSetXMLStreamToResultSet
java.sql.SQLException
See Also:
ResultSet.absolute(int)

relative

public boolean relative(int row)
                 throws java.sql.SQLException
Specified by:
relative in interface java.sql.ResultSet
Specified by:
relative in class WebRowSetXMLStreamToResultSet
java.sql.SQLException
See Also:
ResultSet.relative(int)

beforeFirst

public void beforeFirst()
                 throws java.sql.SQLException
Specified by:
beforeFirst in interface java.sql.ResultSet
Specified by:
beforeFirst in class WebRowSetXMLStreamToResultSet
java.sql.SQLException
See Also:
ResultSet.beforeFirst()

afterLast

public void afterLast()
               throws java.sql.SQLException
Specified by:
afterLast in interface java.sql.ResultSet
Specified by:
afterLast in class WebRowSetXMLStreamToResultSet
java.sql.SQLException
See Also:
ResultSet.afterLast()

first

public boolean first()
              throws java.sql.SQLException
Specified by:
first in interface java.sql.ResultSet
Specified by:
first in class WebRowSetXMLStreamToResultSet
java.sql.SQLException
See Also:
ResultSet.first()

last

public boolean last()
             throws java.sql.SQLException
Specified by:
last in interface java.sql.ResultSet
Specified by:
last in class WebRowSetXMLStreamToResultSet
java.sql.SQLException
See Also:
ResultSet.last()

isBeforeFirst

public boolean isBeforeFirst()
                      throws java.sql.SQLException
Specified by:
isBeforeFirst in interface java.sql.ResultSet
Specified by:
isBeforeFirst in class WebRowSetXMLStreamToResultSet
java.sql.SQLException
See Also:
ResultSet.isBeforeFirst()

isAfterLast

public boolean isAfterLast()
                    throws java.sql.SQLException
Specified by:
isAfterLast in interface java.sql.ResultSet
Specified by:
isAfterLast in class WebRowSetXMLStreamToResultSet
java.sql.SQLException
See Also:
ResultSet.isAfterLast()

isFirst

public boolean isFirst()
                throws java.sql.SQLException
Specified by:
isFirst in interface java.sql.ResultSet
Specified by:
isFirst in class WebRowSetXMLStreamToResultSet
java.sql.SQLException
See Also:
ResultSet.isFirst()

isLast

public boolean isLast()
               throws java.sql.SQLException
Specified by:
isLast in interface java.sql.ResultSet
Specified by:
isLast in class WebRowSetXMLStreamToResultSet
java.sql.SQLException
See Also:
ResultSet.isLast()

getRow

public int getRow()
           throws java.sql.SQLException
Specified by:
getRow in interface java.sql.ResultSet
Overrides:
getRow in class WebRowSetXMLStreamToResultSet
java.sql.SQLException
See Also:
ResultSet.getRow()