APIdia Launch Partner
Top Description Fields Constructors Methods
io.github.spannm.jackcess

public Class CursorBuilder

extends Object
Class Inheritance
Imports
io.github.spannm.jackcess.impl.CursorImpl, .IndexCursorImpl, .IndexData, .IndexImpl, .TableImpl, io.github.spannm.jackcess.util.CaseInsensitiveColumnMatcher, .ColumnMatcher, java.io.IOException, java.util.ArrayList, .Arrays, .List, .Map

Builder style class for constructing a 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"));

Field Summary

Modifier and TypeField 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 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 Object[]
startRow

optional start row for an index cursor

private boolean
startRowInclusive

whether or not start row for an index cursor is inclusive

private final TableImpl
table

the table which the cursor will traverse

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public CursorBuilder
afterLast()

Sets the cursor so that it will start at the end (unless a savepoint is given).

public CursorBuilder
beforeFirst()

Sets the cursor so that it will start at the beginning (unless a savepoint is given).

public static Cursor
createCursor(Table
the table over which this cursor will traverse
table
)

Creates a normal, un-indexed cursor for the given table.

public static IndexCursor
createCursor(Index
index for the table which will define traversal order as well as enhance certain lookups
index
)

Creates an indexed cursor for the given table.

public static IndexCursor
createCursor(Index
index for the table which will define traversal order as well as enhance certain lookups
index
,
Object[]
the first row of data for the cursor (inclusive), or null for the first entry
startRow
,
Object[]
the last row of data for the cursor (inclusive), or null for the last entry
endRow
)

Creates an indexed cursor for the given table, narrowed to the given range.

public static IndexCursor
createCursor(Index
index for the table which will define traversal order as well as enhance certain lookups
index
,
Object[]
the first row of data for the cursor, or null for the first entry
startRow
,
boolean
whether or not startRow is inclusive or exclusive
startInclusive
,
Object[]
the last row of data for the cursor, or null for the last entry
endRow
,
boolean
whether or not endRow is inclusive or exclusive
endInclusive
)

Creates an indexed cursor for the given table, narrowed to the given range.

public static IndexCursor
createPrimaryKeyCursor(Table
the table over which this cursor will traverse
table
)

Creates an indexed cursor for the primary key cursor of the given table.

public static Row

Returns:

the matching row or null if a match could not be found.
findRow
(Table
the table to search
table
,
Map<String, ?>
pattern to be used to find the row
rowPattern
)

Convenience method for finding a specific row in a table which matches a given row "pattern".

public static Row

Returns:

the matching row or null if a match could not be found.
findRow
(Index
index to assist the search
index
,
Map<String, ?>
pattern to be used to find the row
rowPattern
)

Convenience method for finding a specific row in an indexed table which matches a given row "pattern".

public static Row

Returns:

the matching row or null if a match could not be found.
findRowByEntry
(Index
the index to search
index
,
Object...
the column values for the index's columns.
entryValues
)

Convenience method for finding a specific row (as defined by the cursor) where the index entries match the given values.

public static Row

Returns:

the matching row or null if a match could not be found.
findRowByPrimaryKey
(Table
the table to search
table
,
Object...
the column values for the table's primary key columns.
entryValues
)

Convenience method for finding a specific row by the primary key of the table.

public static Object

Returns:

the matching row or null if a match could not be found.
findValue
(Table
the table to search
table
,
Column
column whose value should be returned
column
,
Column
column being matched by the valuePattern
columnPattern
,
Object
value from the columnPattern which will match the desired row
valuePattern
)

Convenience method for finding a specific row in a table which matches a given row "pattern".

public static Object

Returns:

the matching row or null if a match could not be found.
findValue
(Index
index to assist the search
index
,
Column
column whose value should be returned
column
,
Column
column being matched by the valuePattern
columnPattern
,
Object
value from the columnPattern which will match the desired row
valuePattern
)

Convenience method for finding a specific row in a table which matches a given row "pattern".

public CursorBuilder
restoreSavepoint(Cursor.Savepoint newSavepoint)

Sets a savepoint to restore for the initial position of the cursor.

public Cursor
toCursor()

Returns a new cursor for the table, constructed to the given specifications.

public IndexCursor
toIndexCursor()

Returns a new index cursor for the table, constructed to the given specifications.

public CursorBuilder
withCaseInsensitive()

Sets the ColumnMatcher to an instance of CaseInsensitiveColumnMatcher

public CursorBuilder
withColumnMatcher(ColumnMatcher newColumnMatcher)

Sets the ColumnMatcher to use for matching row patterns.

public CursorBuilder
withEndEntry(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).

public CursorBuilder
withEndRow(Object... newEndRow)

Sets the ending row for a range based index cursor.

public CursorBuilder
withEndRowInclusive(boolean inclusive)

Sets whether the ending row for a range based index cursor is inclusive or exclusive.

public CursorBuilder
withIndex(Index newIndex)

Sets an index to use for the cursor.

public CursorBuilder
withIndexByColumnNames(String... columnNames)

Sets an index to use for the cursor by searching the table for an index with exactly the given columns.

public CursorBuilder
withIndexByColumns(Column... columns)

Sets an index to use for the cursor by searching the table for an index with exactly the given columns.

private CursorBuilder
withIndexByColumns(List<String> searchColumns)

Searches for an index with the given column names.

public CursorBuilder
withIndexByName(String indexName)

Sets an index to use for the cursor by searching the table for an index with the given name.

public CursorBuilder
withSpecificEntry(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).

public CursorBuilder
withSpecificRow(Object... specificRow)

Sets the starting and ending row for a range based index cursor.

public CursorBuilder
withStartEntry(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).

public CursorBuilder
withStartRow(Object... newStartRow)

Sets the starting row for a range based index cursor.

public CursorBuilder
withStartRowInclusive(boolean inclusive)

Sets whether the starting row for a range based index cursor is inclusive or exclusive.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

beforeFirstback to summary
private boolean beforeFirst

whether to start at beginning or end of cursor

columnMatcherback to summary
private ColumnMatcher columnMatcher

ColumnMatcher to be used when matching column values

endRowback to summary
private Object[] endRow

optional end row for an index cursor

endRowInclusiveback to summary
private boolean endRowInclusive

whether or not end row for an index cursor is inclusive

indexback to summary
private IndexImpl index

optional index to use in traversal

savepointback to summary
private Cursor.Savepoint savepoint

optional save point to restore to the cursor

startRowback to summary
private Object[] startRow

optional start row for an index cursor

startRowInclusiveback to summary
private boolean startRowInclusive

whether or not start row for an index cursor is inclusive

tableback to summary
private final TableImpl table

the table which the cursor will traverse

Constructor Detail

CursorBuilderback to summary
public CursorBuilder(Table table)

Method Detail

afterLastback to summary
public CursorBuilder afterLast()

Sets the cursor so that it will start at the end (unless a savepoint is given).

beforeFirstback to summary
public CursorBuilder beforeFirst()

Sets the cursor so that it will start at the beginning (unless a savepoint is given).

createCursorback to summary
public static Cursor createCursor(Table table) throws IOException

Creates a normal, un-indexed cursor for the given table.

Parameters
table:Table

the table over which this cursor will traverse

createCursorback to summary
public static IndexCursor createCursor(Index index) throws IOException

Creates an indexed cursor for the given table.

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

Parameters
index:Index

index for the table which will define traversal order as well as enhance certain lookups

createCursorback to summary
public static IndexCursor createCursor(Index index, Object[] startRow, Object[] endRow) throws IOException

Creates an indexed cursor for the given table, narrowed to the given range.

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

Parameters
index:Index

index for the table which will define traversal order as well as enhance certain lookups

startRow:Object[]

the first row of data for the cursor (inclusive), or null for the first entry

endRow:Object[]

the last row of data for the cursor (inclusive), or null for the last entry

createCursorback to summary
public static IndexCursor createCursor(Index index, Object[] startRow, boolean startInclusive, Object[] endRow, boolean endInclusive) throws IOException

Creates an indexed cursor for the given table, narrowed to the given range.

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

Parameters
index:Index

index for the table which will define traversal order as well as enhance certain lookups

startRow:Object[]

the first row of data for the cursor, or null for the first entry

startInclusive:boolean

whether or not startRow is inclusive or exclusive

endRow:Object[]

the last row of data for the cursor, or null for the last entry

endInclusive:boolean

whether or not endRow is inclusive or exclusive

createPrimaryKeyCursorback to summary
public static IndexCursor createPrimaryKeyCursor(Table table) throws IOException

Creates an indexed cursor for the primary key cursor of the given table.

Parameters
table:Table

the table over which this cursor will traverse

findRowback to summary
public static Row findRow(Table table, Map<String, ?> rowPattern) throws IOException

Convenience method for finding a specific row in a table which matches a given row "pattern". See 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).

Parameters
table:Table

the table to search

rowPattern:Map<String, ?>

pattern to be used to find the row

Returns:Row

the matching row or null if a match could not be found.

findRowback to summary
public static Row findRow(Index index, Map<String, ?> rowPattern) throws IOException

Convenience method for finding a specific row in an indexed table which matches a given row "pattern". See 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).

Parameters
index:Index

index to assist the search

rowPattern:Map<String, ?>

pattern to be used to find the row

Returns:Row

the matching row or null if a match could not be found.

findRowByEntryback to summary
public static Row findRowByEntry(Index index, Object... entryValues) throws IOException

Convenience method for finding a specific row (as defined by the cursor) where the index entries match the given values. See IndexCursor#findRowByEntry(Object...) for details on the entryValues.

Parameters
index:Index

the index to search

entryValues:Object[]

the column values for the index's columns.

Returns:Row

the matching row or null if a match could not be found.

findRowByPrimaryKeyback to summary
public static Row findRowByPrimaryKey(Table table, Object... entryValues) throws IOException

Convenience method for finding a specific row by the primary key of the table. See IndexCursor#findRowByEntry(Object...) for details on the entryValues.

Parameters
table:Table

the table to search

entryValues:Object[]

the column values for the table's primary key columns.

Returns:Row

the matching row or null if a match could not be found.

findValueback to summary
public static Object findValue(Table table, Column column, Column columnPattern, Object valuePattern) throws IOException

Convenience method for finding a specific row in a table which matches a given row "pattern". See 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.

Parameters
table:Table

the table to search

column:Column

column whose value should be returned

columnPattern:Column

column being matched by the valuePattern

valuePattern:Object

value from the columnPattern which will match the desired row

Returns:Object

the matching row or null if a match could not be found.

findValueback to summary
public static Object findValue(Index index, Column column, Column columnPattern, Object valuePattern) throws IOException

Convenience method for finding a specific row in a table which matches a given row "pattern". See 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.

Parameters
index:Index

index to assist the search

column:Column

column whose value should be returned

columnPattern:Column

column being matched by the valuePattern

valuePattern:Object

value from the columnPattern which will match the desired row

Returns:Object

the matching row or null if a match could not be found.

restoreSavepointback to summary
public CursorBuilder restoreSavepoint(Cursor.Savepoint newSavepoint)

Sets a savepoint to restore for the initial position of the cursor.

toCursorback to summary
public Cursor toCursor() throws IOException

Returns a new cursor for the table, constructed to the given specifications.

toIndexCursorback to summary
public IndexCursor toIndexCursor() throws IOException

Returns a new index cursor for the table, constructed to the given specifications.

withCaseInsensitiveback to summary
public CursorBuilder withCaseInsensitive()

Sets the ColumnMatcher to an instance of CaseInsensitiveColumnMatcher

withColumnMatcherback to summary
public CursorBuilder withColumnMatcher(ColumnMatcher newColumnMatcher)

Sets the ColumnMatcher to use for matching row patterns.

withEndEntryback to summary
public CursorBuilder withEndEntry(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).

A valid index must be specified before calling this method.

withEndRowback to summary
public CursorBuilder withEndRow(Object... newEndRow)

Sets the ending row for a range based index cursor.

A valid index must be specified before calling this method.

withEndRowInclusiveback to summary
public CursorBuilder withEndRowInclusive(boolean inclusive)

Sets whether the ending row for a range based index cursor is inclusive or exclusive.

withIndexback to summary
public CursorBuilder withIndex(Index newIndex)

Sets an index to use for the cursor.

withIndexByColumnNamesback to summary
public CursorBuilder withIndexByColumnNames(String... columnNames)

Sets an index to use for the cursor by searching the table for an index with exactly the given columns.

Exceptions
IllegalArgumentException:
if no index can be found on the table with the given columns
withIndexByColumnsback to summary
public CursorBuilder withIndexByColumns(Column... columns)

Sets an index to use for the cursor by searching the table for an index with exactly the given columns.

Exceptions
IllegalArgumentException:
if no index can be found on the table with the given columns
withIndexByColumnsback to summary
private CursorBuilder withIndexByColumns(List<String> searchColumns)

Searches for an index with the given column names.

withIndexByNameback to summary
public CursorBuilder withIndexByName(String indexName)

Sets an index to use for the cursor by searching the table for an index with the given name.

Exceptions
IllegalArgumentException:
if no index can be found on the table with the given name
withSpecificEntryback to summary
public CursorBuilder withSpecificEntry(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).

A valid index must be specified before calling this method.

withSpecificRowback to summary
public CursorBuilder withSpecificRow(Object... specificRow)

Sets the starting and ending row for a range based index cursor.

A valid index must be specified before calling this method.

withStartEntryback to summary
public CursorBuilder withStartEntry(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).

A valid index must be specified before calling this method.

withStartRowback to summary
public CursorBuilder withStartRow(Object... newStartRow)

Sets the starting row for a range based index cursor.

A valid index must be specified before calling this method.

withStartRowInclusiveback to summary
public CursorBuilder withStartRowInclusive(boolean inclusive)

Sets whether the starting row for a range based index cursor is inclusive or exclusive.