org.apache.xalan.lib.sql
Class SQLDocument

java.lang.Object
  extended by org.apache.xml.dtm.ref.DTMDefaultBase
      extended by org.apache.xml.dtm.ref.DTMDefaultBaseTraversers
          extended by org.apache.xml.dtm.ref.DTMDefaultBaseIterators
              extended by org.apache.xalan.lib.sql.DTMDocument
                  extended by org.apache.xalan.lib.sql.SQLDocument
All Implemented Interfaces:
DTM

public class SQLDocument
extends DTMDocument

The SQL Document is the main controlling class the executesa SQL Query


Nested Class Summary
 
Nested classes/interfaces inherited from class org.apache.xalan.lib.sql.DTMDocument
DTMDocument.CharacterNodeHandler
 
Nested classes/interfaces inherited from class org.apache.xml.dtm.ref.DTMDefaultBaseIterators
DTMDefaultBaseIterators.AncestorIterator, DTMDefaultBaseIterators.AttributeIterator, DTMDefaultBaseIterators.ChildrenIterator, DTMDefaultBaseIterators.DescendantIterator, DTMDefaultBaseIterators.FollowingIterator, DTMDefaultBaseIterators.FollowingSiblingIterator, DTMDefaultBaseIterators.InternalAxisIteratorBase, DTMDefaultBaseIterators.NamespaceAttributeIterator, DTMDefaultBaseIterators.NamespaceChildrenIterator, DTMDefaultBaseIterators.NamespaceIterator, DTMDefaultBaseIterators.NthDescendantIterator, DTMDefaultBaseIterators.ParentIterator, DTMDefaultBaseIterators.PrecedingIterator, DTMDefaultBaseIterators.PrecedingSiblingIterator, DTMDefaultBaseIterators.RootIterator, DTMDefaultBaseIterators.SingletonIterator, DTMDefaultBaseIterators.TypedAncestorIterator, DTMDefaultBaseIterators.TypedAttributeIterator, DTMDefaultBaseIterators.TypedChildrenIterator, DTMDefaultBaseIterators.TypedDescendantIterator, DTMDefaultBaseIterators.TypedFollowingIterator, DTMDefaultBaseIterators.TypedFollowingSiblingIterator, DTMDefaultBaseIterators.TypedNamespaceIterator, DTMDefaultBaseIterators.TypedPrecedingIterator, DTMDefaultBaseIterators.TypedPrecedingSiblingIterator, DTMDefaultBaseIterators.TypedRootIterator, DTMDefaultBaseIterators.TypedSingletonIterator
 
Field Summary
private  boolean DEBUG
           
private  int m_Col_TypeID
           
private  int m_ColAttrib_CASESENSITIVE_TypeID
           
private  int m_ColAttrib_CATALOGUE_NAME_TypeID
           
private  int m_ColAttrib_COLUMN_LABEL_TypeID
           
private  int m_ColAttrib_COLUMN_NAME_TypeID
           
private  int m_ColAttrib_COLUMN_TYPE_TypeID
           
private  int m_ColAttrib_COLUMN_TYPENAME_TypeID
           
private  int m_ColAttrib_DEFINITELYWRITEABLE_TypeID
           
private  int m_ColAttrib_DISPLAY_SIZE_TypeID
           
private  int m_ColAttrib_ISNULLABLE_TypeID
           
private  int m_ColAttrib_ISSEARCHABLE_TypeID
           
private  int m_ColAttrib_ISSIGNED_TypeID
           
private  int m_ColAttrib_ISWRITEABLE_TypeID
           
private  int m_ColAttrib_PRECISION_TypeID
           
private  int m_ColAttrib_SCALE_TypeID
           
private  int m_ColAttrib_SCHEMA_NAME_TypeID
           
private  int m_ColAttrib_TABLE_NAME_TypeID
           
private  int m_ColCount
          An indicator on how many columns are in this query
private  int[] m_ColHeadersIdx
          As the column header array is built, keep the node index for each Column.
private  int m_ColumnHeader_TypeID
           
private  ConnectionPool m_ConnectionPool
          The Connection Pool where we has derived all of our connections for this document
private  ExpressionContext m_ExpressionContext
          Expression COntext used to creat this document may be used to grab variables from the XSL processor
private  int m_FirstRowIdx
          Demark the first row element where we started adding rows into the Document.
private  boolean m_HasErrors
          Flag to detect if an error occured during an operation Defines how errors are handled and how the SQL Connection is closed.
private  boolean m_IsStatementCachingEnabled
          Is statement caching enabled.
private  int m_LastRowIdx
          Keep track of the Last row inserted into the DTM from the ResultSet.
private  int m_MetaData_TypeID
           
private  int m_MetaDataIdx
          The Index of the MetaData Node.
private  boolean m_MultipleResults
          Multiple Result sets mode (metadata inside rowset).
private  int m_OutParameter_TypeID
           
private  SQLQueryParser m_QueryParser
          The parameter definitions if this is a callable statement with output parameters.
private  java.sql.ResultSet m_ResultSet
          The current ResultSet.
private  int m_Row_TypeID
           
private  int m_RowSet_TypeID
           
private  int m_RowSetIdx
          The index of the Row Set node.
private  int m_SQL_TypeID
           
private  int m_SQLIdx
           
private  java.sql.Statement m_Statement
          The Statement used to extract the data from the database connection.
private  boolean m_StreamingMode
          Streaming Mode Control, In Streaming mode we reduce the memory footprint since we only use a single row instance.
private  XConnection m_XConnection
          XConnection this document came from.
private static java.lang.String S_CASESENSITIVE
           
private static java.lang.String S_CATALOGUE_NAME
           
private static java.lang.String S_COL
           
private static java.lang.String S_COLUMN_HEADER
           
private static java.lang.String S_COLUMN_LABEL
           
private static java.lang.String S_COLUMN_NAME
           
private static java.lang.String S_COLUMN_TYPE
           
private static java.lang.String S_COLUMN_TYPENAME
           
private static java.lang.String S_DEFINITELYWRITABLE
           
private static java.lang.String S_DISPLAY_SIZE
           
private static java.lang.String S_ISNULLABLE
           
private static java.lang.String S_ISSEARCHABLE
           
private static java.lang.String S_ISSIGNED
           
private static java.lang.String S_ISWRITEABLE
           
private static java.lang.String S_METADATA
           
private static java.lang.String S_NAMESPACE
           
private static java.lang.String S_OUT_PARAMETERS
           
private static java.lang.String S_PRECISION
           
private static java.lang.String S_ROW
           
private static java.lang.String S_ROW_SET
           
private static java.lang.String S_SCALE
           
private static java.lang.String S_SCHEMA_NAME
           
private static java.lang.String S_SQL
           
private static java.lang.String S_TABLE_NAME
           
 
Fields inherited from class org.apache.xalan.lib.sql.DTMDocument
m_attribute, m_Document_TypeID, m_DocumentIdx, m_ObjectArray, m_TextNode_TypeID, S_ATTRIB_NOT_SUPPORTED, S_DOCUMENT, S_ELEMENT_NODE, S_ISFALSE, S_ISTRUE, S_TEXT_NODE
 
Fields inherited from class org.apache.xml.dtm.ref.DTMDefaultBase
DEFAULT_BLOCKSIZE, DEFAULT_NUMBLOCKS, DEFAULT_NUMBLOCKS_SMALL, m_documentBaseURI, m_dtmIdent, m_elemIndexes, m_expandedNameTable, m_exptype, m_firstch, m_indexing, m_mgr, m_mgrDefault, m_namespaceDeclSetElements, m_namespaceDeclSets, m_nextsib, m_parent, m_prevsib, m_shouldStripWhitespaceStack, m_shouldStripWS, m_size, m_traversers, m_wsfilter, m_xstrf, NOTPROCESSED, ROOTNODE
 
Fields inherited from interface org.apache.xml.dtm.DTM
ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_TYPE_NODE, ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE, NAMESPACE_NODE, NOTATION_NODE, NTYPES, NULL, PROCESSING_INSTRUCTION_NODE, ROOT_NODE, TEXT_NODE
 
Constructor Summary
SQLDocument(DTMManager mgr, int ident)
           
 
Method Summary
protected  int _nextsib(int identity)
          Get the next sibling for the given node identity.
private  boolean addRowToDTMFromResultSet()
          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.
 java.sql.SQLWarning checkWarnings()
           
 void close(boolean flushConnPool)
          Close down any resources used by this document.
protected  void createExpandedNameTable()
          Populate the Expanded Name Table with the Node that we will use.
 void documentRegistration()
          A dummy routine to satisify the abstract interface.
 void documentRelease()
          A dummy routine to satisify the abstract interface.
 void execute(XConnection xconn, SQLQueryParser query)
           
private  void executeSQLStatement()
           
private  void extractSQLMetaData(java.sql.ResultSetMetaData meta)
          Extract the Meta Data and build the Column Attribute List.
 ExpressionContext getExpressionContext()
          Return the context used to build this document
static SQLDocument getNewDocument(ExpressionContext exprContext)
          This static method simplifies the creation of an SQL Document and allows us to embedd the complexity of creating / handling the dtmIdent inside the document.
 boolean hasErrors()
          Used by the XConnection to determine if the Document should handle the document differently.
protected  boolean nextNode()
          This method should try and build one or more nodes in the table.
protected  void setExpressionContext(ExpressionContext expr)
          When building the SQL Document, we need to store the Expression Context that was used to create the document.
 void skip(int value)
          Push the record set forward value rows.
 
Methods inherited from class org.apache.xalan.lib.sql.DTMDocument
_exptype, _firstch, _level, _parent, _prevsib, _type, addAttributeToNode, addElement, addElementWithData, appendChild, appendTextChild, cloneAttributeFromNode, declareNamespaceInContext, dispatchCharactersEvents, dispatchNodeData, dispatchToEvents, dumpDTM, ensureSize, ensureSizeOfIndex, error, findGTE, findInSortedSuballocatedIntVector, findNamespaceContext, getAttributeNode, getAxisIterator, getAxisTraverser, getContentHandler, getDeclHandler, getDocument, getDocumentAllDeclarationsProcessed, getDocumentBaseURI, getDocumentEncoding, getDocumentStandalone, getDocumentSystemIdentifier, getDocumentTypeDeclarationPublicIdentifier, getDocumentTypeDeclarationSystemIdentifier, getDocumentVersion, getDTDHandler, getElementById, getEntityResolver, getErrorHandler, getExpandedTypeID, getExpandedTypeID, getFirstAttribute, getFirstChild, getFirstNamespaceNode, getLastChild, getLevel, getLexicalHandler, getLocalName, getLocalNameFromExpandedNameID, getNamespaceFromExpandedNameID, getNamespaceType, getNamespaceURI, getNextAttribute, getNextNamespaceNode, getNextNodeIdentity, getNextSibling, getNode, getNodeData, getNodeName, getNodeNameX, getNodeType, getNodeValue, getNumberOfNodes, getOwnerDocument, getParent, getPrefix, getPreviousSibling, getShouldStripWhitespace, getSourceLocatorFor, getStringValue, getStringValueChunk, getStringValueChunkCount, getTypedAxisIterator, getUnparsedEntityURI, hasChildNodes, indexNode, isAttributeSpecified, isCharacterElementContentWhitespace, isDocumentAllDeclarationsProcessed, isNodeAfter, isSupported, needsTwoThreads, popShouldStripWhitespace, pushShouldStripWhitespace, setDocumentBaseURI, setFeature, setProperty, setShouldStripWhitespace, supportsPreStripping
 
Methods inherited from class org.apache.xml.dtm.ref.DTMDefaultBase
dumpDTM, dumpNode, getDocumentRoot, getDTMIDs, getFirstAttributeIdentity, getManager, getNextAttributeIdentity, getNodeHandle, getNodeIdent, getTypedAttribute, getTypedFirstChild, getTypedNextSibling, makeNodeHandle, makeNodeIdentity, migrateTo
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

private boolean DEBUG

S_NAMESPACE

private static final java.lang.String S_NAMESPACE
See Also:
Constant Field Values

S_SQL

private static final java.lang.String S_SQL
See Also:
Constant Field Values

S_ROW_SET

private static final java.lang.String S_ROW_SET
See Also:
Constant Field Values

S_METADATA

private static final java.lang.String S_METADATA
See Also:
Constant Field Values

S_COLUMN_HEADER

private static final java.lang.String S_COLUMN_HEADER
See Also:
Constant Field Values

S_ROW

private static final java.lang.String S_ROW
See Also:
Constant Field Values

S_COL

private static final java.lang.String S_COL
See Also:
Constant Field Values

S_OUT_PARAMETERS

private static final java.lang.String S_OUT_PARAMETERS
See Also:
Constant Field Values

S_CATALOGUE_NAME

private static final java.lang.String S_CATALOGUE_NAME
See Also:
Constant Field Values

S_DISPLAY_SIZE

private static final java.lang.String S_DISPLAY_SIZE
See Also:
Constant Field Values

S_COLUMN_LABEL

private static final java.lang.String S_COLUMN_LABEL
See Also:
Constant Field Values

S_COLUMN_NAME

private static final java.lang.String S_COLUMN_NAME
See Also:
Constant Field Values

S_COLUMN_TYPE

private static final java.lang.String S_COLUMN_TYPE
See Also:
Constant Field Values

S_COLUMN_TYPENAME

private static final java.lang.String S_COLUMN_TYPENAME
See Also:
Constant Field Values

S_PRECISION

private static final java.lang.String S_PRECISION
See Also:
Constant Field Values

S_SCALE

private static final java.lang.String S_SCALE
See Also:
Constant Field Values

S_SCHEMA_NAME

private static final java.lang.String S_SCHEMA_NAME
See Also:
Constant Field Values

S_TABLE_NAME

private static final java.lang.String S_TABLE_NAME
See Also:
Constant Field Values

S_CASESENSITIVE

private static final java.lang.String S_CASESENSITIVE
See Also:
Constant Field Values

S_DEFINITELYWRITABLE

private static final java.lang.String S_DEFINITELYWRITABLE
See Also:
Constant Field Values

S_ISNULLABLE

private static final java.lang.String S_ISNULLABLE
See Also:
Constant Field Values

S_ISSIGNED

private static final java.lang.String S_ISSIGNED
See Also:
Constant Field Values

S_ISWRITEABLE

private static final java.lang.String S_ISWRITEABLE
See Also:
Constant Field Values

S_ISSEARCHABLE

private static final java.lang.String S_ISSEARCHABLE
See Also:
Constant Field Values

m_SQL_TypeID

private int m_SQL_TypeID

m_MetaData_TypeID

private int m_MetaData_TypeID

m_ColumnHeader_TypeID

private int m_ColumnHeader_TypeID

m_RowSet_TypeID

private int m_RowSet_TypeID

m_Row_TypeID

private int m_Row_TypeID

m_Col_TypeID

private int m_Col_TypeID

m_OutParameter_TypeID

private int m_OutParameter_TypeID

m_ColAttrib_CATALOGUE_NAME_TypeID

private int m_ColAttrib_CATALOGUE_NAME_TypeID

m_ColAttrib_DISPLAY_SIZE_TypeID

private int m_ColAttrib_DISPLAY_SIZE_TypeID

m_ColAttrib_COLUMN_LABEL_TypeID

private int m_ColAttrib_COLUMN_LABEL_TypeID

m_ColAttrib_COLUMN_NAME_TypeID

private int m_ColAttrib_COLUMN_NAME_TypeID

m_ColAttrib_COLUMN_TYPE_TypeID

private int m_ColAttrib_COLUMN_TYPE_TypeID

m_ColAttrib_COLUMN_TYPENAME_TypeID

private int m_ColAttrib_COLUMN_TYPENAME_TypeID

m_ColAttrib_PRECISION_TypeID

private int m_ColAttrib_PRECISION_TypeID

m_ColAttrib_SCALE_TypeID

private int m_ColAttrib_SCALE_TypeID

m_ColAttrib_SCHEMA_NAME_TypeID

private int m_ColAttrib_SCHEMA_NAME_TypeID

m_ColAttrib_TABLE_NAME_TypeID

private int m_ColAttrib_TABLE_NAME_TypeID

m_ColAttrib_CASESENSITIVE_TypeID

private int m_ColAttrib_CASESENSITIVE_TypeID

m_ColAttrib_DEFINITELYWRITEABLE_TypeID

private int m_ColAttrib_DEFINITELYWRITEABLE_TypeID

m_ColAttrib_ISNULLABLE_TypeID

private int m_ColAttrib_ISNULLABLE_TypeID

m_ColAttrib_ISSIGNED_TypeID

private int m_ColAttrib_ISSIGNED_TypeID

m_ColAttrib_ISWRITEABLE_TypeID

private int m_ColAttrib_ISWRITEABLE_TypeID

m_ColAttrib_ISSEARCHABLE_TypeID

private int m_ColAttrib_ISSEARCHABLE_TypeID

m_Statement

private java.sql.Statement m_Statement
The Statement used to extract the data from the database connection.


m_ExpressionContext

private ExpressionContext m_ExpressionContext
Expression COntext used to creat this document may be used to grab variables from the XSL processor


m_ConnectionPool

private ConnectionPool m_ConnectionPool
The Connection Pool where we has derived all of our connections for this document


m_ResultSet

private java.sql.ResultSet m_ResultSet
The current ResultSet.


m_QueryParser

private SQLQueryParser m_QueryParser
The parameter definitions if this is a callable statement with output parameters.


m_ColHeadersIdx

private int[] m_ColHeadersIdx
As the column header array is built, keep the node index for each Column. The primary use of this is to locate the first attribute for each column in each row as we add records.


m_ColCount

private int m_ColCount
An indicator on how many columns are in this query


m_MetaDataIdx

private int m_MetaDataIdx
The Index of the MetaData Node. Currently the MetaData Node contains the


m_RowSetIdx

private int m_RowSetIdx
The index of the Row Set node. This is the sibling directly after the last Column Header.


m_SQLIdx

private int m_SQLIdx

m_FirstRowIdx

private int m_FirstRowIdx
Demark the first row element where we started adding rows into the Document.


m_LastRowIdx

private int m_LastRowIdx
Keep track of the Last row inserted into the DTM from the ResultSet. This will be used as the index of the parent Row Element when adding a row.


m_StreamingMode

private boolean m_StreamingMode
Streaming Mode Control, In Streaming mode we reduce the memory footprint since we only use a single row instance.


m_MultipleResults

private boolean m_MultipleResults
Multiple Result sets mode (metadata inside rowset).


m_HasErrors

private boolean m_HasErrors
Flag to detect if an error occured during an operation Defines how errors are handled and how the SQL Connection is closed.


m_IsStatementCachingEnabled

private boolean m_IsStatementCachingEnabled
Is statement caching enabled.


m_XConnection

private XConnection m_XConnection
XConnection this document came from.

Constructor Detail

SQLDocument

public SQLDocument(DTMManager mgr,
                   int ident)
Parameters:
mgr -
ident -
Throws:
java.sql.SQLException
Method Detail

getNewDocument

public static SQLDocument getNewDocument(ExpressionContext exprContext)
This static method simplifies the creation of an SQL Document and allows us to embedd the complexity of creating / handling the dtmIdent inside the document. This type of method may better placed inside the DTMDocument code


setExpressionContext

protected void setExpressionContext(ExpressionContext expr)
When building the SQL Document, we need to store the Expression Context that was used to create the document. This will be se to reference items int he XSLT process such as any variables that were present.


getExpressionContext

public ExpressionContext getExpressionContext()
Return the context used to build this document


execute

public void execute(XConnection xconn,
                    SQLQueryParser query)
             throws java.sql.SQLException
Throws:
java.sql.SQLException

executeSQLStatement

private void executeSQLStatement()
                          throws java.sql.SQLException
Throws:
java.sql.SQLException

skip

public void skip(int value)
Push the record set forward value rows. Used to help in SQL pagination.

Parameters:
value -

extractSQLMetaData

private void extractSQLMetaData(java.sql.ResultSetMetaData meta)
Extract the Meta Data and build the Column Attribute List.

Parameters:
meta -

createExpandedNameTable

protected void createExpandedNameTable()
Populate the Expanded Name Table with the Node that we will use. Keep a reference of each of the types for access speed.

Overrides:
createExpandedNameTable in class DTMDocument

addRowToDTMFromResultSet

private boolean addRowToDTMFromResultSet()
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.

Returns:

hasErrors

public boolean hasErrors()
Used by the XConnection to determine if the Document should handle the document differently.


close

public void close(boolean flushConnPool)
Close down any resources used by this document. If an SQL Error occure while the document was being accessed, the SQL Connection used to create this document will be released to the Connection Pool on error. This allows the COnnection Pool to give special attention to any connection that may be in a errored state.


nextNode

protected boolean nextNode()
Description copied from class: DTMDefaultBase
This method should try and build one or more nodes in the table.

Overrides:
nextNode in class DTMDocument
Returns:

_nextsib

protected int _nextsib(int identity)
Description copied from class: DTMDefaultBase
Get the next sibling for the given node identity.

Overrides:
_nextsib in class DTMDocument
Parameters:
identity -
Returns:

documentRegistration

public void documentRegistration()
Description copied from class: DTMDefaultBase
A dummy routine to satisify the abstract interface. If the DTM implememtation that extends the default base requires notification of registration, they can override this method.

Specified by:
documentRegistration in interface DTM
Overrides:
documentRegistration in class DTMDefaultBase

documentRelease

public void documentRelease()
Description copied from class: DTMDefaultBase
A dummy routine to satisify the abstract interface. If the DTM implememtation that extends the default base requires notification when the document is being released, they can override this method

Specified by:
documentRelease in interface DTM
Overrides:
documentRelease in class DTMDefaultBase

checkWarnings

public java.sql.SQLWarning checkWarnings()