📄 netcursor.java
字号:
skipFdocaBytes(2); // skip single length } else { varcharLength = readFdocaTwoByteLength(); // read single length sqlerrmc = readFdocaBytes(varcharLength); // read single bytes sqlerrmcCcsid = typdef.getCcsidSbc(); } netSqlca.setSqlerrd(sqlerrd); netSqlca.setSqlwarnBytes(sqlwarn); netSqlca.setSqlerrmcBytes(sqlerrmc, sqlerrmcCcsid); } // SQLDIAGGRP : FDOCA EARLY GROUP private void parseSQLDIAGGRP() throws DisconnectException, SqlException { if (readFdocaOneByte() == CodePoint.NULLDATA) { return; } netAgent_.accumulateChainBreakingReadExceptionAndThrow(new DisconnectException(netAgent_, "parseSQLDIAGGRP not yet implemented")); } private String parseVCS(Typdef typdefInEffect) throws DisconnectException, SqlException { return readFdocaString(readFdocaTwoByteLength(), typdefInEffect.getCcsidSbcEncoding()); } // This is not used for column data. private String readFdocaString(int length, String encoding) throws DisconnectException, SqlException { if (length == 0) { return null; } // For singleton select, the complete row always comes back, even if multiple query blocks are required, // so there is no need to drive a flowFetch (continue query) request for singleton select. if ((position_ + length) > lastValidBytePosition_) { // Check for ENDQRYRM, throw SqlException if already received one. checkAndThrowReceivedEndqryrm(); // Send CNTQRY to complete the row/rowset. int lastValidByteBeforeFetch = completeSplitRow(); // if lastValidBytePosition_ has not changed, and an ENDQRYRM was received, // throw a SqlException for the ENDQRYRM. checkAndThrowReceivedEndqryrm(lastValidByteBeforeFetch); } String s = null; try { s = new String(dataBuffer_, position_, length, encoding); } catch (java.io.UnsupportedEncodingException e) { netAgent_.accumulateChainBreakingReadExceptionAndThrow(new org.apache.derby.client.am.DisconnectException(e, netAgent_, "encoding not supported!!")); } position_ += length; return s; } void allocateColumnOffsetAndLengthArrays() { columnDataPosition_ = new int[columns_]; columnDataComputedLength_ = new int[columns_]; isNull_ = new boolean[columns_]; } void setBlocking(int queryProtocolType) { if (queryProtocolType == CodePoint.LMTBLKPRC) { blocking_ = true; } else { blocking_ = false; } } protected byte[] findExtdtaData(int column) { byte[] data = null; // locate the EXTDTA bytes, if any Integer key = new Integer(column); if (extdtaPositions_.containsKey(key)) { // found, get the data int extdtaQueuePosition = ((Integer) extdtaPositions_.get(key)).intValue(); data = (byte[]) (extdtaData_.get(extdtaQueuePosition)); } return data; } public Blob getBlobColumn_(int column, Agent agent) throws SqlException { int index = column - 1; int dataOffset; byte[] data; Blob blob = null; // locate the EXTDTA bytes, if any data = findExtdtaData(column); if (data != null) { // data found // set data offset based on the presence of a null indicator if (!nullable_[index]) { dataOffset = 0; } else { dataOffset = 1; } blob = new Blob(data, agent, dataOffset); } else { blob = new Blob(new byte[0], agent, 0); } return blob; } public Clob getClobColumn_(int column, Agent agent) throws SqlException { int index = column - 1; int dataOffset; byte[] data; Clob clob = null; // locate the EXTDTA bytes, if any data = findExtdtaData(column); if (data != null) { // data found // set data offset based on the presence of a null indicator if (!nullable_[index]) { dataOffset = 0; } else { dataOffset = 1; } clob = new Clob(agent, data, charsetName_[index], dataOffset); } else { // the locator is not valid, it is a zero-length LOB clob = new Clob(agent, ""); } return clob; } public byte[] getClobBytes_(int column, int[] dataOffset /*output*/) throws SqlException { int index = column - 1; byte[] data = null; // locate the EXTDTA bytes, if any data = findExtdtaData(column); if (data != null) { // data found // set data offset based on the presence of a null indicator if (!nullable_[index]) { dataOffset[0] = 0; } else { dataOffset[0] = 1; } } return data; } // this is really an event-callback from NetStatementReply.parseSQLDTARDarray() void initializeColumnInfoArrays(Typdef typdef, int columnCount, int targetSqlamForTypdef) throws DisconnectException { qrydscTypdef_ = typdef; // Allocate arrays to hold the descriptor information. setNumberOfColumns(columnCount); fdocaLength_ = new int[columnCount]; isGraphic_ = new boolean[columnCount]; typeToUseForComputingDataLength_ = new int[columnCount]; targetSqlamForTypdef_ = targetSqlamForTypdef; } int ensureSpaceForDataBuffer(int ddmLength) { if (dataBuffer_ == null) { allocateDataBuffer(); } //super.resultSet.cursor.clearColumnDataOffsetsCache(); // Need to know how many bytes to ask from the Reply object, // and handle the case where buffer is not big enough for all the bytes. // Get the length in front of the code point first. int bytesAvailableInDataBuffer = dataBuffer_.length - lastValidBytePosition_; // Make sure the buffer has at least ddmLength amount of room left. // If not, expand the buffer before calling the getQrydtaData() method. if (bytesAvailableInDataBuffer < ddmLength) { // Get a new buffer that is twice the size of the current buffer. // Copy the contents from the old buffer to the new buffer. int newBufferSize = 2 * dataBuffer_.length; while (newBufferSize < ddmLength) { newBufferSize = 2 * newBufferSize; } byte[] tempBuffer = new byte[newBufferSize]; System.arraycopy(dataBuffer_, 0, tempBuffer, 0, lastValidBytePosition_); // Make the new buffer the dataBuffer. dataBuffer_ = tempBuffer; // Recalculate bytesAvailableInDataBuffer bytesAvailableInDataBuffer = dataBuffer_.length - lastValidBytePosition_; } return bytesAvailableInDataBuffer; } protected void getMoreData_() throws SqlException { // reset the dataBuffer_ before getting more data if cursor is foward-only. // getMoreData() is only called in Cursor.next() when current position is // equal to lastValidBytePosition_. if (netResultSet_.resultSetType_ == java.sql.ResultSet.TYPE_FORWARD_ONLY) { resetDataBuffer(); } netResultSet_.flowFetch(); } public void nullDataForGC() // memory leak fix { super.nullDataForGC(); qrydscTypdef_ = null; typeToUseForComputingDataLength_ = null; isGraphic_ = null; if (extdtaPositions_ != null) { extdtaPositions_.clear(); } extdtaPositions_ = null; if (extdtaData_ != null) { extdtaData_.clear(); } extdtaData_ = null; } // It is possible for the driver to have received an QRYDTA(with incomplete row)+ENDQRYRM+SQLCARD. // This means some error has occurred on the server and the server is terminating the query. // Before sending a CNTQRY to retrieve the rest of the split row, check if an ENDQRYRM has already // been received. If so, do not send CNTQRY because the cursor is already closed on the server. // Instead, throw a SqlException. Since we did not receive a complete row, it is not safe to // allow the application to continue to access the ResultSet, so we close it. private void checkAndThrowReceivedEndqryrm() throws SqlException { // If we are in a split row, and before sending CNTQRY, check whether an ENDQRYRM // has been received. if (!netResultSet_.openOnServer_) { SqlException sqlException = null; int sqlcode = org.apache.derby.client.am.Utils.getSqlcodeFromSqlca(netResultSet_.queryTerminatingSqlca_); if (sqlcode < 0) { sqlException = new SqlException(agent_.logWriter_, netResultSet_.queryTerminatingSqlca_); } else { sqlException = new SqlException(agent_.logWriter_, "Query processing has been terminated due to error on the server."); } try { netResultSet_.closeX(); // the auto commit logic is in closeX() } catch (SqlException e) { sqlException.setNextException(e); } throw sqlException; } } private void checkAndThrowReceivedEndqryrm(int lastValidBytePositionBeforeFetch) throws SqlException { // if we have received more data in the dataBuffer_, just return. if (lastValidBytePosition_ > lastValidBytePositionBeforeFetch) { return; } checkAndThrowReceivedEndqryrm(); } private int completeSplitRow() throws DisconnectException, SqlException { int lastValidBytePositionBeforeFetch = 0; if (netResultSet_ != null && netResultSet_.scrollable_) { lastValidBytePositionBeforeFetch = lastValidBytePosition_; netResultSet_.flowFetchToCompleteRowset(); } else { // Shift partial row to the beginning of the dataBuffer shiftPartialRowToBeginning(); resetCurrentRowPosition(); lastValidBytePositionBeforeFetch = lastValidBytePosition_; netResultSet_.flowFetch(); } return lastValidBytePositionBeforeFetch; } private int completeSplitRow(int index) throws DisconnectException, SqlException { int lastValidBytePositionBeforeFetch = 0; if (netResultSet_ != null && netResultSet_.scrollable_) { lastValidBytePositionBeforeFetch = lastValidBytePosition_; netResultSet_.flowFetchToCompleteRowset(); } else { // Shift partial row to the beginning of the dataBuffer shiftPartialRowToBeginning(); adjustColumnOffsetsForColumnsPreviouslyCalculated(index); resetCurrentRowPosition(); lastValidBytePositionBeforeFetch = lastValidBytePosition_; netResultSet_.flowFetch(); } return lastValidBytePositionBeforeFetch; } private int[] allocateColumnDataPositionArray(int row) { int[] columnDataPosition; if (columnDataPositionCache_.size() == row) { columnDataPosition = new int[columns_]; columnDataPositionCache_.add(columnDataPosition); } else { columnDataPosition = (int[]) columnDataPositionCache_.get(row); } return columnDataPosition; } private int[] allocateColumnDataComputedLengthArray(int row) { int[] columnDataComputedLength; if (columnDataLengthCache_.size() == row) { columnDataComputedLength = new int[columns_]; columnDataLengthCache_.add(columnDataComputedLength); } else { columnDataComputedLength = (int[]) columnDataLengthCache_.get(row); } return columnDataComputedLength; } private boolean[] allocateColumnDataIsNullArray(int row) { boolean[] columnDataIsNull; if (columnDataIsNullCache_.size() <= row) { columnDataIsNull = new boolean[columns_]; columnDataIsNullCache_.add(columnDataIsNull); } else { columnDataIsNull = (boolean[]) columnDataIsNullCache_.get(row); } return columnDataIsNull; } protected int getDecimalLength(int index) { return (((fdocaLength_[index] >> 8) & 0xff) + 2) / 2; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -