sqldocument.java
来自「java jdk 1.4的源码」· Java 代码 · 共 871 行 · 第 1/2 页
JAVA
871 行
addAttributeToNode( new Integer(meta.getColumnType(i)), m_ColAttrib_COLUMN_TYPE_TypeID, lastColHeaderIdx); } catch(Exception e) { addAttributeToNode( S_ATTRIB_NOT_SUPPORTED, m_ColAttrib_COLUMN_TYPE_TypeID, lastColHeaderIdx); } try { addAttributeToNode( meta.getColumnTypeName(i), m_ColAttrib_COLUMN_TYPENAME_TypeID, lastColHeaderIdx); } catch(Exception e) { addAttributeToNode( S_ATTRIB_NOT_SUPPORTED, m_ColAttrib_COLUMN_TYPENAME_TypeID, lastColHeaderIdx); } try { addAttributeToNode( new Integer(meta.getPrecision(i)), m_ColAttrib_PRECISION_TypeID, lastColHeaderIdx); } catch(Exception e) { addAttributeToNode( S_ATTRIB_NOT_SUPPORTED, m_ColAttrib_PRECISION_TypeID, lastColHeaderIdx); } try { addAttributeToNode( new Integer(meta.getScale(i)), m_ColAttrib_SCALE_TypeID, lastColHeaderIdx); } catch(Exception e) { addAttributeToNode( S_ATTRIB_NOT_SUPPORTED, m_ColAttrib_SCALE_TypeID, lastColHeaderIdx); } try { addAttributeToNode( meta.getSchemaName(i), m_ColAttrib_SCHEMA_NAME_TypeID, lastColHeaderIdx); } catch(Exception e) { addAttributeToNode( S_ATTRIB_NOT_SUPPORTED, m_ColAttrib_SCHEMA_NAME_TypeID, lastColHeaderIdx); } try { addAttributeToNode( meta.getTableName(i), m_ColAttrib_TABLE_NAME_TypeID, lastColHeaderIdx); } catch(Exception e) { addAttributeToNode( S_ATTRIB_NOT_SUPPORTED, m_ColAttrib_TABLE_NAME_TypeID, lastColHeaderIdx); } try { addAttributeToNode( meta.isCaseSensitive(i) ? S_ISTRUE : S_ISFALSE, m_ColAttrib_CASESENSITIVE_TypeID, lastColHeaderIdx); } catch(Exception e) { addAttributeToNode( S_ATTRIB_NOT_SUPPORTED, m_ColAttrib_CASESENSITIVE_TypeID, lastColHeaderIdx); } try { addAttributeToNode( meta.isDefinitelyWritable(i) ? S_ISTRUE : S_ISFALSE, m_ColAttrib_DEFINITLEYWRITEABLE_TypeID, lastColHeaderIdx); } catch(Exception e) { addAttributeToNode( S_ATTRIB_NOT_SUPPORTED, m_ColAttrib_DEFINITLEYWRITEABLE_TypeID, lastColHeaderIdx); } try { addAttributeToNode( meta.isNullable(i) != 0 ? S_ISTRUE : S_ISFALSE, m_ColAttrib_ISNULLABLE_TypeID, lastColHeaderIdx); } catch(Exception e) { addAttributeToNode( S_ATTRIB_NOT_SUPPORTED, m_ColAttrib_ISNULLABLE_TypeID, lastColHeaderIdx); } try { addAttributeToNode( meta.isSigned(i) ? S_ISTRUE : S_ISFALSE, m_ColAttrib_ISSIGNED_TypeID, lastColHeaderIdx); } catch(Exception e) { addAttributeToNode( S_ATTRIB_NOT_SUPPORTED, m_ColAttrib_ISSIGNED_TypeID, lastColHeaderIdx); } try { addAttributeToNode( meta.isWritable(i) == true ? S_ISTRUE : S_ISFALSE, m_ColAttrib_ISWRITEABLE_TypeID, lastColHeaderIdx); } catch(Exception e) { addAttributeToNode( S_ATTRIB_NOT_SUPPORTED, m_ColAttrib_ISWRITEABLE_TypeID, lastColHeaderIdx); } try { addAttributeToNode( meta.isSearchable(i) == true ? S_ISTRUE : S_ISFALSE, m_ColAttrib_ISSEARCHABLE_TypeID, lastColHeaderIdx); } catch(Exception e) { addAttributeToNode( S_ATTRIB_NOT_SUPPORTED, m_ColAttrib_ISSEARCHABLE_TypeID, lastColHeaderIdx); } } } /** * Populate the Expanded Name Table with the Node that we will use. * Keep a reference of each of the types for access speed. * @return */ protected void createExpandedNameTable( ) { super.createExpandedNameTable(); m_SQL_TypeID = m_expandedNameTable.getExpandedTypeID(S_NAMESPACE, S_SQL, DTM.ELEMENT_NODE); m_MetaData_TypeID = m_expandedNameTable.getExpandedTypeID(S_NAMESPACE, S_METADATA, DTM.ELEMENT_NODE); m_ColumnHeader_TypeID = m_expandedNameTable.getExpandedTypeID(S_NAMESPACE, S_COLUMN_HEADER, DTM.ELEMENT_NODE); m_RowSet_TypeID = m_expandedNameTable.getExpandedTypeID(S_NAMESPACE, S_ROW_SET, DTM.ELEMENT_NODE); m_Row_TypeID = m_expandedNameTable.getExpandedTypeID(S_NAMESPACE, S_ROW, DTM.ELEMENT_NODE); m_Col_TypeID = m_expandedNameTable.getExpandedTypeID(S_NAMESPACE, S_COL, DTM.ELEMENT_NODE); m_ColAttrib_CATALOGUE_NAME_TypeID = m_expandedNameTable.getExpandedTypeID(S_NAMESPACE, S_CATALOGUE_NAME, DTM.ATTRIBUTE_NODE); m_ColAttrib_DISPLAY_SIZE_TypeID = m_expandedNameTable.getExpandedTypeID(S_NAMESPACE, S_DISPLAY_SIZE, DTM.ATTRIBUTE_NODE); m_ColAttrib_COLUMN_LABEL_TypeID = m_expandedNameTable.getExpandedTypeID(S_NAMESPACE, S_COLUMN_LABEL, DTM.ATTRIBUTE_NODE); m_ColAttrib_COLUMN_NAME_TypeID = m_expandedNameTable.getExpandedTypeID(S_NAMESPACE, S_COLUMN_NAME, DTM.ATTRIBUTE_NODE); m_ColAttrib_COLUMN_TYPE_TypeID = m_expandedNameTable.getExpandedTypeID(S_NAMESPACE, S_COLUMN_TYPE, DTM.ATTRIBUTE_NODE); m_ColAttrib_COLUMN_TYPENAME_TypeID = m_expandedNameTable.getExpandedTypeID(S_NAMESPACE, S_COLUMN_TYPENAME, DTM.ATTRIBUTE_NODE); m_ColAttrib_PRECISION_TypeID = m_expandedNameTable.getExpandedTypeID(S_NAMESPACE, S_PRECISION, DTM.ATTRIBUTE_NODE); m_ColAttrib_SCALE_TypeID = m_expandedNameTable.getExpandedTypeID(S_NAMESPACE, S_SCALE, DTM.ATTRIBUTE_NODE); m_ColAttrib_SCHEMA_NAME_TypeID = m_expandedNameTable.getExpandedTypeID(S_NAMESPACE, S_SCHEMA_NAME, DTM.ATTRIBUTE_NODE); m_ColAttrib_TABLE_NAME_TypeID = m_expandedNameTable.getExpandedTypeID(S_NAMESPACE, S_TABLE_NAME, DTM.ATTRIBUTE_NODE); m_ColAttrib_CASESENSITIVE_TypeID = m_expandedNameTable.getExpandedTypeID(S_NAMESPACE, S_CASESENSITIVE, DTM.ATTRIBUTE_NODE); m_ColAttrib_DEFINITLEYWRITEABLE_TypeID = m_expandedNameTable.getExpandedTypeID(S_NAMESPACE, S_DEFINITLEYWRITABLE, DTM.ATTRIBUTE_NODE); m_ColAttrib_ISNULLABLE_TypeID = m_expandedNameTable.getExpandedTypeID(S_NAMESPACE, S_ISNULLABLE, DTM.ATTRIBUTE_NODE); m_ColAttrib_ISSIGNED_TypeID = m_expandedNameTable.getExpandedTypeID(S_NAMESPACE, S_ISSIGNED, DTM.ATTRIBUTE_NODE); m_ColAttrib_ISWRITEABLE_TypeID = m_expandedNameTable.getExpandedTypeID(S_NAMESPACE, S_ISWRITEABLE, DTM.ATTRIBUTE_NODE); m_ColAttrib_ISSEARCHABLE_TypeID = m_expandedNameTable.getExpandedTypeID(S_NAMESPACE, S_ISSEARCHABLE, DTM.ATTRIBUTE_NODE); } /** * 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. * @return */ private boolean addRowToDTMFromResultSet( ) { try { // If we have not started the RowSet yet, then add it to the // tree. if (m_RowSetIdx == DTM.NULL) { m_RowSetIdx = addElement(1, m_RowSet_TypeID, m_SQLIdx, m_MetaDataIdx); } // 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. Only do this if we have statted the loop to begin with. if (m_StreamingMode && (m_LastRowIdx != DTM.NULL)) { // We are at the end, so let's untie the mark m_nextsib.setElementAt(DTM.NULL, m_LastRowIdx); } 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, DTM.NULL); m_LastRowIdx = m_FirstRowIdx; if (m_StreamingMode) { // Let's tie the rows together until the end. m_nextsib.setElementAt(m_LastRowIdx, m_LastRowIdx); } } else { // // 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); // 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++) { // Just grab the Column Object Type, we will convert it to a string // later. Object o = m_ResultSet.getObject(i); // 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() + "]"); } // Only do a single row... return true; } /** * Clean up our ties to the database but this does not necessarly * clean up the document. * @return */ public void close( ) { if (DEBUG) System.out.println("close()"); try { if (null != m_ResultSet) m_ResultSet.close(); } catch(Exception e) { } try { if (null != m_Statement) m_Statement.close(); } catch(Exception e) { } try { if (null != m_Connection) m_ConnectionPool.releaseConnection(m_Connection); } catch(Exception e) { } } /** * When an error occurs, the XConnection will call this method * do that we can deal with the Connection properly * @return */ public void closeOnError( ) { if (DEBUG) System.out.println("close()"); try { if (null != m_ResultSet) m_ResultSet.close(); } catch(Exception e) { } try { if (null != m_Statement) m_Statement.close(); } catch(Exception e) { } try { if (null != m_Connection) m_ConnectionPool.releaseConnectionOnError(m_Connection); } catch(Exception e) { } } /** * @return */ protected boolean nextNode( ) { if (DEBUG) System.out.println("nextNode()"); try { return false;// return m_ResultSet.isAfterLast(); } catch(Exception e) { return false; } } /** * @param identity * @return */ protected int _nextsib( int identity ) { // 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. // int id = _exptype(identity); if ( ( id == m_Row_TypeID) && (identity >= m_LastRowIdx)) { if (DEBUG) System.out.println("reading from the ResultSet"); addRowToDTMFromResultSet(); } return super._nextsib(identity); } public void documentRegistration() { if (DEBUG) System.out.println("Document Registration"); } public void documentRelease() { if (DEBUG) System.out.println("Document Release"); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?