Przeglądaj źródła

IndexCursor can early exit when searching based on indexed values, fixes 109

git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@881 f203690c-595d-4dc9-a70b-905162fa7fd2
tags/jackcess-2.0.6
James Ahlborn 9 lat temu
rodzic
commit
94148f092f

+ 5
- 0
src/changes/changes.xml Wyświetl plik

@@ -4,6 +4,11 @@
<author email="javajedi@users.sf.net">Tim McCune</author>
</properties>
<body>
<release version="2.0.6" date="TBD">
<action dev="jahlborn" type="fix" system="SourceForge2" issue="109">
IndexCursor can early exit when searching based on indexed values.
</action>
</release>
<release version="2.0.5" date="2014-09-17">
<action dev="jahlborn" type="add">
Add Cursor.findRow(RowId) for moving to a specific Table row using

+ 23
- 5
src/main/java/com/healthmarketscience/jackcess/impl/CursorImpl.java Wyświetl plik

@@ -315,7 +315,7 @@ public abstract class CursorImpl implements Cursor
* {@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)) {
@@ -485,7 +485,7 @@ public abstract class CursorImpl implements Cursor
reset(moveForward);
}
found = findAnotherRowImpl(columnPattern, valuePattern, moveForward,
columnMatcher);
columnMatcher, null);
return found;
} finally {
if(!found) {
@@ -521,7 +521,7 @@ public abstract class CursorImpl implements Cursor
if(reset) {
reset(moveForward);
}
found = findAnotherRowImpl(rowPattern, moveForward, columnMatcher);
found = findAnotherRowImpl(rowPattern, moveForward, columnMatcher, null);
return found;
} finally {
if(!found) {
@@ -598,13 +598,16 @@ public abstract class CursorImpl implements Cursor
*/
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;
}
@@ -622,17 +625,32 @@ public abstract class CursorImpl implements Cursor
*/
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);

+ 24
- 21
src/main/java/com/healthmarketscience/jackcess/impl/IndexCursorImpl.java Wyświetl plik

@@ -246,23 +246,18 @@ public class IndexCursorImpl extends CursorImpl implements IndexCursor
@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
@@ -300,23 +295,20 @@ public class IndexCursorImpl extends CursorImpl implements IndexCursor
}

@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
@@ -398,6 +390,17 @@ public class IndexCursorImpl extends CursorImpl implements IndexCursor
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);

Ładowanie…
Anuluj
Zapisz