public class CursorBuilder
extends java.lang.Object
Cursor. By default, a
cursor is created at the beginning of the table, and any start/end rows are
inclusive.
Simple example traversal:
for(Row row : table.newCursor().toCursor()) {
// ... process each row ...
}
Simple example search:
Row row = CursorBuilder.findRow(table, Collections.singletonMap(col, "foo"));
| Modifier and Type | Field and Description |
|---|---|
private boolean |
_beforeFirst
whether to start at beginning or end of cursor
|
private ColumnMatcher |
_columnMatcher
ColumnMatcher to be used when matching column values
|
private java.lang.Object[] |
_endRow
optional end row for an index cursor
|
private boolean |
_endRowInclusive
whether or not end row for an index cursor is inclusive
|
private IndexImpl |
_index
optional index to use in traversal
|
private Cursor.Savepoint |
_savepoint
optional save point to restore to the cursor
|
private java.lang.Object[] |
_startRow
optional start row for an index cursor
|
private boolean |
_startRowInclusive
whether or not start row for an index cursor is inclusive
|
private TableImpl |
_table
the table which the cursor will traverse
|
| Constructor and Description |
|---|
CursorBuilder(Table table) |
| Modifier and Type | Method and Description |
|---|---|
CursorBuilder |
afterLast()
Sets the cursor so that it will start at the end (unless a savepoint is
given).
|
CursorBuilder |
beforeFirst()
Sets the cursor so that it will start at the beginning (unless a
savepoint is given).
|
static IndexCursor |
createCursor(Index index)
Creates an indexed cursor for the given table.
|
static IndexCursor |
createCursor(Index index,
java.lang.Object[] startRow,
boolean startInclusive,
java.lang.Object[] endRow,
boolean endInclusive)
Creates an indexed cursor for the given table, narrowed to the given
range.
|
static IndexCursor |
createCursor(Index index,
java.lang.Object[] startRow,
java.lang.Object[] endRow)
Creates an indexed cursor for the given table, narrowed to the given
range.
|
static Cursor |
createCursor(Table table)
Creates a normal, un-indexed cursor for the given table.
|
static IndexCursor |
createPrimaryKeyCursor(Table table)
Creates an indexed cursor for the primary key cursor of the given table.
|
static Row |
findRow(Index index,
java.util.Map<java.lang.String,?> rowPattern)
Convenience method for finding a specific row in an indexed table which
matches a given row "pattern".
|
static Row |
findRow(Table table,
java.util.Map<java.lang.String,?> rowPattern)
Convenience method for finding a specific row in a table which matches a
given row "pattern".
|
static Row |
findRowByEntry(Index index,
java.lang.Object... entryValues)
Convenience method for finding a specific row (as defined by the cursor)
where the index entries match the given values.
|
static Row |
findRowByPrimaryKey(Table table,
java.lang.Object... entryValues)
Convenience method for finding a specific row by the primary key of the
table.
|
static java.lang.Object |
findValue(Index index,
Column column,
Column columnPattern,
java.lang.Object valuePattern)
Convenience method for finding a specific row in a table which matches a
given row "pattern".
|
static java.lang.Object |
findValue(Table table,
Column column,
Column columnPattern,
java.lang.Object valuePattern)
Convenience method for finding a specific row in a table which matches a
given row "pattern".
|
CursorBuilder |
restoreSavepoint(Cursor.Savepoint savepoint)
Sets a savepoint to restore for the initial position of the cursor.
|
CursorBuilder |
setColumnMatcher(ColumnMatcher columnMatcher)
Sets the ColumnMatcher to use for matching row patterns.
|
CursorBuilder |
setEndEntry(java.lang.Object... endEntry)
Sets the ending row for a range based index cursor to the given entry
(where the given values correspond to the index's columns).
|
CursorBuilder |
setEndRow(java.lang.Object... endRow)
Sets the ending row for a range based index cursor.
|
CursorBuilder |
setEndRowInclusive(boolean inclusive)
Sets whether the ending row for a range based index cursor is inclusive
or exclusive.
|
CursorBuilder |
setIndex(Index index)
Sets an index to use for the cursor.
|
CursorBuilder |
setIndexByColumnNames(java.lang.String... columnNames)
Sets an index to use for the cursor by searching the table for an index
with exactly the given columns.
|
CursorBuilder |
setIndexByColumns(Column... columns)
Sets an index to use for the cursor by searching the table for an index
with exactly the given columns.
|
private CursorBuilder |
setIndexByColumns(java.util.List<java.lang.String> searchColumns)
Searches for an index with the given column names.
|
CursorBuilder |
setIndexByName(java.lang.String indexName)
Sets an index to use for the cursor by searching the table for an index
with the given name.
|
CursorBuilder |
setSpecificEntry(java.lang.Object... specificEntry)
Sets the starting and ending row for a range based index cursor to the
given entry (where the given values correspond to the index's columns).
|
CursorBuilder |
setSpecificRow(java.lang.Object... specificRow)
Sets the starting and ending row for a range based index cursor.
|
CursorBuilder |
setStartEntry(java.lang.Object... startEntry)
Sets the starting row for a range based index cursor to the given entry
(where the given values correspond to the index's columns).
|
CursorBuilder |
setStartRow(java.lang.Object... startRow)
Sets the starting row for a range based index cursor.
|
CursorBuilder |
setStartRowInclusive(boolean inclusive)
Sets whether the starting row for a range based index cursor is inclusive
or exclusive.
|
Cursor |
toCursor()
Returns a new cursor for the table, constructed to the given
specifications.
|
IndexCursor |
toIndexCursor()
Returns a new index cursor for the table, constructed to the given
specifications.
|
private final TableImpl _table
private IndexImpl _index
private java.lang.Object[] _startRow
private boolean _startRowInclusive
private java.lang.Object[] _endRow
private boolean _endRowInclusive
private boolean _beforeFirst
private Cursor.Savepoint _savepoint
private ColumnMatcher _columnMatcher
public CursorBuilder(Table table)
public CursorBuilder beforeFirst()
public CursorBuilder afterLast()
public CursorBuilder restoreSavepoint(Cursor.Savepoint savepoint)
public CursorBuilder setIndex(Index index)
public CursorBuilder setIndexByName(java.lang.String indexName)
java.lang.IllegalArgumentException - if no index can be found on the table
with the given namepublic CursorBuilder setIndexByColumnNames(java.lang.String... columnNames)
java.lang.IllegalArgumentException - if no index can be found on the table
with the given columnspublic CursorBuilder setIndexByColumns(Column... columns)
java.lang.IllegalArgumentException - if no index can be found on the table
with the given columnsprivate CursorBuilder setIndexByColumns(java.util.List<java.lang.String> searchColumns)
public CursorBuilder setSpecificRow(java.lang.Object... specificRow)
A valid index must be specified before calling this method.
public CursorBuilder setSpecificEntry(java.lang.Object... specificEntry)
A valid index must be specified before calling this method.
public CursorBuilder setStartRow(java.lang.Object... startRow)
A valid index must be specified before calling this method.
public CursorBuilder setStartEntry(java.lang.Object... startEntry)
A valid index must be specified before calling this method.
public CursorBuilder setStartRowInclusive(boolean inclusive)
public CursorBuilder setEndRow(java.lang.Object... endRow)
A valid index must be specified before calling this method.
public CursorBuilder setEndEntry(java.lang.Object... endEntry)
A valid index must be specified before calling this method.
public CursorBuilder setEndRowInclusive(boolean inclusive)
public CursorBuilder setColumnMatcher(ColumnMatcher columnMatcher)
public Cursor toCursor() throws java.io.IOException
java.io.IOExceptionpublic IndexCursor toIndexCursor() throws java.io.IOException
java.io.IOExceptionpublic static Cursor createCursor(Table table) throws java.io.IOException
table - the table over which this cursor will traversejava.io.IOExceptionpublic static IndexCursor createCursor(Index index) throws java.io.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()).
index - index for the table which will define traversal order as
well as enhance certain lookupsjava.io.IOExceptionpublic static IndexCursor createPrimaryKeyCursor(Table table) throws java.io.IOException
table - the table over which this cursor will traversejava.io.IOExceptionpublic static IndexCursor createCursor(Index index, java.lang.Object[] startRow, java.lang.Object[] endRow) throws java.io.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()).
index - 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 entryjava.io.IOExceptionpublic static IndexCursor createCursor(Index index, java.lang.Object[] startRow, boolean startInclusive, java.lang.Object[] endRow, boolean endInclusive) throws java.io.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()).
index - 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 exclusivejava.io.IOExceptionpublic static Row findRow(Table table, java.util.Map<java.lang.String,?> rowPattern) throws java.io.IOException
Cursor.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 rownull if a match could not be found.java.io.IOExceptionpublic static Row findRowByEntry(Index index, java.lang.Object... entryValues) throws java.io.IOException
IndexCursor.findRowByEntry(Object...) for details on the entryValues.index - the index to searchentryValues - the column values for the index's columns.null if a match could not be found.java.io.IOExceptionpublic static Row findRowByPrimaryKey(Table table, java.lang.Object... entryValues) throws java.io.IOException
IndexCursor.findRowByEntry(Object...) for details on
the entryValues.table - the table to searchentryValues - the column values for the table's primary key columns.null if a match could not be found.java.io.IOExceptionpublic static java.lang.Object findValue(Table table, Column column, Column columnPattern, java.lang.Object valuePattern) throws java.io.IOException
Cursor.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 rownull if a match could not be found.java.io.IOExceptionpublic static Row findRow(Index index, java.util.Map<java.lang.String,?> rowPattern) throws java.io.IOException
Cursor.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).
index - index to assist the searchrowPattern - pattern to be used to find the rownull if a match could not be found.java.io.IOExceptionpublic static java.lang.Object findValue(Index index, Column column, Column columnPattern, java.lang.Object valuePattern) throws java.io.IOException
Cursor.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.
index - 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 rownull if a match could not be found.java.io.IOException