Class CursorImpl
- java.lang.Object
-
- com.healthmarketscience.jackcess.impl.CursorImpl
-
- Direct Known Subclasses:
IndexCursorImpl,TableScanCursor
public abstract class CursorImpl extends Object implements 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.
- Author:
- James Ahlborn
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.healthmarketscience.jackcess.Cursor
Cursor.Id, Cursor.Position, Cursor.Savepoint
-
-
Field Summary
Fields Modifier and Type Field Description static booleanMOVE_FORWARDboolean value indicating forward movementstatic booleanMOVE_REVERSEboolean value indicating reverse movement
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterLast()Resets this cursor for reverse traversal (sets cursor to after the last row).voidbeforeFirst()Resets this cursor for forward traversal (sets cursor to before the first row).static CursorImplcreateCursor(TableImpl table)Creates a normal, un-indexed cursor for the given table.booleancurrentRowMatches(Column columnPattern, Object valuePattern)Returnstrueif the current row matches the given pattern.booleancurrentRowMatches(ColumnImpl columnPattern, Object valuePattern)booleancurrentRowMatches(Map<String,?> rowPattern)Returnstrueif the current row matches the given pattern.voiddeleteCurrentRow()Delete the current row.booleanfindFirstRow(Column columnPattern, Object valuePattern)Moves to the first row (as defined by the cursor) where the given column has the given value.booleanfindFirstRow(ColumnImpl columnPattern, Object valuePattern)booleanfindFirstRow(Map<String,?> rowPattern)Moves to the first row (as defined by the cursor) where the given columns have the given values.booleanfindNextRow(Column columnPattern, Object valuePattern)Moves to the next row (as defined by the cursor) where the given column has the given value.booleanfindNextRow(ColumnImpl columnPattern, Object valuePattern)booleanfindNextRow(Map<String,?> rowPattern)Moves to the next row (as defined by the cursor) where the given columns have the given values.booleanfindRow(RowId rowId)Moves to the row with the given rowId.ColumnMatchergetColumnMatcher()Returns the currently configured ColumnMatcher, always non-null.RowgetCurrentRow()Returns the current row in this cursor (Column name -> Column value).RowgetCurrentRow(Collection<String> columnNames)Returns the current row in this cursor (Column name -> Column value).ObjectgetCurrentRowValue(Column column)Returns the given column from the current row.ObjectgetCurrentRowValue(ColumnImpl column)ErrorHandlergetErrorHandler()Gets the currently configured ErrorHandler (always non-null).JetFormatgetFormat()com.healthmarketscience.jackcess.impl.CursorImpl.IdImplgetId()RowgetNextRow()Moves to the next row in the table and returns it.RowgetNextRow(Collection<String> columnNames)Moves to the next row in the table and returns it.PageChannelgetPageChannel()RowgetPreviousRow()Moves to the previous row in the table and returns it.RowgetPreviousRow(Collection<String> columnNames)Moves to the previous row in the table and returns it.TableImpl.RowStategetRowState()com.healthmarketscience.jackcess.impl.CursorImpl.SavepointImplgetSavepoint()Returns the current state of the cursor which can be restored at a future point in time by a call toCursor.restoreSavepoint(com.healthmarketscience.jackcess.Cursor.Savepoint).TableImplgetTable()booleanisAfterLast()Returnstrueif the cursor is currently positioned after the last row,falseotherwise.booleanisBeforeFirst()Returnstrueif the cursor is currently positioned before the first row,falseotherwise.booleanisCurrentRowDeleted()Returnstrueif the row at which the cursor is currently positioned is deleted,falseotherwise (including invalid rows).Iterator<Row>iterator()CallsCursor.beforeFirst()on this cursor and returns a modifiable Iterator which will iterate through all the rows of this table.Iterator<Row>iterator(IterableBuilder iterBuilder)intmoveNextRows(int numRows)Moves forward as many rows as possible up to the given number of rows.intmovePreviousRows(int numRows)Moves backward as many rows as possible up to the given number of rows.booleanmoveToNextRow()Moves to the next row as defined by this cursor.booleanmoveToPreviousRow()Moves to the previous row as defined by this cursor.IterableBuildernewIterable()Convenience method for constructing a new IterableBuilder for this cursor.voidreset()Resets this cursor for forward traversal.voidrestoreSavepoint(Cursor.Savepoint savepoint)Moves the cursor to a savepoint previously returned fromCursor.getSavepoint().voidrestoreSavepoint(com.healthmarketscience.jackcess.impl.CursorImpl.SavepointImpl savepoint)voidsetColumnMatcher(ColumnMatcher columnMatcher)Sets a new ColumnMatcher.voidsetCurrentRowValue(Column column, Object value)Updates a single value in the current row.voidsetCurrentRowValue(ColumnImpl column, Object value)voidsetErrorHandler(ErrorHandler newErrorHandler)Sets a new ErrorHandler.StringtoString()Object[]updateCurrentRow(Object... row)Update the current row.<M extends Map<String,Object>>
MupdateCurrentRowFromMap(M row)Update the current row.-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Field Detail
-
MOVE_FORWARD
public static final boolean MOVE_FORWARD
boolean value indicating forward movement- See Also:
- Constant Field Values
-
MOVE_REVERSE
public static final boolean MOVE_REVERSE
boolean value indicating reverse movement- See Also:
- Constant Field Values
-
-
Method Detail
-
createCursor
public static CursorImpl createCursor(TableImpl table)
Creates a normal, un-indexed cursor for the given table.- Parameters:
table- the table over which this cursor will traverse
-
getRowState
public TableImpl.RowState getRowState()
-
getId
public com.healthmarketscience.jackcess.impl.CursorImpl.IdImpl getId()
-
getFormat
public JetFormat getFormat()
-
getPageChannel
public PageChannel getPageChannel()
-
getErrorHandler
public ErrorHandler getErrorHandler()
Description copied from interface:CursorGets the currently configured ErrorHandler (always non-null). This will be used to handle all errors.- Specified by:
getErrorHandlerin interfaceCursor
-
setErrorHandler
public void setErrorHandler(ErrorHandler newErrorHandler)
Description copied from interface:CursorSets a new ErrorHandler. Ifnull, resets to using the ErrorHandler configured at the Table level.- Specified by:
setErrorHandlerin interfaceCursor
-
getColumnMatcher
public ColumnMatcher getColumnMatcher()
Description copied from interface:CursorReturns the currently configured ColumnMatcher, always non-null.- Specified by:
getColumnMatcherin interfaceCursor
-
setColumnMatcher
public void setColumnMatcher(ColumnMatcher columnMatcher)
Description copied from interface:CursorSets a new ColumnMatcher. Ifnull, resets to using the default matcher (default depends on Cursor type).- Specified by:
setColumnMatcherin interfaceCursor
-
getSavepoint
public com.healthmarketscience.jackcess.impl.CursorImpl.SavepointImpl getSavepoint()
Description copied from interface:CursorReturns the current state of the cursor which can be restored at a future point in time by a call toCursor.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.- Specified by:
getSavepointin interfaceCursor
-
restoreSavepoint
public void restoreSavepoint(Cursor.Savepoint savepoint) throws IOException
Description copied from interface:CursorMoves the cursor to a savepoint previously returned fromCursor.getSavepoint().- Specified by:
restoreSavepointin interfaceCursor- Throws:
IOException
-
restoreSavepoint
public void restoreSavepoint(com.healthmarketscience.jackcess.impl.CursorImpl.SavepointImpl savepoint) throws IOException- Throws:
IOException
-
reset
public void reset()
Description copied from interface:CursorResets this cursor for forward traversal. CallsCursor.beforeFirst().
-
beforeFirst
public void beforeFirst()
Description copied from interface:CursorResets this cursor for forward traversal (sets cursor to before the first row).- Specified by:
beforeFirstin interfaceCursor
-
afterLast
public void afterLast()
Description copied from interface:CursorResets this cursor for reverse traversal (sets cursor to after the last row).
-
isBeforeFirst
public boolean isBeforeFirst() throws IOExceptionDescription copied from interface:CursorReturnstrueif the cursor is currently positioned before the first row,falseotherwise.- Specified by:
isBeforeFirstin interfaceCursor- Throws:
IOException
-
isAfterLast
public boolean isAfterLast() throws IOExceptionDescription copied from interface:CursorReturnstrueif the cursor is currently positioned after the last row,falseotherwise.- Specified by:
isAfterLastin interfaceCursor- Throws:
IOException
-
isCurrentRowDeleted
public boolean isCurrentRowDeleted() throws IOExceptionDescription copied from interface:CursorReturnstrueif the row at which the cursor is currently positioned is deleted,falseotherwise (including invalid rows).- Specified by:
isCurrentRowDeletedin interfaceCursor- Throws:
IOException
-
iterator
public Iterator<Row> iterator()
Description copied from interface:CursorCallsCursor.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 toCursor.getNextRow().For more flexible iteration see
Cursor.newIterable().
-
newIterable
public IterableBuilder newIterable()
Description copied from interface:CursorConvenience method for constructing a new IterableBuilder for this cursor. An IterableBuilder provides a variety of options for more flexible iteration.- Specified by:
newIterablein interfaceCursor
-
iterator
public Iterator<Row> iterator(IterableBuilder iterBuilder)
-
deleteCurrentRow
public void deleteCurrentRow() throws IOExceptionDescription copied from interface:CursorDelete the current row.Note, re-deleting an already deleted row is allowed (it does nothing).
- Specified by:
deleteCurrentRowin interfaceCursor- Throws:
IOException
-
updateCurrentRow
public Object[] updateCurrentRow(Object... row) throws IOException
Description copied from interface:CursorUpdate the current row.- Specified by:
updateCurrentRowin interfaceCursor- Returns:
- the given row values if long enough, otherwise a new array, updated with the current row values
- Throws:
IOException
-
updateCurrentRowFromMap
public <M extends Map<String,Object>> M updateCurrentRowFromMap(M row) throws IOException
Description copied from interface:CursorUpdate the current row.- Specified by:
updateCurrentRowFromMapin interfaceCursor- Returns:
- the given row, updated with the current row values
- Throws:
IOException
-
getNextRow
public Row getNextRow() throws IOException
Description copied from interface:CursorMoves to the next row in the table and returns it.- Specified by:
getNextRowin interfaceCursor- Returns:
- The next row in this table (Column name -> Column value), or
nullif no next row is found - Throws:
IOException
-
getNextRow
public Row getNextRow(Collection<String> columnNames) throws IOException
Description copied from interface:CursorMoves to the next row in the table and returns it.- Specified by:
getNextRowin interfaceCursor- Parameters:
columnNames- Only column names in this collection will be returned- Returns:
- The next row in this table (Column name -> Column value), or
nullif no next row is found - Throws:
IOException
-
getPreviousRow
public Row getPreviousRow() throws IOException
Description copied from interface:CursorMoves to the previous row in the table and returns it.- Specified by:
getPreviousRowin interfaceCursor- Returns:
- The previous row in this table (Column name -> Column value), or
nullif no previous row is found - Throws:
IOException
-
getPreviousRow
public Row getPreviousRow(Collection<String> columnNames) throws IOException
Description copied from interface:CursorMoves to the previous row in the table and returns it.- Specified by:
getPreviousRowin interfaceCursor- Parameters:
columnNames- Only column names in this collection will be returned- Returns:
- The previous row in this table (Column name -> Column value), or
nullif no previous row is found - Throws:
IOException
-
moveToNextRow
public boolean moveToNextRow() throws IOExceptionDescription copied from interface:CursorMoves to the next row as defined by this cursor.- Specified by:
moveToNextRowin interfaceCursor- Returns:
trueif a valid next row was found,falseotherwise- Throws:
IOException
-
moveToPreviousRow
public boolean moveToPreviousRow() throws IOExceptionDescription copied from interface:CursorMoves to the previous row as defined by this cursor.- Specified by:
moveToPreviousRowin interfaceCursor- Returns:
trueif a valid previous row was found,falseotherwise- Throws:
IOException
-
findRow
public boolean findRow(RowId rowId) throws IOException
Description copied from interface:CursorMoves to the row with the given rowId. If the row is not found (or an exception is thrown), the cursor is restored to its previous state.- Specified by:
findRowin interfaceCursor- Returns:
trueif a valid row was found with the given id,falseif no row was found- Throws:
IOException
-
findFirstRow
public boolean findFirstRow(Column columnPattern, Object valuePattern) throws IOException
Description copied from interface:CursorMoves to the first row (as defined by the cursor) where the given column has the given value. This may be more efficient on some cursors than others. If a match is not found (or an exception is thrown), the cursor is restored to its previous state.Warning, this method always starts searching from the beginning of the Table (you cannot use it to find successive matches).
- Specified by:
findFirstRowin interfaceCursor- Parameters:
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 ofPredicate, it will be applied to the potential row value instead (overriding any configured ColumnMatcher)- Returns:
trueif a valid row was found with the given value,falseif no row was found- Throws:
IOException
-
findFirstRow
public boolean findFirstRow(ColumnImpl columnPattern, Object valuePattern) throws IOException
- Throws:
IOException
-
findNextRow
public boolean findNextRow(Column columnPattern, Object valuePattern) throws IOException
Description copied from interface:CursorMoves to the next row (as defined by the cursor) where the given column has the given value. This may be more efficient on some cursors than others. If a match is not found (or an exception is thrown), the cursor is restored to its previous state.- Specified by:
findNextRowin interfaceCursor- Parameters:
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 ofPredicate, it will be applied to the potential row value instead (overriding any configured ColumnMatcher)- Returns:
trueif a valid row was found with the given value,falseif no row was found- Throws:
IOException
-
findNextRow
public boolean findNextRow(ColumnImpl columnPattern, Object valuePattern) throws IOException
- Throws:
IOException
-
findFirstRow
public boolean findFirstRow(Map<String,?> rowPattern) throws IOException
Description copied from interface:CursorMoves to the first row (as defined by the cursor) where the given columns have the given values. This may be more efficient on some cursors than others. If a match is not found (or an exception is thrown), the cursor is restored to its previous state.Warning, this method always starts searching from the beginning of the Table (you cannot use it to find successive matches).
- Specified by:
findFirstRowin interfaceCursor- Parameters:
rowPattern- column names and values which must be equal to the corresponding values in the matched row. If a value is an instance ofPredicate, it will be applied to the potential row value instead (overriding any configured ColumnMatcher)- Returns:
trueif a valid row was found with the given values,falseif no row was found- Throws:
IOException
-
findNextRow
public boolean findNextRow(Map<String,?> rowPattern) throws IOException
Description copied from interface:CursorMoves to the next row (as defined by the cursor) where the given columns have the given values. This may be more efficient on some cursors than others. If a match is not found (or an exception is thrown), the cursor is restored to its previous state.- Specified by:
findNextRowin interfaceCursor- Parameters:
rowPattern- column names and values which must be equal to the corresponding values in the matched row. If a value is an instance ofPredicate, it will be applied to the potential row value instead (overriding any configured ColumnMatcher)- Returns:
trueif a valid row was found with the given values,falseif no row was found- Throws:
IOException
-
currentRowMatches
public boolean currentRowMatches(Column columnPattern, Object valuePattern) throws IOException
Description copied from interface:CursorReturnstrueif the current row matches the given pattern.- Specified by:
currentRowMatchesin interfaceCursor- Parameters:
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 ofPredicate, it will be applied to the potential row value instead (overriding any configured ColumnMatcher)- Throws:
IOException
-
currentRowMatches
public boolean currentRowMatches(ColumnImpl columnPattern, Object valuePattern) throws IOException
- Throws:
IOException
-
currentRowMatches
public boolean currentRowMatches(Map<String,?> rowPattern) throws IOException
Description copied from interface:CursorReturnstrueif the current row matches the given pattern.- Specified by:
currentRowMatchesin interfaceCursor- Parameters:
rowPattern- column names and values which must be equal to the corresponding values in the matched row. If a value is an instance ofPredicate, it will be applied to the potential row value instead (overriding any configured ColumnMatcher)- Throws:
IOException
-
moveNextRows
public int moveNextRows(int numRows) throws IOExceptionDescription copied from interface:CursorMoves forward as many rows as possible up to the given number of rows.- Specified by:
moveNextRowsin interfaceCursor- Returns:
- the number of rows moved.
- Throws:
IOException
-
movePreviousRows
public int movePreviousRows(int numRows) throws IOExceptionDescription copied from interface:CursorMoves backward as many rows as possible up to the given number of rows.- Specified by:
movePreviousRowsin interfaceCursor- Returns:
- the number of rows moved.
- Throws:
IOException
-
getCurrentRow
public Row getCurrentRow() throws IOException
Description copied from interface:CursorReturns the current row in this cursor (Column name -> Column value).- Specified by:
getCurrentRowin interfaceCursor- Throws:
IOException
-
getCurrentRow
public Row getCurrentRow(Collection<String> columnNames) throws IOException
Description copied from interface:CursorReturns the current row in this cursor (Column name -> Column value).- Specified by:
getCurrentRowin interfaceCursor- Parameters:
columnNames- Only column names in this collection will be returned- Throws:
IOException
-
getCurrentRowValue
public Object getCurrentRowValue(Column column) throws IOException
Description copied from interface:CursorReturns the given column from the current row.- Specified by:
getCurrentRowValuein interfaceCursor- Throws:
IOException
-
getCurrentRowValue
public Object getCurrentRowValue(ColumnImpl column) throws IOException
- Throws:
IOException
-
setCurrentRowValue
public void setCurrentRowValue(Column column, Object value) throws IOException
Description copied from interface:CursorUpdates a single value in the current row.- Specified by:
setCurrentRowValuein interfaceCursor- Throws:
IOException
-
setCurrentRowValue
public void setCurrentRowValue(ColumnImpl column, Object value) throws IOException
- Throws:
IOException
-
-