|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.healthmarketscience.jackcess.Cursor
public abstract class Cursor
Manages iteration for a Table. Different cursors provide different methods of traversing a table. Cursors should be fairly robust in the face of table modification during traversal (although depending on how the table is traversed, row updates may or may not be seen). Multiple cursors may traverse the same table simultaneously.
The Cursor provides a variety of static utility methods to construct
cursors with given characteristics or easily search for specific values.
For even friendlier and more flexible construction, see
CursorBuilder.
Is not thread-safe.
| Nested Class Summary | |
|---|---|
static class |
Cursor.Id
Identifier for a cursor. |
static class |
Cursor.Position
Value object which maintains the current position of the cursor. |
static class |
Cursor.Savepoint
Value object which represents a complete save state of the cursor. |
| Field Summary | |
|---|---|
static boolean |
MOVE_FORWARD
boolean value indicating forward movement |
static boolean |
MOVE_REVERSE
boolean value indicating reverse movement |
| Method Summary | |
|---|---|
void |
afterLast()
Resets this cursor for reverse traversal (sets cursor to after the last row). |
void |
beforeFirst()
Resets this cursor for forward traversal (sets cursor to before the first row). |
Iterable<Map<String,Object>> |
columnMatchIterable(Collection<String> columnNames,
Column columnPattern,
Object valuePattern)
Returns an Iterable whose iterator() method returns the result of a call to columnMatchIterator(Collection,Column,Object) |
Iterable<Map<String,Object>> |
columnMatchIterable(Column columnPattern,
Object valuePattern)
Returns an Iterable whose iterator() method returns the result of a call to columnMatchIterable(Column,Object) |
Iterator<Map<String,Object>> |
columnMatchIterator(Collection<String> columnNames,
Column columnPattern,
Object valuePattern)
Calls beforeFirst on this table and returns a modifiable
Iterator which will iterate through all the rows of this table which
match the given column pattern, returning only the given columns. |
Iterator<Map<String,Object>> |
columnMatchIterator(Column columnPattern,
Object valuePattern)
Calls beforeFirst on this cursor and returns a modifiable
Iterator which will iterate through all the rows of this table which
match the given column pattern. |
static Cursor |
createCursor(Table table)
Creates a normal, un-indexed cursor for the given table. |
static Cursor |
createIndexCursor(Table table,
Index index)
Creates an indexed cursor for the given table. |
static Cursor |
createIndexCursor(Table table,
Index index,
Object[] startRow,
boolean startInclusive,
Object[] endRow,
boolean endInclusive)
Creates an indexed cursor for the given table, narrowed to the given range. |
static Cursor |
createIndexCursor(Table table,
Index index,
Object[] startRow,
Object[] endRow)
Creates an indexed cursor for the given table, narrowed to the given range. |
boolean |
currentRowMatches(Column columnPattern,
Object valuePattern)
Returns true if the current row matches the given pattern. |
boolean |
currentRowMatches(Map<String,?> rowPattern)
Returns true if the current row matches the given pattern. |
void |
deleteCurrentRow()
Delete the current row. |
boolean |
findFirstRow(Column columnPattern,
Object valuePattern)
Moves to the first row (as defined by the cursor) where the given column has the given value. |
boolean |
findFirstRow(Map<String,?> rowPattern)
Moves to the first row (as defined by the cursor) where the given columns have the given values. |
boolean |
findNextRow(Column columnPattern,
Object valuePattern)
Moves to the next row (as defined by the cursor) where the given column has the given value. |
boolean |
findNextRow(Map<String,?> rowPattern)
Moves to the next row (as defined by the cursor) where the given columns have the given values. |
boolean |
findRow(Column columnPattern,
Object valuePattern)
Deprecated. renamed to findFirstRow(Column,Object) to be more clear |
boolean |
findRow(Map<String,?> rowPattern)
Deprecated. renamed to findFirstRow(Map) to be more clear |
static Map<String,Object> |
findRow(Table table,
Index index,
Map<String,?> rowPattern)
Convenience method for finding a specific row in an indexed table which matches a given row "pattern". |
static Map<String,Object> |
findRow(Table table,
Map<String,?> rowPattern)
Convenience method for finding a specific row in a table which matches a given row "pattern". |
static Object |
findValue(Table table,
Column column,
Column columnPattern,
Object valuePattern)
Convenience method for finding a specific row in a table which matches a given row "pattern". |
static Object |
findValue(Table table,
Index index,
Column column,
Column columnPattern,
Object valuePattern)
Convenience method for finding a specific row in a table which matches a given row "pattern". |
ColumnMatcher |
getColumnMatcher()
Returns the currently configured ColumnMatcher, always non- null. |
Map<String,Object> |
getCurrentRow()
Returns the current row in this cursor (Column name -> Column value). |
Map<String,Object> |
getCurrentRow(Collection<String> columnNames)
Returns the current row in this cursor (Column name -> Column value). |
Object |
getCurrentRowValue(Column column)
Returns the given column from the current row. |
ErrorHandler |
getErrorHandler()
Gets the currently configured ErrorHandler (always non- null). |
JetFormat |
getFormat()
|
Cursor.Id |
getId()
|
Map<String,Object> |
getNextRow()
Moves to the next row in the table and returns it. |
Map<String,Object> |
getNextRow(Collection<String> columnNames)
Moves to the next row in the table and returns it. |
PageChannel |
getPageChannel()
|
Map<String,Object> |
getPreviousRow()
Moves to the previous row in the table and returns it. |
Map<String,Object> |
getPreviousRow(Collection<String> columnNames)
Moves to the previous row in the table and returns it. |
Cursor.Savepoint |
getSavepoint()
Returns the current state of the cursor which can be restored at a future point in time by a call to restoreSavepoint(com.healthmarketscience.jackcess.Cursor.Savepoint). |
Table |
getTable()
|
boolean |
isAfterLast()
Returns true if the cursor is currently positioned after the
last row, false otherwise. |
boolean |
isBeforeFirst()
Returns true if the cursor is currently positioned before the
first row, false otherwise. |
boolean |
isCurrentRowDeleted()
Returns true if the row at which the cursor is currently
positioned is deleted, false otherwise (including invalid rows). |
Iterable<Map<String,Object>> |
iterable(Collection<String> columnNames)
Returns an Iterable whose iterator() method returns the result of a call to iterator(Collection) |
Iterator<Map<String,Object>> |
iterator()
Calls beforeFirst on this cursor and returns a modifiable
Iterator which will iterate through all the rows of this table. |
Iterator<Map<String,Object>> |
iterator(Collection<String> columnNames)
Calls beforeFirst on this table and returns a modifiable
Iterator which will iterate through all the rows of this table, returning
only the given columns. |
int |
moveNextRows(int numRows)
Moves forward as many rows as possible up to the given number of rows. |
int |
movePreviousRows(int numRows)
Moves backward as many rows as possible up to the given number of rows. |
boolean |
moveToNextRow()
Moves to the next row as defined by this cursor. |
boolean |
moveToPreviousRow()
Moves to the previous row as defined by this cursor. |
void |
reset()
Resets this cursor for forward traversal. |
void |
restoreSavepoint(Cursor.Savepoint savepoint)
Moves the cursor to a savepoint previously returned from getSavepoint(). |
Iterable<Map<String,Object>> |
reverseIterable()
Returns an Iterable whose iterator() method calls afterLast
on this cursor and returns a modifiable Iterator which will iterate
through all the rows of this table in reverse order. |
Iterable<Map<String,Object>> |
reverseIterable(Collection<String> columnNames)
Returns an Iterable whose iterator() method calls afterLast
on this table and returns a modifiable Iterator which will iterate
through all the rows of this table in reverse order, returning only the
given columns. |
Iterable<Map<String,Object>> |
rowMatchIterable(Collection<String> columnNames,
Map<String,?> rowPattern)
Returns an Iterable whose iterator() method returns the result of a call to rowMatchIterator(Collection,Map) |
Iterable<Map<String,Object>> |
rowMatchIterable(Map<String,?> rowPattern)
Returns an Iterable whose iterator() method returns the result of a call to rowMatchIterator(Map) |
Iterator<Map<String,Object>> |
rowMatchIterator(Collection<String> columnNames,
Map<String,?> rowPattern)
Calls beforeFirst on this table and returns a modifiable
Iterator which will iterate through all the rows of this table which
match the given row pattern, returning only the given columns. |
Iterator<Map<String,Object>> |
rowMatchIterator(Map<String,?> rowPattern)
Calls beforeFirst on this cursor and returns a modifiable
Iterator which will iterate through all the rows of this table which
match the given row pattern. |
void |
setColumnMatcher(ColumnMatcher columnMatcher)
Sets a new ColumnMatcher. |
void |
setCurrentRowValue(Column column,
Object value)
Updates a single value in the current row. |
void |
setErrorHandler(ErrorHandler newErrorHandler)
Sets a new ErrorHandler. |
String |
toString()
|
void |
updateCurrentRow(Object... row)
Update the current row. |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final boolean MOVE_FORWARD
public static final boolean MOVE_REVERSE
| Method Detail |
|---|
public static Cursor createCursor(Table table)
table - the table over which this cursor will traverse
public static Cursor createIndexCursor(Table table,
Index index)
throws IOException
Note, index based table traversal may not include all rows, as certain
types of indexes do not include all entries (namely, some indexes ignore
null entries, see Index.shouldIgnoreNulls()).
table - the table over which this cursor will traverseindex - index for the table which will define traversal order as
well as enhance certain lookups
IOException
public static Cursor createIndexCursor(Table table,
Index index,
Object[] startRow,
Object[] endRow)
throws IOException
Note, index based table traversal may not include all rows, as certain
types of indexes do not include all entries (namely, some indexes ignore
null entries, see Index.shouldIgnoreNulls()).
table - the table over which this cursor will traverseindex - index for the table which will define traversal order as
well as enhance certain lookupsstartRow - the first row of data for the cursor (inclusive), or
null for the first entryendRow - the last row of data for the cursor (inclusive), or
null for the last entry
IOException
public static Cursor createIndexCursor(Table table,
Index index,
Object[] startRow,
boolean startInclusive,
Object[] endRow,
boolean endInclusive)
throws IOException
Note, index based table traversal may not include all rows, as certain
types of indexes do not include all entries (namely, some indexes ignore
null entries, see Index.shouldIgnoreNulls()).
table - the table over which this cursor will traverseindex - index for the table which will define traversal order as
well as enhance certain lookupsstartRow - the first row of data for the cursor, or null for
the first entrystartInclusive - whether or not startRow is inclusive or exclusiveendRow - the last row of data for the cursor, or null for
the last entryendInclusive - whether or not endRow is inclusive or exclusive
IOException
public static Map<String,Object> findRow(Table table,
Map<String,?> rowPattern)
throws IOException
findFirstRow(Map) for details on the
rowPattern.
Warning, this method always starts searching from the beginning of the Table (you cannot use it to find successive matches).
table - the table to searchrowPattern - pattern to be used to find the row
null if a match could not be found.
IOException
public static Object findValue(Table table,
Column column,
Column columnPattern,
Object valuePattern)
throws IOException
findFirstRow(Column,Object) for
details on the pattern.
Note, a null result value is ambiguous in that it could imply no
match or a matching row with null for the desired value. If
distinguishing this situation is important, you will need to use a Cursor
directly instead of this convenience method.
table - the table to searchcolumn - column whose value should be returnedcolumnPattern - column being matched by the valuePatternvaluePattern - value from the columnPattern which will match the
desired row
null if a match could not be found.
IOException
public static Map<String,Object> findRow(Table table,
Index index,
Map<String,?> rowPattern)
throws IOException
findFirstRow(Map) for
details on the rowPattern.
Warning, this method always starts searching from the beginning of the Table (you cannot use it to find successive matches).
table - the table to searchindex - index to assist the searchrowPattern - pattern to be used to find the row
null if a match could not be found.
IOException
public static Object findValue(Table table,
Index index,
Column column,
Column columnPattern,
Object valuePattern)
throws IOException
findFirstRow(Column,Object) for
details on the pattern.
Note, a null result value is ambiguous in that it could imply no
match or a matching row with null for the desired value. If
distinguishing this situation is important, you will need to use a Cursor
directly instead of this convenience method.
table - the table to searchindex - index to assist the searchcolumn - column whose value should be returnedcolumnPattern - column being matched by the valuePatternvaluePattern - value from the columnPattern which will match the
desired row
null if a match could not be found.
IOExceptionpublic Cursor.Id getId()
public Table getTable()
public JetFormat getFormat()
public PageChannel getPageChannel()
public ErrorHandler getErrorHandler()
null).
This will be used to handle all errors.
public void setErrorHandler(ErrorHandler newErrorHandler)
null, resets to using the
ErrorHandler configured at the Table level.
public ColumnMatcher getColumnMatcher()
null.
public void setColumnMatcher(ColumnMatcher columnMatcher)
null, resets to using the
default matcher, SimpleColumnMatcher.INSTANCE.
public Cursor.Savepoint getSavepoint()
restoreSavepoint(com.healthmarketscience.jackcess.Cursor.Savepoint).
Savepoints may be used across different cursor instances for the same
table, but they must have the same Cursor.Id.
public void restoreSavepoint(Cursor.Savepoint savepoint)
throws IOException
getSavepoint().
IllegalArgumentException - if the given savepoint does not have a
cursorId equal to this cursor's id
IOExceptionpublic void reset()
beforeFirst().
public void beforeFirst()
public void afterLast()
public boolean isBeforeFirst()
throws IOException
true if the cursor is currently positioned before the
first row, false otherwise.
IOException
public boolean isAfterLast()
throws IOException
true if the cursor is currently positioned after the
last row, false otherwise.
IOException
public boolean isCurrentRowDeleted()
throws IOException
true if the row at which the cursor is currently
positioned is deleted, false otherwise (including invalid rows).
IOExceptionpublic Iterable<Map<String,Object>> reverseIterable()
afterLast
on this cursor and returns a modifiable Iterator which will iterate
through all the rows of this table in reverse order. Use of the Iterator
follows the same restrictions as a call to getPreviousRow.
IllegalStateException - if an IOException is thrown by one of the
operations, the actual exception will be contained withinpublic Iterable<Map<String,Object>> reverseIterable(Collection<String> columnNames)
afterLast
on this table and returns a modifiable Iterator which will iterate
through all the rows of this table in reverse order, returning only the
given columns. Use of the Iterator follows the same restrictions as a
call to getPreviousRow.
IllegalStateException - if an IOException is thrown by one of the
operations, the actual exception will be contained withinpublic Iterator<Map<String,Object>> iterator()
beforeFirst on this cursor and returns a modifiable
Iterator which will iterate through all the rows of this table. Use of
the Iterator follows the same restrictions as a call to
getNextRow.
iterator in interface Iterable<Map<String,Object>>IllegalStateException - if an IOException is thrown by one of the
operations, the actual exception will be contained withinpublic Iterable<Map<String,Object>> iterable(Collection<String> columnNames)
iterator(Collection)
IllegalStateException - if an IOException is thrown by one of the
operations, the actual exception will be contained withinpublic Iterator<Map<String,Object>> iterator(Collection<String> columnNames)
beforeFirst on this table and returns a modifiable
Iterator which will iterate through all the rows of this table, returning
only the given columns. Use of the Iterator follows the same
restrictions as a call to getNextRow.
IllegalStateException - if an IOException is thrown by one of the
operations, the actual exception will be contained within
public Iterable<Map<String,Object>> columnMatchIterable(Column columnPattern,
Object valuePattern)
columnMatchIterable(Column,Object)
IllegalStateException - if an IOException is thrown by one of the
operations, the actual exception will be contained within
public Iterator<Map<String,Object>> columnMatchIterator(Column columnPattern,
Object valuePattern)
beforeFirst on this cursor and returns a modifiable
Iterator which will iterate through all the rows of this table which
match the given column pattern. Use of the Iterator follows the same
restrictions as a call to getNextRow. See
findFirstRow(Column,Object) for details on the columnPattern.
IllegalStateException - if an IOException is thrown by one of the
operations, the actual exception will be contained within
public Iterable<Map<String,Object>> columnMatchIterable(Collection<String> columnNames,
Column columnPattern,
Object valuePattern)
columnMatchIterator(Collection,Column,Object)
IllegalStateException - if an IOException is thrown by one of the
operations, the actual exception will be contained within
public Iterator<Map<String,Object>> columnMatchIterator(Collection<String> columnNames,
Column columnPattern,
Object valuePattern)
beforeFirst on this table and returns a modifiable
Iterator which will iterate through all the rows of this table which
match the given column pattern, returning only the given columns. Use of
the Iterator follows the same restrictions as a call to
getNextRow. See findFirstRow(Column,Object) for
details on the columnPattern.
IllegalStateException - if an IOException is thrown by one of the
operations, the actual exception will be contained withinpublic Iterable<Map<String,Object>> rowMatchIterable(Map<String,?> rowPattern)
rowMatchIterator(Map)
IllegalStateException - if an IOException is thrown by one of the
operations, the actual exception will be contained withinpublic Iterator<Map<String,Object>> rowMatchIterator(Map<String,?> rowPattern)
beforeFirst on this cursor and returns a modifiable
Iterator which will iterate through all the rows of this table which
match the given row pattern. Use of the Iterator follows the same
restrictions as a call to getNextRow. See
findFirstRow(Map) for details on the rowPattern.
IllegalStateException - if an IOException is thrown by one of the
operations, the actual exception will be contained within
public Iterable<Map<String,Object>> rowMatchIterable(Collection<String> columnNames,
Map<String,?> rowPattern)
rowMatchIterator(Collection,Map)
IllegalStateException - if an IOException is thrown by one of the
operations, the actual exception will be contained within
public Iterator<Map<String,Object>> rowMatchIterator(Collection<String> columnNames,
Map<String,?> rowPattern)
beforeFirst on this table and returns a modifiable
Iterator which will iterate through all the rows of this table which
match the given row pattern, returning only the given columns. Use of
the Iterator follows the same restrictions as a call to
getNextRow. See findFirstRow(Map) for details on
the rowPattern.
IllegalStateException - if an IOException is thrown by one of the
operations, the actual exception will be contained within
public void deleteCurrentRow()
throws IOException
IllegalStateException - if the current row is not valid (at
beginning or end of table), or already deleted.
IOException
public void updateCurrentRow(Object... row)
throws IOException
IllegalStateException - if the current row is not valid (at
beginning or end of table), or deleted.
IOException
public Map<String,Object> getNextRow()
throws IOException
null if no next row is found
IOException
public Map<String,Object> getNextRow(Collection<String> columnNames)
throws IOException
columnNames - Only column names in this collection will be returned
null if no next row is found
IOException
public Map<String,Object> getPreviousRow()
throws IOException
null if no previous row is found
IOException
public Map<String,Object> getPreviousRow(Collection<String> columnNames)
throws IOException
columnNames - Only column names in this collection will be returned
null if no previous row is found
IOException
public boolean moveToNextRow()
throws IOException
true if a valid next row was found, false
otherwise
IOException
public boolean moveToPreviousRow()
throws IOException
true if a valid previous row was found, false
otherwise
IOException
@Deprecated
public boolean findRow(Column columnPattern,
Object valuePattern)
throws IOException
findFirstRow(Column,Object) to be more clear
IOException
public boolean findFirstRow(Column columnPattern,
Object valuePattern)
throws IOException
Warning, this method always starts searching from the beginning of the Table (you cannot use it to find successive matches).
columnPattern - column from the table for this cursor which is being
matched by the valuePatternvaluePattern - value which is equal to the corresponding value in
the matched row
true if a valid row was found with the given value,
false if no row was found
IOException
public boolean findNextRow(Column columnPattern,
Object valuePattern)
throws IOException
columnPattern - column from the table for this cursor which is being
matched by the valuePatternvaluePattern - value which is equal to the corresponding value in
the matched row
true if a valid row was found with the given value,
false if no row was found
IOException
@Deprecated
public boolean findRow(Map<String,?> rowPattern)
throws IOException
findFirstRow(Map) to be more clear
IOException
public boolean findFirstRow(Map<String,?> rowPattern)
throws IOException
Warning, this method always starts searching from the beginning of the Table (you cannot use it to find successive matches).
rowPattern - column names and values which must be equal to the
corresponding values in the matched row
true if a valid row was found with the given values,
false if no row was found
IOException
public boolean findNextRow(Map<String,?> rowPattern)
throws IOException
rowPattern - column names and values which must be equal to the
corresponding values in the matched row
true if a valid row was found with the given values,
false if no row was found
IOException
public boolean currentRowMatches(Column columnPattern,
Object valuePattern)
throws IOException
true if the current row matches the given pattern.
columnPattern - column from the table for this cursor which is being
matched by the valuePatternvaluePattern - value which is tested for equality with the
corresponding value in the current row
IOException
public boolean currentRowMatches(Map<String,?> rowPattern)
throws IOException
true if the current row matches the given pattern.
rowPattern - column names and values which must be equal to the
corresponding values in the current row
IOException
public int moveNextRows(int numRows)
throws IOException
IOException
public int movePreviousRows(int numRows)
throws IOException
IOException
public Map<String,Object> getCurrentRow()
throws IOException
IOException
public Map<String,Object> getCurrentRow(Collection<String> columnNames)
throws IOException
columnNames - Only column names in this collection will be returned
IOException
public Object getCurrentRowValue(Column column)
throws IOException
IOException
public void setCurrentRowValue(Column column,
Object value)
throws IOException
IllegalStateException - if the current row is not valid (at
beginning or end of table), or deleted.
IOExceptionpublic String toString()
toString in class Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||