public abstract class CursorImpl extends Object implements Cursor
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.
| Modifier and Type | Class and Description |
|---|---|
protected class |
CursorImpl.BaseIterator
Base implementation of iterator for this cursor, modifiable.
|
protected class |
CursorImpl.DirHandler
Handles moving the cursor in a given direction.
|
protected static class |
CursorImpl.IdImpl
Identifier for a cursor.
|
protected static class |
CursorImpl.PositionImpl
Value object which maintains the current position of the cursor.
|
protected static class |
CursorImpl.SavepointImpl
Value object which represents a complete save state of the cursor.
|
Cursor.Id, Cursor.Position, Cursor.Savepoint| Modifier and Type | Field and Description |
|---|---|
protected ColumnMatcher |
_columnMatcher
ColumnMatcher to be used when matching column values
|
protected CursorImpl.PositionImpl |
_curPos
the current row
|
protected CursorImpl.PositionImpl |
_prevPos
the previous row
|
static boolean |
MOVE_FORWARD
boolean value indicating forward movement
|
static boolean |
MOVE_REVERSE
boolean value indicating reverse movement
|
| Modifier | Constructor and Description |
|---|---|
protected |
CursorImpl(CursorImpl.IdImpl id,
TableImpl table,
CursorImpl.PositionImpl firstPos,
CursorImpl.PositionImpl lastPos) |
| 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).
|
static CursorImpl |
createCursor(TableImpl table)
Creates a normal, un-indexed cursor for the given table.
|
boolean |
currentRowMatches(ColumnImpl columnPattern,
Object valuePattern) |
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. |
protected boolean |
currentRowMatchesImpl(ColumnImpl columnPattern,
Object valuePattern,
ColumnMatcher columnMatcher) |
protected boolean |
currentRowMatchesImpl(Map<String,?> rowPattern,
ColumnMatcher columnMatcher) |
void |
deleteCurrentRow()
Delete the current row.
|
protected abstract CursorImpl.PositionImpl |
findAnotherPosition(TableImpl.RowState rowState,
CursorImpl.PositionImpl curPos,
boolean moveForward)
Finds the next non-deleted row after the given row (as defined by this
cursor) and returns the id of the row, where "next" may be backwards if
moveForward is
false. |
protected boolean |
findAnotherRow(ColumnImpl columnPattern,
Object valuePattern,
boolean reset,
boolean moveForward,
ColumnMatcher columnMatcher,
Object searchInfo) |
protected boolean |
findAnotherRow(Map<String,?> rowPattern,
boolean reset,
boolean moveForward,
ColumnMatcher columnMatcher,
Object searchInfo) |
protected boolean |
findAnotherRowImpl(ColumnImpl columnPattern,
Object valuePattern,
boolean moveForward,
ColumnMatcher columnMatcher,
Object searchInfo)
Moves to the next row (as defined by the cursor) where the given column
has the given value.
|
protected boolean |
findAnotherRowImpl(Map<String,?> rowPattern,
boolean moveForward,
ColumnMatcher columnMatcher,
Object searchInfo)
Moves to the next row (as defined by the cursor) where the given columns
have the given values.
|
boolean |
findFirstRow(ColumnImpl columnPattern,
Object valuePattern) |
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(ColumnImpl columnPattern,
Object valuePattern) |
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.
|
Object |
getCurrentRowValue(ColumnImpl column) |
protected ColumnMatcher |
getDefaultColumnMatcher()
Returns the default ColumnMatcher for this Cursor.
|
protected abstract CursorImpl.DirHandler |
getDirHandler(boolean moveForward)
Returns the DirHandler for the given movement direction.
|
ErrorHandler |
getErrorHandler()
Gets the currently configured ErrorHandler (always non-
null). |
protected CursorImpl.PositionImpl |
getFirstPosition()
Returns the first row id (exclusive) as defined by this cursor.
|
JetFormat |
getFormat() |
CursorImpl.IdImpl |
getId() |
protected CursorImpl.PositionImpl |
getLastPosition()
Returns the last row id (exclusive) as defined by this cursor.
|
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.
|
PageChannel |
getPageChannel() |
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.
|
protected abstract CursorImpl.PositionImpl |
getRowPosition(RowIdImpl rowId)
Returns the appropriate position information for the given row (which is
the current row and is valid).
|
TableImpl.RowState |
getRowState() |
CursorImpl.SavepointImpl |
getSavepoint()
Returns the current state of the cursor which can be restored at a future
point in time by a call to
Cursor.restoreSavepoint(com.healthmarketscience.jackcess.Cursor.Savepoint). |
TableImpl |
getTable() |
boolean |
isAfterLast()
Returns
true if the cursor is currently positioned after the
last row, false otherwise. |
protected boolean |
isAtBeginning(boolean moveForward) |
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). |
protected boolean |
isCurrentRowValid()
Returns
true of the current row is valid, false otherwise. |
protected boolean |
isUpToDate()
Returns
true if this cursor is up-to-date with respect to the
relevant table and related table objects, false otherwise. |
Iterator<Row> |
iterator()
Calls
Cursor.beforeFirst() on this cursor and returns a modifiable
Iterator which will iterate through all the rows of this table. |
Iterator<Row> |
iterator(IterableBuilder iterBuilder) |
protected boolean |
keepSearching(ColumnMatcher columnMatcher,
Object searchInfo)
Called by findAnotherRowImpl to determine if the search should continue
after finding a row which does not match the current pattern.
|
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.
|
protected boolean |
moveToAnotherRow(boolean moveForward)
Moves to another row in the given direction as defined by this cursor.
|
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.
|
protected Object |
prepareSearchInfo(ColumnImpl columnPattern,
Object valuePattern)
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)
Called before a search commences to allow for search specific data to be
generated (which is cached for re-use by the iterators).
|
void |
reset()
Resets this cursor for forward traversal.
|
protected void |
reset(boolean moveForward)
Resets this cursor for traversing the given direction.
|
protected void |
restorePosition(CursorImpl.PositionImpl curPos)
Restores a current position for the cursor (current position becomes
previous position).
|
protected void |
restorePosition(CursorImpl.PositionImpl curPos,
CursorImpl.PositionImpl prevPos)
Restores a current and previous position for the cursor if the given
positions are different from the current positions.
|
protected void |
restorePositionImpl(CursorImpl.PositionImpl curPos,
CursorImpl.PositionImpl prevPos)
Restores a current and previous position for the cursor.
|
void |
restoreSavepoint(Cursor.Savepoint savepoint)
Moves the cursor to a savepoint previously returned from
Cursor.getSavepoint(). |
void |
restoreSavepoint(CursorImpl.SavepointImpl savepoint) |
void |
setColumnMatcher(ColumnMatcher columnMatcher)
Sets a new ColumnMatcher.
|
void |
setCurrentRowValue(ColumnImpl column,
Object value) |
void |
setCurrentRowValue(Column column,
Object value)
Updates a single value in the current row.
|
void |
setErrorHandler(ErrorHandler newErrorHandler)
Sets a new ErrorHandler.
|
String |
toString() |
Object[] |
updateCurrentRow(Object... row)
Update the current row.
|
<M extends Map<String,Object>> |
updateCurrentRowFromMap(M row)
Update the current row.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitforEach, spliteratorpublic static final boolean MOVE_FORWARD
public static final boolean MOVE_REVERSE
protected CursorImpl.PositionImpl _prevPos
protected CursorImpl.PositionImpl _curPos
protected ColumnMatcher _columnMatcher
protected CursorImpl(CursorImpl.IdImpl id, TableImpl table, CursorImpl.PositionImpl firstPos, CursorImpl.PositionImpl lastPos)
public static CursorImpl createCursor(TableImpl table)
table - the table over which this cursor will traversepublic TableImpl.RowState getRowState()
public CursorImpl.IdImpl getId()
public JetFormat getFormat()
public PageChannel getPageChannel()
public ErrorHandler getErrorHandler()
Cursornull).
This will be used to handle all errors.getErrorHandler in interface Cursorpublic void setErrorHandler(ErrorHandler newErrorHandler)
Cursornull, resets to using the
ErrorHandler configured at the Table level.setErrorHandler in interface Cursorpublic ColumnMatcher getColumnMatcher()
Cursornull.getColumnMatcher in interface Cursorpublic void setColumnMatcher(ColumnMatcher columnMatcher)
Cursornull, resets to using the default
matcher (default depends on Cursor type).setColumnMatcher in interface Cursorprotected ColumnMatcher getDefaultColumnMatcher()
public CursorImpl.SavepointImpl getSavepoint()
CursorCursor.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.
getSavepoint in interface Cursorpublic void restoreSavepoint(Cursor.Savepoint savepoint) throws IOException
CursorCursor.getSavepoint().restoreSavepoint in interface CursorIOExceptionpublic void restoreSavepoint(CursorImpl.SavepointImpl savepoint) throws IOException
IOExceptionprotected CursorImpl.PositionImpl getFirstPosition()
protected CursorImpl.PositionImpl getLastPosition()
public void reset()
CursorCursor.beforeFirst().public void beforeFirst()
CursorbeforeFirst in interface Cursorpublic void afterLast()
Cursorpublic boolean isBeforeFirst()
throws IOException
Cursortrue if the cursor is currently positioned before the
first row, false otherwise.isBeforeFirst in interface CursorIOExceptionpublic boolean isAfterLast()
throws IOException
Cursortrue if the cursor is currently positioned after the
last row, false otherwise.isAfterLast in interface CursorIOExceptionprotected boolean isAtBeginning(boolean moveForward)
throws IOException
IOExceptionpublic boolean isCurrentRowDeleted()
throws IOException
Cursortrue if the row at which the cursor is currently
positioned is deleted, false otherwise (including invalid rows).isCurrentRowDeleted in interface CursorIOExceptionprotected void reset(boolean moveForward)
public Iterator<Row> iterator()
CursorCursor.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
Cursor.getNextRow().
For more flexible iteration see Cursor.newIterable().public IterableBuilder newIterable()
CursornewIterable in interface Cursorpublic Iterator<Row> iterator(IterableBuilder iterBuilder)
public void deleteCurrentRow()
throws IOException
CursordeleteCurrentRow in interface CursorIOExceptionpublic Object[] updateCurrentRow(Object... row) throws IOException
CursorupdateCurrentRow in interface CursorIOExceptionpublic <M extends Map<String,Object>> M updateCurrentRowFromMap(M row) throws IOException
CursorupdateCurrentRowFromMap in interface CursorIOExceptionpublic Row getNextRow() throws IOException
CursorgetNextRow in interface Cursornull if no next row is foundIOExceptionpublic Row getNextRow(Collection<String> columnNames) throws IOException
CursorgetNextRow in interface CursorcolumnNames - Only column names in this collection will be returnednull if no next row is foundIOExceptionpublic Row getPreviousRow() throws IOException
CursorgetPreviousRow in interface Cursornull if no previous row is foundIOExceptionpublic Row getPreviousRow(Collection<String> columnNames) throws IOException
CursorgetPreviousRow in interface CursorcolumnNames - Only column names in this collection will be returnednull if no previous row is foundIOExceptionpublic boolean moveToNextRow()
throws IOException
CursormoveToNextRow in interface Cursortrue if a valid next row was found, false
otherwiseIOExceptionpublic boolean moveToPreviousRow()
throws IOException
CursormoveToPreviousRow in interface Cursortrue if a valid previous row was found, false
otherwiseIOExceptionprotected boolean moveToAnotherRow(boolean moveForward)
throws IOException
true if another valid row was found in the given
direction, false otherwiseIOExceptionprotected void restorePosition(CursorImpl.PositionImpl curPos) throws IOException
IOExceptionprotected final void restorePosition(CursorImpl.PositionImpl curPos, CursorImpl.PositionImpl prevPos) throws IOException
IOExceptionprotected void restorePositionImpl(CursorImpl.PositionImpl curPos, CursorImpl.PositionImpl prevPos) throws IOException
IOExceptionpublic boolean findRow(RowId rowId) throws IOException
CursorfindRow in interface Cursortrue if a valid row was found with the given id,
false if no row was foundIOExceptionpublic boolean findFirstRow(Column columnPattern, Object valuePattern) throws IOException
CursorWarning, this method always starts searching from the beginning of the Table (you cannot use it to find successive matches).
findFirstRow in interface CursorcolumnPattern - 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 rowtrue if a valid row was found with the given value,
false if no row was foundIOExceptionpublic boolean findFirstRow(ColumnImpl columnPattern, Object valuePattern) throws IOException
IOExceptionpublic boolean findNextRow(Column columnPattern, Object valuePattern) throws IOException
CursorfindNextRow in interface CursorcolumnPattern - 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 rowtrue if a valid row was found with the given value,
false if no row was foundIOExceptionpublic boolean findNextRow(ColumnImpl columnPattern, Object valuePattern) throws IOException
IOExceptionprotected boolean findAnotherRow(ColumnImpl columnPattern, Object valuePattern, boolean reset, boolean moveForward, ColumnMatcher columnMatcher, Object searchInfo) throws IOException
IOExceptionpublic boolean findFirstRow(Map<String,?> rowPattern) throws IOException
CursorWarning, this method always starts searching from the beginning of the Table (you cannot use it to find successive matches).
findFirstRow in interface CursorrowPattern - column names and values which must be equal to the
corresponding values in the matched rowtrue if a valid row was found with the given values,
false if no row was foundIOExceptionpublic boolean findNextRow(Map<String,?> rowPattern) throws IOException
CursorfindNextRow in interface CursorrowPattern - column names and values which must be equal to the
corresponding values in the matched rowtrue if a valid row was found with the given values,
false if no row was foundIOExceptionprotected boolean findAnotherRow(Map<String,?> rowPattern, boolean reset, boolean moveForward, ColumnMatcher columnMatcher, Object searchInfo) throws IOException
IOExceptionpublic boolean currentRowMatches(Column columnPattern, Object valuePattern) throws IOException
Cursortrue if the current row matches the given pattern.currentRowMatches in interface CursorcolumnPattern - 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 rowIOExceptionpublic boolean currentRowMatches(ColumnImpl columnPattern, Object valuePattern) throws IOException
IOExceptionprotected boolean currentRowMatchesImpl(ColumnImpl columnPattern, Object valuePattern, ColumnMatcher columnMatcher) throws IOException
IOExceptionpublic boolean currentRowMatches(Map<String,?> rowPattern) throws IOException
Cursortrue if the current row matches the given pattern.currentRowMatches in interface CursorrowPattern - column names and values which must be equal to the
corresponding values in the current rowIOExceptionprotected boolean currentRowMatchesImpl(Map<String,?> rowPattern, ColumnMatcher columnMatcher) throws IOException
IOExceptionprotected boolean findAnotherRowImpl(ColumnImpl columnPattern, Object valuePattern, boolean moveForward, ColumnMatcher columnMatcher, Object searchInfo) throws IOException
Default implementation scans the table from beginning to end.
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 rowtrue if a valid row was found with the given value,
false if no row was foundIOExceptionprotected boolean findAnotherRowImpl(Map<String,?> rowPattern, boolean moveForward, ColumnMatcher columnMatcher, Object searchInfo) throws IOException
Default implementation scans the table from beginning to end.
rowPattern - column names and values which must be equal to the
corresponding values in the matched rowtrue if a valid row was found with the given values,
false if no row was foundIOExceptionprotected Object prepareSearchInfo(ColumnImpl columnPattern, Object valuePattern)
protected Object prepareSearchInfo(Map<String,?> rowPattern)
protected boolean keepSearching(ColumnMatcher columnMatcher, Object searchInfo) throws IOException
IOExceptionpublic int moveNextRows(int numRows)
throws IOException
CursormoveNextRows in interface CursorIOExceptionpublic int movePreviousRows(int numRows)
throws IOException
CursormovePreviousRows in interface CursorIOExceptionpublic Row getCurrentRow() throws IOException
CursorgetCurrentRow in interface CursorIOExceptionpublic Row getCurrentRow(Collection<String> columnNames) throws IOException
CursorgetCurrentRow in interface CursorcolumnNames - Only column names in this collection will be returnedIOExceptionpublic Object getCurrentRowValue(Column column) throws IOException
CursorgetCurrentRowValue in interface CursorIOExceptionpublic Object getCurrentRowValue(ColumnImpl column) throws IOException
IOExceptionpublic void setCurrentRowValue(Column column, Object value) throws IOException
CursorsetCurrentRowValue in interface CursorIOExceptionpublic void setCurrentRowValue(ColumnImpl column, Object value) throws IOException
IOExceptionprotected boolean isUpToDate()
true if this cursor is up-to-date with respect to the
relevant table and related table objects, false otherwise.protected boolean isCurrentRowValid()
throws IOException
true of the current row is valid, false otherwise.IOExceptionprotected abstract CursorImpl.PositionImpl getRowPosition(RowIdImpl rowId) throws IOException
IOExceptionprotected abstract CursorImpl.PositionImpl findAnotherPosition(TableImpl.RowState rowState, CursorImpl.PositionImpl curPos, boolean moveForward) throws IOException
false. If there are no more rows, the returned
rowId should equal the value returned by getLastPosition() if
moving forward and getFirstPosition() if moving backward.IOExceptionprotected abstract CursorImpl.DirHandler getDirHandler(boolean moveForward)
Copyright © 2005–2016. All rights reserved.