📄 hashscanresultset.java
字号:
} } /** * Return the next row (if any) from the scan (if open). * * @exception StandardException thrown on failure to get next row */ public ExecRow getNextRowCore() throws StandardException { ExecRow result = null; DataValueDescriptor[] columns = null; beginTime = getCurrentTimeMillis(); if ( isOpen && hashtableBuilt) { /* We use a do/while loop to ensure that we continue down * the duplicate chain, if one exists, until we find a * row that matches on all probe predicates (or the * duplicate chain is exhausted.) */ do { if (firstNext) { firstNext = false; /* Hash key could be either a single column or multiple columns. * If a single column, then it is the datavalue wrapper, otherwise * it is a KeyHasher. */ Object hashEntry; if (keyColumns.length == 1) { hashEntry = hashtable.get(nextQualifiers[0][0].getOrderable()); } else { KeyHasher mh = new KeyHasher(keyColumns.length); if (SanityManager.DEBUG) { SanityManager.ASSERT(nextQualifiers.length == 1); } for (int index = 0; index < keyColumns.length; index++) { // For hashing only use the AND qualifiers // located in nextQualifiers[0][0...N], OR // qualifiers are checked down a bit by calling // qualifyRow on rows returned from hash. DataValueDescriptor dvd = nextQualifiers[0][index].getOrderable(); if (dvd == null) { mh = null; break; } mh.setObject( index, nextQualifiers[0][index].getOrderable()); } hashEntry = (mh == null) ? null : hashtable.get(mh); } if (hashEntry instanceof Vector) { entryVector = (Vector) hashEntry; entryVectorSize = entryVector.size(); columns = (DataValueDescriptor[]) entryVector.firstElement(); } else { entryVector = null; entryVectorSize = 0; columns = (DataValueDescriptor[]) hashEntry; } } else if (numFetchedOnNext < entryVectorSize) { /* We walking a Vector and there's * more rows left in the vector. */ columns = (DataValueDescriptor[]) entryVector.elementAt(numFetchedOnNext); } if (columns != null) { if (SanityManager.DEBUG) { // There used to be an assertion here that the columns // array was the same size as the number of columns // in the compact row. This assertion no longer holds // now that we're doing sparse rows, so I deleted it. // Columns is really a Storable[] for (int i = 0; i < columns.length; i++) { if (columns[i] != null && ! (columns[i] instanceof Storable)) { SanityManager.THROWASSERT( "columns[" + i + "] expected to be Storable, not " + columns[i].getClass().getName()); } } } // See if the entry satisfies all of the other qualifiers /* We've already "evaluated" the 1st keyColumns qualifiers * when we probed into the hash table, but we need to * evaluate them again here because of the behavior of * NULLs. NULLs are treated as equal when building and * probing the hash table so that we only get a single * entry. However, NULL does not equal NULL, so the * compare() method below will eliminate any row that * has a key column containing a NULL. * * The following code will also evaluate any OR clauses * that may exist, while the above hashing does not * include them. */ if (RowUtil.qualifyRow(columns, nextQualifiers)) { setCompatRow(compactRow, columns); rowsSeen++; result = compactRow; } else { result = null; } numFetchedOnNext++; } else { result = null; } } while (result == null && numFetchedOnNext < entryVectorSize); } currentRow = result; setCurrentRow(result); nextTime += getElapsedMillis(beginTime); return result; } /** * If the result set has been opened, * close the open scan. * * @exception StandardException thrown on error */ public void close() throws StandardException { beginTime = getCurrentTimeMillis(); if ( isOpen ) { // we don't want to keep around a pointer to the // row ... so it can be thrown away. // REVISIT: does this need to be in a finally // block, to ensure that it is executed? clearCurrentRow(); if (closeCleanup != null) { closeCleanup.invoke(activation); // let activation tidy up } currentRow = null; if (hashtableBuilt) { // This is where we get the scan properties for a subquery scanProperties = getScanProperties(); // This is where we get the positioner info for inner tables if (runTimeStatisticsOn) { startPositionString = printStartPosition(); stopPositionString = printStopPosition(); } // close the hash table, eating any exception hashtable.close(); hashtable = null; hashtableBuilt = false; } startPosition = null; stopPosition = null; super.close(); } else if (SanityManager.DEBUG) SanityManager.DEBUG("CloseRepeatInfo","Close of HashScanResultSet repeated"); closeTime += getElapsedMillis(beginTime); } /** * Return the total amount of time spent in this ResultSet * * @param type CURRENT_RESULTSET_ONLY - time spent only in this ResultSet * ENTIRE_RESULTSET_TREE - time spent in this ResultSet and below. * * @return long The total amount of time spent (in milliseconds). */ public long getTimeSpent(int type) { long totTime = constructorTime + openTime + nextTime + closeTime; /* RESOLVE - subtract out store time later, when available */ if (type == NoPutResultSet.CURRENT_RESULTSET_ONLY) { return totTime; } else { return totTime; } } /** * @see NoPutResultSet#getScanIsolationLevel */ public int getScanIsolationLevel() { return isolationLevel; } /** * @see NoPutResultSet#requiresRelocking */ public boolean requiresRelocking() { // IndexRowToBaseRow needs to relock if we didn't keep the lock return( ((isolationLevel == TransactionController.ISOLATION_READ_COMMITTED) || (isolationLevel == TransactionController.ISOLATION_READ_COMMITTED_NOHOLDLOCK) || (isolationLevel == TransactionController.ISOLATION_READ_UNCOMMITTED))); } // // CursorResultSet interface // /** * This result set has its row location from * the last fetch done. If the cursor is closed, * a null is returned. * * @see CursorResultSet * * @return the row location of the current cursor row. * @exception StandardException thrown on failure to get row location */ public RowLocation getRowLocation() throws StandardException { if (! isOpen) return null; if ( ! hashtableBuilt) return null; /* This method should only be called if the last column * in the current row is a RowLocation. */ if (SanityManager.DEBUG) { SanityManager.ASSERT(currentRow != null, "There must be a current row when fetching the row location"); Object rlCandidate = currentRow.getColumn( currentRow.nColumns()); if (! (rlCandidate instanceof RowLocation)) { SanityManager.THROWASSERT( "rlCandidate expected to be instanceof RowLocation, not " + rlCandidate.getClass().getName()); } } return (RowLocation) currentRow.getColumn( currentRow.nColumns()); } /** * This result set has its row from the last fetch done. * If the cursor is closed, a null is returned. * * @see CursorResultSet * * @return the last row returned; * @exception StandardException thrown on failure. */ /* RESOLVE - this should return activation.getCurrentRow(resultSetNumber), * once there is such a method. (currentRow is redundant) */ public ExecRow getCurrentRow() throws StandardException { /* Doesn't make sense to call this method for this node since * joins are not updatable. */ if (SanityManager.DEBUG) { SanityManager.THROWASSERT( "getCurrentRow() not expected to be called for HSRS"); } return null; } public String printStartPosition() { return printPosition(startSearchOperator, startKeyGetter, startPosition); } public String printStopPosition() { if (sameStartStopPosition) { return printPosition(stopSearchOperator, startKeyGetter, startPosition); } else { return printPosition(stopSearchOperator, stopKeyGetter, stopPosition); } } /** * Return a start or stop positioner as a String. */ private String printPosition(int searchOperator, GeneratedMethod positionGetter, ExecIndexRow eiRow) { String idt = ""; String output = ""; if (positionGetter == null) { return "\t" + MessageService.getTextMessage(SQLState.LANG_NONE) + "\n"; } ExecIndexRow positioner = null; try { positioner = (ExecIndexRow) positionGetter.invoke(activation); } catch (StandardException e) { if (eiRow == null) { return "\t" + MessageService.getTextMessage( SQLState.LANG_POSITION_NOT_AVAIL); } return "\t" + MessageService.getTextMessage( SQLState.LANG_UNEXPECTED_EXC_GETTING_POSITIONER) + "\n"; } if (positioner == null) { return "\t" + MessageService.getTextMessage(SQLState.LANG_NONE) + "\n"; } String searchOp = null; switch (searchOperator) { case ScanController.GE: searchOp = ">="; break; case ScanController.GT: searchOp = ">"; break; default: if (SanityManager.DEBUG) { SanityManager.THROWASSERT("Unknown search operator " + searchOperator); } // This is not internationalized because we should never // reach here. searchOp = "unknown value (" + searchOperator + ")"; break; } output += "\t" + MessageService.getTextMessage( SQLState.LANG_POSITIONER, searchOp, String.valueOf(positioner.nColumns())) + "\n"; output += "\t" + MessageService.getTextMessage( SQLState.LANG_ORDERED_NULL_SEMANTICS) + "\n"; for (int position = 0; position < positioner.nColumns(); position++) { if (positioner.areNullsOrdered(position)) { output = output + position + " "; } } return output + "\n"; } public Properties getScanProperties() { return scanProperties; } /** * Is this ResultSet or it's source result set for update * * @return Whether or not the result set is for update. */ public boolean isForUpdate() { return forUpdate; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -