public class CursorBuilder extends 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"));
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,
Object[] startRow,
boolean startInclusive,
Object[] endRow,
boolean endInclusive)
Creates an indexed cursor for the given table, narrowed to the given
range.
|
static IndexCursor |
createCursor(Index index,
Object[] startRow,
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,
Map<String,?> rowPattern)
Convenience method for finding a specific row in an indexed table which
matches a given row "pattern".
|
static Row |
findRow(Table table,
Map<String,?> rowPattern)
Convenience method for finding a specific row in a table which matches a
given row "pattern".
|
static Row |
findRowByEntry(Index index,
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,
Object... entryValues)
Convenience method for finding a specific row by the primary key of the
table.
|
static Object |
findValue(Index index,
Column column,
Column columnPattern,
Object valuePattern)
Convenience method for finding a specific row in a table which matches a
given row "pattern".
|
static Object |
findValue(Table table,
Column column,
Column columnPattern,
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 |
setCaseInsensitive()
Sets the ColumnMatcher to an instance of CaseInsensitiveColumnMatcher
|
CursorBuilder |
setColumnMatcher(ColumnMatcher columnMatcher)
Sets the ColumnMatcher to use for matching row patterns.
|
CursorBuilder |
setEndEntry(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(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(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.
|
CursorBuilder |
setIndexByName(String indexName)
Sets an index to use for the cursor by searching the table for an index
with the given name.
|
CursorBuilder |
setSpecificEntry(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(Object... specificRow)
Sets the starting and ending row for a range based index cursor.
|
CursorBuilder |
setStartEntry(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(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.
|
public CursorBuilder(Table table)
public CursorBuilder beforeFirst()
public CursorBuilder afterLast()
public CursorBuilder restoreSavepoint(Cursor.Savepoint savepoint)
public CursorBuilder setIndex(Index index)
public CursorBuilder setIndexByName(String indexName)
IllegalArgumentException
- if no index can be found on the table
with the given namepublic CursorBuilder setIndexByColumnNames(String... columnNames)
IllegalArgumentException
- if no index can be found on the table
with the given columnspublic CursorBuilder setIndexByColumns(Column... columns)
IllegalArgumentException
- if no index can be found on the table
with the given columnspublic CursorBuilder setSpecificRow(Object... specificRow)
A valid index must be specified before calling this method.
public CursorBuilder setSpecificEntry(Object... specificEntry)
A valid index must be specified before calling this method.
public CursorBuilder setStartRow(Object... startRow)
A valid index must be specified before calling this method.
public CursorBuilder setStartEntry(Object... startEntry)
A valid index must be specified before calling this method.
public CursorBuilder setStartRowInclusive(boolean inclusive)
public CursorBuilder setEndRow(Object... endRow)
A valid index must be specified before calling this method.
public CursorBuilder setEndEntry(Object... endEntry)
A valid index must be specified before calling this method.
public CursorBuilder setEndRowInclusive(boolean inclusive)
public CursorBuilder setColumnMatcher(ColumnMatcher columnMatcher)
public CursorBuilder setCaseInsensitive()
public Cursor toCursor() throws IOException
IOException
public IndexCursor toIndexCursor() throws IOException
IOException
public static Cursor createCursor(Table table) throws IOException
table
- the table over which this cursor will traverseIOException
public static IndexCursor createCursor(Index index) throws 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 lookupsIOException
public static IndexCursor createPrimaryKeyCursor(Table table) throws IOException
table
- the table over which this cursor will traverseIOException
public static IndexCursor createCursor(Index index, Object[] startRow, Object[] endRow) throws 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 entryIOException
public static IndexCursor createCursor(Index index, Object[] startRow, boolean startInclusive, Object[] endRow, boolean endInclusive) throws 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 exclusiveIOException
public static Row findRow(Table table, Map<String,?> rowPattern) throws 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.IOException
public static Row findRowByEntry(Index index, Object... entryValues) throws 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.IOException
public static Row findRowByPrimaryKey(Table table, Object... entryValues) throws 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.IOException
public static Object findValue(Table table, Column column, Column columnPattern, Object valuePattern) throws 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.IOException
public static Row findRow(Index index, Map<String,?> rowPattern) throws 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.IOException
public static Object findValue(Index index, Column column, Column columnPattern, Object valuePattern) throws 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.IOException
Copyright © 2005–2024 OpenHMS. All rights reserved.