throws IOException
{
return findAnotherRow(columnPattern, valuePattern, true, MOVE_FORWARD,
- _columnMatcher);
+ _columnMatcher,
+ prepareSearchInfo(columnPattern, valuePattern));
}
public boolean findNextRow(Column columnPattern, Object valuePattern)
throws IOException
{
return findAnotherRow(columnPattern, valuePattern, false, MOVE_FORWARD,
- _columnMatcher);
+ _columnMatcher,
+ prepareSearchInfo(columnPattern, valuePattern));
}
protected boolean findAnotherRow(ColumnImpl columnPattern, Object valuePattern,
boolean reset, boolean moveForward,
- ColumnMatcher columnMatcher)
+ ColumnMatcher columnMatcher, Object searchInfo)
throws IOException
{
PositionImpl curPos = _curPos;
reset(moveForward);
}
found = findAnotherRowImpl(columnPattern, valuePattern, moveForward,
- columnMatcher, null);
+ columnMatcher, searchInfo);
return found;
} finally {
if(!found) {
public boolean findFirstRow(Map<String,?> rowPattern) throws IOException
{
- return findAnotherRow(rowPattern, true, MOVE_FORWARD, _columnMatcher);
+ return findAnotherRow(rowPattern, true, MOVE_FORWARD, _columnMatcher,
+ prepareSearchInfo(rowPattern));
}
public boolean findNextRow(Map<String,?> rowPattern)
throws IOException
{
- return findAnotherRow(rowPattern, false, MOVE_FORWARD, _columnMatcher);
+ return findAnotherRow(rowPattern, false, MOVE_FORWARD, _columnMatcher,
+ prepareSearchInfo(rowPattern));
}
protected boolean findAnotherRow(Map<String,?> rowPattern, boolean reset,
boolean moveForward,
- ColumnMatcher columnMatcher)
+ ColumnMatcher columnMatcher, Object searchInfo)
throws IOException
{
PositionImpl curPos = _curPos;
if(reset) {
reset(moveForward);
}
- found = findAnotherRowImpl(rowPattern, moveForward, columnMatcher, null);
+ found = findAnotherRowImpl(rowPattern, moveForward, columnMatcher,
+ searchInfo);
return found;
} finally {
if(!found) {
return false;
}
+ /**
+ * Called before a search commences to allow for search specific data to be
+ * generated (which is cached for re-use by the iterators).
+ */
+ protected Object prepareSearchInfo(ColumnImpl columnPattern, Object valuePattern)
+ {
+ return null;
+ }
+
+ /**
+ * Called before a search commences to allow for search specific data to be
+ * generated (which is cached for re-use by the iterators).
+ */
+ protected Object prepareSearchInfo(Map<String,?> rowPattern)
+ {
+ return null;
+ }
+
/**
* Called by findAnotherRowImpl to determine if the search should continue
* after finding a row which does not match the current pattern.
{
private final ColumnImpl _columnPattern;
private final Object _valuePattern;
+ private final Object _searchInfo;
private ColumnMatchIterator(Collection<String> columnNames,
ColumnImpl columnPattern, Object valuePattern,
super(columnNames, reset, moveForward, columnMatcher);
_columnPattern = columnPattern;
_valuePattern = valuePattern;
+ _searchInfo = prepareSearchInfo(columnPattern, valuePattern);
}
@Override
protected boolean findNext() throws IOException {
return findAnotherRow(_columnPattern, _valuePattern, false, _moveForward,
- _colMatcher);
+ _colMatcher, _searchInfo);
}
}
private final class RowMatchIterator extends BaseIterator
{
private final Map<String,?> _rowPattern;
+ private final Object _searchInfo;
private RowMatchIterator(Collection<String> columnNames,
Map<String,?> rowPattern,
{
super(columnNames, reset, moveForward, columnMatcher);
_rowPattern = rowPattern;
+ _searchInfo = prepareSearchInfo(rowPattern);
}
@Override
protected boolean findNext() throws IOException {
- return findAnotherRow(_rowPattern, false, _moveForward, _colMatcher);
+ return findAnotherRow(_rowPattern, false, _moveForward, _colMatcher,
+ _searchInfo);
}
}
ColumnMatcher columnMatcher, Object searchInfo)
throws IOException
{
- // searching for the first match
- Object[] rowValues = _entryCursor.getIndexData().constructIndexRow(
- columnPattern.getName(), valuePattern);
+ Object[] rowValues = (Object[])searchInfo;
if((rowValues == null) || !isAtBeginning(moveForward)) {
// use the default table scan if we don't have index data or we are
ColumnMatcher columnMatcher, Object searchInfo)
throws IOException
{
- // searching for the first match
- IndexData indexData = _entryCursor.getIndexData();
- Object[] rowValues = indexData.constructIndexRow(rowPattern);
+ Object[] rowValues = (Object[])searchInfo;
if((rowValues == null) || !isAtBeginning(moveForward)) {
// use the default table scan if we don't have index data or we are
}
// find actual matching row
+ IndexData indexData = _entryCursor.getIndexData();
Map<String,?> indexRowPattern = null;
if(rowPattern.size() == indexData.getColumns().size()) {
// the rowPattern matches our index columns exactly, so we can
return true;
}
+ @Override
+ protected Object prepareSearchInfo(ColumnImpl columnPattern, Object valuePattern)
+ {
+ // attempt to generate a lookup row for this index
+ return _entryCursor.getIndexData().constructIndexRow(
+ columnPattern.getName(), valuePattern);
+ }
+
+ @Override
+ protected Object prepareSearchInfo(Map<String,?> rowPattern)
+ {
+ // attempt to generate a lookup row for this index
+ return _entryCursor.getIndexData().constructIndexRow(rowPattern);
+ }
+
@Override
protected boolean keepSearching(ColumnMatcher columnMatcher,
Object searchInfo)
throws IOException
{
if(searchInfo instanceof Object[]) {
+ // if we have a lookup row for this index, then we only need to continue
+ // searching while we are looking at rows which match the index lookup
+ // value(s). once we move past those rows, no other rows could possibly
+ // match.
return currentRowMatchesEntryImpl((Object[])searchInfo, columnMatcher);
}
+ // we are doing a full table scan
return true;
}