public interface Cursor extends Iterable<Row>
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.
Basic cursors will generally iterate table data in the order it appears in
the database and searches will require scanning the entire table.
Additional features are available when utilizing an Index backed
IndexCursor.
The CursorBuilder provides a variety of static utility methods to
construct cursors with given characteristics or easily search for specific
values as well as friendly and flexible construction options.
A Cursor instance is not thread-safe (see Database for more
thread-safety details).
| Modifier and Type | Interface and Description |
|---|---|
static interface |
Cursor.Id
Identifier for a cursor.
|
static interface |
Cursor.Position
Value object which maintains the current position of the cursor.
|
static interface |
Cursor.Savepoint
Value object which represents a complete save state of the cursor.
|
| Modifier and Type | Method and Description |
|---|---|
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).
|
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(RowId rowId)
Moves to the row with the given rowId.
|
ColumnMatcher |
getColumnMatcher()
Returns the currently configured ColumnMatcher, always non-
null. |
Row |
getCurrentRow()
Returns the current row in this cursor (Column name -> Column value).
|
Row |
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). |
Cursor.Id |
getId() |
Row |
getNextRow()
Moves to the next row in the table and returns it.
|
Row |
getNextRow(Collection<String> columnNames)
Moves to the next row in the table and returns it.
|
Row |
getPreviousRow()
Moves to the previous row in the table and returns it.
|
Row |
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). |
Iterator<Row> |
iterator()
Calls
beforeFirst() on this cursor and returns a modifiable
Iterator which will iterate through all the rows of this table. |
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.
|
IterableBuilder |
newIterable()
Convenience method for constructing a new IterableBuilder for 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(). |
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.
|
default Stream<Row> |
stream() |
Object[] |
updateCurrentRow(Object... row)
Update the current row.
|
<M extends Map<String,Object>> |
updateCurrentRowFromMap(M row)
Update the current row.
|
forEach, spliteratorCursor.Id getId()
Table getTable()
ErrorHandler getErrorHandler()
null).
This will be used to handle all errors.void setErrorHandler(ErrorHandler newErrorHandler)
null, resets to using the
ErrorHandler configured at the Table level.ColumnMatcher getColumnMatcher()
null.void setColumnMatcher(ColumnMatcher columnMatcher)
null, resets to using the default
matcher (default depends on Cursor type).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.
void restoreSavepoint(Cursor.Savepoint savepoint) throws IOException
getSavepoint().IllegalArgumentException - if the given savepoint does not have a
cursorId equal to this cursor's idIOExceptionvoid reset()
beforeFirst().void beforeFirst()
void afterLast()
boolean isBeforeFirst()
throws IOException
true if the cursor is currently positioned before the
first row, false otherwise.IOExceptionboolean isAfterLast()
throws IOException
true if the cursor is currently positioned after the
last row, false otherwise.IOExceptionboolean isCurrentRowDeleted()
throws IOException
true if the row at which the cursor is currently
positioned is deleted, false otherwise (including invalid rows).IOExceptionIterator<Row> 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().
For more flexible iteration see newIterable().
iterator in interface Iterable<Row>RuntimeIOException - if an IOException is thrown by one of the
operations, the actual exception will be contained withinIterableBuilder newIterable()
void deleteCurrentRow()
throws IOException
Note, re-deleting an already deleted row is allowed (it does nothing).
IllegalStateException - if the current row is not valid (at
beginning or end of table)IOExceptionObject[] updateCurrentRow(Object... row) throws IOException
IllegalStateException - if the current row is not valid (at
beginning or end of table), or deleted.IOException<M extends Map<String,Object>> M updateCurrentRowFromMap(M row) throws IOException
IllegalStateException - if the current row is not valid (at
beginning or end of table), or deleted.IOExceptionRow getNextRow() throws IOException
null if no next row is foundIOExceptionRow getNextRow(Collection<String> columnNames) throws IOException
columnNames - Only column names in this collection will be returnednull if no next row is foundIOExceptionRow getPreviousRow() throws IOException
null if no previous row is foundIOExceptionRow getPreviousRow(Collection<String> columnNames) throws IOException
columnNames - Only column names in this collection will be returnednull if no previous row is foundIOExceptionboolean moveToNextRow()
throws IOException
true if a valid next row was found, false
otherwiseIOExceptionboolean moveToPreviousRow()
throws IOException
true if a valid previous row was found, false
otherwiseIOExceptionboolean findRow(RowId rowId) throws IOException
true if a valid row was found with the given id,
false if no row was foundIOExceptionboolean 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. If this object is an instance of
Predicate, it will be
applied to the potential row value instead
(overriding any configured ColumnMatcher)true if a valid row was found with the given value,
false if no row was foundIOExceptionboolean 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. If this object is an instance of
Predicate, it will be
applied to the potential row value instead
(overriding any configured ColumnMatcher)true if a valid row was found with the given value,
false if no row was foundIOExceptionboolean 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. If a value is
an instance of Predicate, it
will be applied to the potential row value instead
(overriding any configured ColumnMatcher)true if a valid row was found with the given values,
false if no row was foundIOExceptionboolean findNextRow(Map<String,?> rowPattern) throws IOException
rowPattern - column names and values which must be equal to the
corresponding values in the matched row. If a value is
an instance of Predicate, it
will be applied to the potential row value instead
(overriding any configured ColumnMatcher)true if a valid row was found with the given values,
false if no row was foundIOExceptionboolean 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 equal to the corresponding value in
the matched row. If this object is an instance of
Predicate, it will be
applied to the potential row value instead
(overriding any configured ColumnMatcher)IOExceptionboolean 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 matched row. If a value is
an instance of Predicate, it
will be applied to the potential row value instead
(overriding any configured ColumnMatcher)IOExceptionint moveNextRows(int numRows)
throws IOException
IOExceptionint movePreviousRows(int numRows)
throws IOException
IOExceptionRow getCurrentRow() throws IOException
IOExceptionRow getCurrentRow(Collection<String> columnNames) throws IOException
columnNames - Only column names in this collection will be returnedIOExceptionObject getCurrentRowValue(Column column) throws IOException
IOExceptionvoid setCurrentRowValue(Column column, Object value) throws IOException
IllegalStateException - if the current row is not valid (at
beginning or end of table), or deleted.IOExceptionCopyright © 2005–2025 OpenHMS. All rights reserved.