APIdia Launch Partner
Top Description Inners Methods
io.github.spannm.jackcess

public Interface Cursor

extends Iterable<Row>
Known Direct Subinterfaces
io.github.spannm.jackcess.IndexCursor
Known Direct Implementers
io.github.spannm.jackcess.impl.CursorImpl
Imports
io.github.spannm.jackcess.util.ColumnMatcher, .ErrorHandler, .IterableBuilder, java.io.IOException, .UncheckedIOException, java.util.Collection, .Iterator, .Map, java.util.stream.Stream, .StreamSupport

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.

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).

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
Cursor.Id

Identifier for a cursor.

public static interface
Cursor.Position

Value object which maintains the current position of the cursor.

public static interface
Cursor.Savepoint

Value object which represents a complete save state of the cursor.

Method Summary

Modifier and TypeMethod and Description
public void
afterLast()

Resets this cursor for reverse traversal (sets cursor to after the last row).

public void
beforeFirst()

Resets this cursor for forward traversal (sets cursor to before the first row).

public boolean
currentRowMatches(Column
column from the table for this cursor which is being matched by the valuePattern
columnPattern
,
Object
value which is equal to the corresponding value in the matched row. If this object is an instance of java.util.function.Predicate, it will be applied to the potential row value instead (overriding any configured ColumnMatcher)
valuePattern
)

Returns true if the current row matches the given pattern.

public boolean
currentRowMatches(Map<String, ?>
column names and values which must be equal to the corresponding values in the matched row. If a value is an instance of java.util.function.Predicate, it will be applied to the potential row value instead (overriding any configured ColumnMatcher)
rowPattern
)

Returns true if the current row matches the given pattern.

public void
deleteCurrentRow()

Delete the current row.

public boolean

Returns:

true if a valid row was found with the given value, false if no row was found
findFirstRow
(Column
column from the table for this cursor which is being matched by the valuePattern
columnPattern
,
Object
value which is equal to the corresponding value in the matched row. If this object is an instance of java.util.function.Predicate, it will be applied to the potential row value instead (overriding any configured ColumnMatcher)
valuePattern
)

Moves to the first row (as defined by the cursor) where the given column has the given value.

public boolean

Returns:

true if a valid row was found with the given values, false if no row was found
findFirstRow
(Map<String, ?>
column names and values which must be equal to the corresponding values in the matched row. If a value is an instance of java.util.function.Predicate, it will be applied to the potential row value instead (overriding any configured ColumnMatcher)
rowPattern
)

Moves to the first row (as defined by the cursor) where the given columns have the given values.

public boolean

Returns:

true if a valid row was found with the given value, false if no row was found
findNextRow
(Column
column from the table for this cursor which is being matched by the valuePattern
columnPattern
,
Object
value which is equal to the corresponding value in the matched row. If this object is an instance of java.util.function.Predicate, it will be applied to the potential row value instead (overriding any configured ColumnMatcher)
valuePattern
)

Moves to the next row (as defined by the cursor) where the given column has the given value.

public boolean

Returns:

true if a valid row was found with the given values, false if no row was found
findNextRow
(Map<String, ?>
column names and values which must be equal to the corresponding values in the matched row. If a value is an instance of java.util.function.Predicate, it will be applied to the potential row value instead (overriding any configured ColumnMatcher)
rowPattern
)

Moves to the next row (as defined by the cursor) where the given columns have the given values.

public boolean

Returns:

true if a valid row was found with the given id, false if no row was found
findRow
(RowId rowId)

Moves to the row with the given rowId.

public ColumnMatcher
getColumnMatcher()

Returns the currently configured ColumnMatcher, always non-null.

public Row
getCurrentRow()

Returns the current row in this cursor (Column name -> Column value).

public Row
getCurrentRow(Collection<String>
Only column names in this collection will be returned
columnNames
)

Returns the current row in this cursor (Column name -> Column value).

public Object
getCurrentRowValue(Column column)

Returns the given column from the current row.

public ErrorHandler
getErrorHandler()

Gets the currently configured ErrorHandler (always non-null).

public Cursor.Id

Returns:

the unique identifier of this cursor, usable for validating a Savepoint
getId
()

Returns the unique identifier of this cursor, usable for validating a Savepoint.

public Row

Returns:

The next row in this table (Column name -> Column value), or null if no next row is found
getNextRow
()

Moves to the next row in the table and returns it.

public Row

Returns:

The next row in this table (Column name -> Column value), or null if no next row is found
getNextRow
(Collection<String>
Only column names in this collection will be returned
columnNames
)

Moves to the next row in the table and returns it.

public Row

Returns:

The previous row in this table (Column name -> Column value), or null if no previous row is found
getPreviousRow
()

Moves to the previous row in the table and returns it.

public Row

Returns:

The previous row in this table (Column name -> Column value), or null if no previous row is found
getPreviousRow
(Collection<String>
Only column names in this collection will be returned
columnNames
)

Moves to the previous row in the table and returns it.

public 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.

public Table

Returns:

the table over which this cursor iterates
getTable
()

Returns the table over which this cursor iterates.

public boolean
isAfterLast()

Returns true if the cursor is currently positioned after the last row, false otherwise.

public boolean
isBeforeFirst()

Returns true if the cursor is currently positioned before the first row, false otherwise.

public boolean
isCurrentRowDeleted()

Returns true if the row at which the cursor is currently positioned is deleted, false otherwise (including invalid rows).

public Iterator<Row>
iterator()

Redeclares java.lang.Iterable.iterator.

Calls beforeFirst on this cursor and returns a modifiable Iterator which will iterate through all the rows of this table.

public int

Returns:

the number of rows moved.
moveNextRows
(int numRows)

Moves forward as many rows as possible up to the given number of rows.

public int

Returns:

the number of rows moved.
movePreviousRows
(int numRows)

Moves backward as many rows as possible up to the given number of rows.

public boolean

Returns:

true if a valid next row was found, false otherwise
moveToNextRow
()

Moves to the next row as defined by this cursor.

public boolean

Returns:

true if a valid previous row was found, false otherwise
moveToPreviousRow
()

Moves to the previous row as defined by this cursor.

public IterableBuilder
newIterable()

Convenience method for constructing a new IterableBuilder for this cursor.

public void
reset()

Resets this cursor for forward traversal.

public void
restoreSavepoint(Cursor.Savepoint savepoint)

Moves the cursor to a savepoint previously returned from getSavepoint.

public void
setColumnMatcher(ColumnMatcher columnMatcher)

Sets a new ColumnMatcher.

public void
setCurrentRowValue(Column column, Object value)

Updates a single value in the current row.

public void
setErrorHandler(ErrorHandler newErrorHandler)

Sets a new ErrorHandler.

public default Stream<Row>

Returns:

a Stream using the default Iterator.
stream
()

Returns a Stream using the default Iterator.

public Object[]

Returns:

the given row values if long enough, otherwise a new array, updated with the current row values
updateCurrentRow
(Object... row)

Update the current row.

public <M extends Map<String, Object>> M

Returns:

the given row, updated with the current row values
updateCurrentRowFromMap
(M row)

Update the current row.

Inherited from java.lang.Iterable:
forEachspliterator

Method Detail

afterLastback to summary
public void afterLast()

Resets this cursor for reverse traversal (sets cursor to after the last row).

beforeFirstback to summary
public void beforeFirst()

Resets this cursor for forward traversal (sets cursor to before the first row).

currentRowMatchesback to summary
public boolean currentRowMatches(Column columnPattern, Object valuePattern) throws IOException

Returns true if the current row matches the given pattern.

Parameters
columnPattern:Column

column from the table for this cursor which is being matched by the valuePattern

valuePattern:Object

value which is equal to the corresponding value in the matched row. If this object is an instance of java.util.function.Predicate, it will be applied to the potential row value instead (overriding any configured ColumnMatcher)

currentRowMatchesback to summary
public boolean currentRowMatches(Map<String, ?> rowPattern) throws IOException

Returns true if the current row matches the given pattern.

Parameters
rowPattern:Map<String, ?>

column names and values which must be equal to the corresponding values in the matched row. If a value is an instance of java.util.function.Predicate, it will be applied to the potential row value instead (overriding any configured ColumnMatcher)

deleteCurrentRowback to summary
public void deleteCurrentRow() throws IOException

Delete the current row.

Note, re-deleting an already deleted row is allowed (it does nothing).

Exceptions
IllegalStateException:
if the current row is not valid (at beginning or end of table)
findFirstRowback to summary
public boolean findFirstRow(Column columnPattern, Object valuePattern) throws IOException

Moves 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).

Parameters
columnPattern:Column

column from the table for this cursor which is being matched by the valuePattern

valuePattern:Object

value which is equal to the corresponding value in the matched row. If this object is an instance of java.util.function.Predicate, it will be applied to the potential row value instead (overriding any configured ColumnMatcher)

Returns:boolean

true if a valid row was found with the given value, false if no row was found

findFirstRowback to summary
public boolean findFirstRow(Map<String, ?> rowPattern) throws IOException

Moves 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).

Parameters
rowPattern:Map<String, ?>

column names and values which must be equal to the corresponding values in the matched row. If a value is an instance of java.util.function.Predicate, it will be applied to the potential row value instead (overriding any configured ColumnMatcher)

Returns:boolean

true if a valid row was found with the given values, false if no row was found

findNextRowback to summary
public boolean findNextRow(Column columnPattern, Object valuePattern) throws IOException

Moves 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.

Parameters
columnPattern:Column

column from the table for this cursor which is being matched by the valuePattern

valuePattern:Object

value which is equal to the corresponding value in the matched row. If this object is an instance of java.util.function.Predicate, it will be applied to the potential row value instead (overriding any configured ColumnMatcher)

Returns:boolean

true if a valid row was found with the given value, false if no row was found

findNextRowback to summary
public boolean findNextRow(Map<String, ?> rowPattern) throws IOException

Moves 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.

Parameters
rowPattern:Map<String, ?>

column names and values which must be equal to the corresponding values in the matched row. If a value is an instance of java.util.function.Predicate, it will be applied to the potential row value instead (overriding any configured ColumnMatcher)

Returns:boolean

true if a valid row was found with the given values, false if no row was found

findRowback to summary
public boolean findRow(RowId rowId) throws IOException

Moves 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.

Returns:boolean

true if a valid row was found with the given id, false if no row was found

getColumnMatcherback to summary
public ColumnMatcher getColumnMatcher()

Returns the currently configured ColumnMatcher, always non-null.

getCurrentRowback to summary
public Row getCurrentRow() throws IOException

Returns the current row in this cursor (Column name -> Column value).

getCurrentRowback to summary
public Row getCurrentRow(Collection<String> columnNames) throws IOException

Returns the current row in this cursor (Column name -> Column value).

Parameters
columnNames:Collection<String>

Only column names in this collection will be returned

getCurrentRowValueback to summary
public Object getCurrentRowValue(Column column) throws IOException

Returns the given column from the current row.

getErrorHandlerback to summary
public ErrorHandler getErrorHandler()

Gets the currently configured ErrorHandler (always non-null). This will be used to handle all errors.

getIdback to summary
public Cursor.Id getId()

Returns the unique identifier of this cursor, usable for validating a Savepoint.

Returns:Cursor.Id

the unique identifier of this cursor, usable for validating a Savepoint

getNextRowback to summary
public Row getNextRow() throws IOException

Moves to the next row in the table and returns it.

Returns:Row

The next row in this table (Column name -> Column value), or null if no next row is found

getNextRowback to summary
public Row getNextRow(Collection<String> columnNames) throws IOException

Moves to the next row in the table and returns it.

Parameters
columnNames:Collection<String>

Only column names in this collection will be returned

Returns:Row

The next row in this table (Column name -> Column value), or null if no next row is found

getPreviousRowback to summary
public Row getPreviousRow() throws IOException

Moves to the previous row in the table and returns it.

Returns:Row

The previous row in this table (Column name -> Column value), or null if no previous row is found

getPreviousRowback to summary
public Row getPreviousRow(Collection<String> columnNames) throws IOException

Moves to the previous row in the table and returns it.

Parameters
columnNames:Collection<String>

Only column names in this collection will be returned

Returns:Row

The previous row in this table (Column name -> Column value), or null if no previous row is found

getSavepointback to summary
public 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.

Savepoints may be used across different cursor instances for the same table, but they must have the same Id.

getTableback to summary
public Table getTable()

Returns the table over which this cursor iterates.

Returns:Table

the table over which this cursor iterates

isAfterLastback to summary
public boolean isAfterLast() throws IOException

Returns true if the cursor is currently positioned after the last row, false otherwise.

isBeforeFirstback to summary
public boolean isBeforeFirst() throws IOException

Returns true if the cursor is currently positioned before the first row, false otherwise.

isCurrentRowDeletedback to summary
public boolean isCurrentRowDeleted() throws IOException

Returns true if the row at which the cursor is currently positioned is deleted, false otherwise (including invalid rows).

iteratorback to summary
public Iterator<Row> iterator()

Redeclares java.lang.Iterable.iterator.

Calls 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.

Annotations
@Override
Exceptions
UncheckedIOException:
if an IOException is thrown by one of the operations, the actual exception will be contained within
moveNextRowsback to summary
public int moveNextRows(int numRows) throws IOException

Moves forward as many rows as possible up to the given number of rows.

Returns:int

the number of rows moved.

movePreviousRowsback to summary
public int movePreviousRows(int numRows) throws IOException

Moves backward as many rows as possible up to the given number of rows.

Returns:int

the number of rows moved.

moveToNextRowback to summary
public boolean moveToNextRow() throws IOException

Moves to the next row as defined by this cursor.

Returns:boolean

true if a valid next row was found, false otherwise

moveToPreviousRowback to summary
public boolean moveToPreviousRow() throws IOException

Moves to the previous row as defined by this cursor.

Returns:boolean

true if a valid previous row was found, false otherwise

newIterableback to summary
public IterableBuilder newIterable()

Convenience method for constructing a new IterableBuilder for this cursor. An IterableBuilder provides a variety of options for more flexible iteration.

resetback to summary
public void reset()

Resets this cursor for forward traversal. Calls beforeFirst.

restoreSavepointback to summary
public void restoreSavepoint(Cursor.Savepoint savepoint) throws IOException

Moves the cursor to a savepoint previously returned from getSavepoint.

Exceptions
IllegalArgumentException:
if the given savepoint does not have a cursorId equal to this cursor's id
setColumnMatcherback to summary
public void setColumnMatcher(ColumnMatcher columnMatcher)

Sets a new ColumnMatcher. If null, resets to using the default matcher (default depends on Cursor type).

setCurrentRowValueback to summary
public void setCurrentRowValue(Column column, Object value) throws IOException

Updates a single value in the current row.

Exceptions
IllegalStateException:
if the current row is not valid (at beginning or end of table), or deleted.
setErrorHandlerback to summary
public void setErrorHandler(ErrorHandler newErrorHandler)

Sets a new ErrorHandler. If null, resets to using the ErrorHandler configured at the Table level.

streamback to summary
public default Stream<Row> stream()

Returns a Stream using the default Iterator.

Returns:Stream<Row>

a Stream using the default Iterator.

updateCurrentRowback to summary
public Object[] updateCurrentRow(Object... row) throws IOException

Update the current row.

Returns:Object[]

the given row values if long enough, otherwise a new array, updated with the current row values

Exceptions
IllegalStateException:
if the current row is not valid (at beginning or end of table), or deleted.
updateCurrentRowFromMapback to summary
public <M extends Map<String, Object>> M updateCurrentRowFromMap(M row) throws IOException

Update the current row.

Returns:M

the given row, updated with the current row values

Exceptions
IllegalStateException:
if the current row is not valid (at beginning or end of table), or deleted.
io.github.spannm.jackcess back to summary

public Interface Cursor.Id

Known Direct Implementers
io.github.spannm.jackcess.impl.CursorImpl.IdImpl

Identifier for a cursor. Will be equal to any other cursor of the same type for the same table. Primarily used to check the validity of a Savepoint.
io.github.spannm.jackcess back to summary

public Interface Cursor.Position

Known Direct Implementers
io.github.spannm.jackcess.impl.CursorImpl.PositionImpl

Value object which maintains the current position of the cursor.

Method Summary

Modifier and TypeMethod and Description
public RowId
getRowId()

Returns the unique RowId of the position of the cursor.

Method Detail

getRowIdback to summary
public RowId getRowId()

Returns the unique RowId of the position of the cursor.

io.github.spannm.jackcess back to summary

public Interface Cursor.Savepoint

Known Direct Implementers
io.github.spannm.jackcess.impl.CursorImpl.SavepointImpl

Value object which represents a complete save state of the cursor. Savepoints are created by calling Cursor#getSavepoint and used by calling Cursor#restoreSavepoint to return the the cursor state at the time the Savepoint was created.

Method Summary

Modifier and TypeMethod and Description
public Cursor.Position

Returns:

the cursor position captured by this savepoint
getCurrentPosition
()

Returns the cursor position captured by this savepoint.

public Cursor.Id

Returns:

the id of the cursor this savepoint was created from, used by Cursor#restoreSavepoint to validate that the savepoint is being restored on a compatible cursor
getCursorId
()

Returns the id of the cursor this savepoint was created from, used by Cursor#restoreSavepoint to validate that the savepoint is being restored on a compatible cursor.

Method Detail

getCurrentPositionback to summary
public Cursor.Position getCurrentPosition()

Returns the cursor position captured by this savepoint.

Returns:Cursor.Position

the cursor position captured by this savepoint

getCursorIdback to summary
public Cursor.Id getCursorId()

Returns the id of the cursor this savepoint was created from, used by Cursor#restoreSavepoint to validate that the savepoint is being restored on a compatible cursor.

Returns:Cursor.Id

the id of the cursor this savepoint was created from, used by Cursor#restoreSavepoint to validate that the savepoint is being restored on a compatible cursor