* {@code null} if there is not another row in the given direction.
*/
private Row getAnotherRow(Collection<String> columnNames,
- boolean moveForward)
+ boolean moveForward)
throws IOException
{
if(moveToAnotherRow(moveForward)) {
reset(moveForward);
}
found = findAnotherRowImpl(columnPattern, valuePattern, moveForward,
- columnMatcher);
+ columnMatcher, null);
return found;
} finally {
if(!found) {
if(reset) {
reset(moveForward);
}
- found = findAnotherRowImpl(rowPattern, moveForward, columnMatcher);
+ found = findAnotherRowImpl(rowPattern, moveForward, columnMatcher, null);
return found;
} finally {
if(!found) {
*/
protected boolean findAnotherRowImpl(
ColumnImpl columnPattern, Object valuePattern, boolean moveForward,
- ColumnMatcher columnMatcher)
+ ColumnMatcher columnMatcher, Object searchInfo)
throws IOException
{
while(moveToAnotherRow(moveForward)) {
if(currentRowMatchesImpl(columnPattern, valuePattern, columnMatcher)) {
return true;
}
+ if(!keepSearching(columnMatcher, searchInfo)) {
+ break;
+ }
}
return false;
}
*/
protected boolean findAnotherRowImpl(Map<String,?> rowPattern,
boolean moveForward,
- ColumnMatcher columnMatcher)
+ ColumnMatcher columnMatcher,
+ Object searchInfo)
throws IOException
{
while(moveToAnotherRow(moveForward)) {
if(currentRowMatchesImpl(rowPattern, columnMatcher)) {
return true;
}
+ if(!keepSearching(columnMatcher, searchInfo)) {
+ break;
+ }
}
return false;
}
+ /**
+ * Called by findAnotherRowImpl to determine if the search should continue
+ * after finding a row which does not match the current pattern.
+ */
+ protected boolean keepSearching(ColumnMatcher columnMatcher,
+ Object searchInfo)
+ throws IOException
+ {
+ return true;
+ }
+
public int moveNextRows(int numRows) throws IOException
{
return moveSomeRows(numRows, MOVE_FORWARD);
@Override
protected boolean findAnotherRowImpl(
ColumnImpl columnPattern, Object valuePattern, boolean moveForward,
- ColumnMatcher columnMatcher)
+ ColumnMatcher columnMatcher, Object searchInfo)
throws IOException
{
- if(!isAtBeginning(moveForward)) {
- // use the default table scan for finding rows mid-cursor
- return super.findAnotherRowImpl(columnPattern, valuePattern, moveForward,
- columnMatcher);
- }
-
// searching for the first match
Object[] rowValues = _entryCursor.getIndexData().constructIndexRow(
columnPattern.getName(), valuePattern);
- if(rowValues == null) {
- // bummer, use the default table scan
+ if((rowValues == null) || !isAtBeginning(moveForward)) {
+ // use the default table scan if we don't have index data or we are
+ // mid-cursor
return super.findAnotherRowImpl(columnPattern, valuePattern, moveForward,
- columnMatcher);
+ columnMatcher, rowValues);
}
// sweet, we can use our index
}
@Override
- protected boolean findAnotherRowImpl(Map<String,?> rowPattern,
- boolean moveForward,
- ColumnMatcher columnMatcher)
+ protected boolean findAnotherRowImpl(
+ Map<String,?> rowPattern, boolean moveForward,
+ ColumnMatcher columnMatcher, Object searchInfo)
throws IOException
{
- if(!isAtBeginning(moveForward)) {
- // use the default table scan for finding rows mid-cursor
- return super.findAnotherRowImpl(rowPattern, moveForward, columnMatcher);
- }
-
// searching for the first match
IndexData indexData = _entryCursor.getIndexData();
Object[] rowValues = indexData.constructIndexRow(rowPattern);
- if(rowValues == null) {
- // bummer, use the default table scan
- return super.findAnotherRowImpl(rowPattern, moveForward, columnMatcher);
+ if((rowValues == null) || !isAtBeginning(moveForward)) {
+ // use the default table scan if we don't have index data or we are
+ // mid-cursor
+ return super.findAnotherRowImpl(rowPattern, moveForward, columnMatcher,
+ rowValues);
}
// sweet, we can use our index
return true;
}
+ @Override
+ protected boolean keepSearching(ColumnMatcher columnMatcher,
+ Object searchInfo)
+ throws IOException
+ {
+ if(searchInfo instanceof Object[]) {
+ return currentRowMatchesEntryImpl((Object[])searchInfo, columnMatcher);
+ }
+ return true;
+ }
+
private Object[] toRowValues(Object[] entryValues)
{
return _entryCursor.getIndexData().constructIndexRowFromEntry(entryValues);