Package db
Class Table
java.lang.Object
db.Table
Table implementation class.
NOTE: Most public methods are synchronized on the associated DBHandle instance
to prevent concurrent modification by multiple threads.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Delete all records within this table.boolean
deleteRecord
(long key) Delete a record identified by the specified key value.boolean
deleteRecord
(Field key) Delete a record identified by the specified key value.boolean
deleteRecords
(long startKey, long endKey) Delete all records whose keys fall within the specified range, inclusive.boolean
deleteRecords
(Field startKey, Field endKey) Delete all records whose keys fall within the specified range, inclusive.Iterate over all primary keys in ascending sorted order.fieldKeyIterator
(Field startKey) Iterate over the primary keys in ascending sorted order starting at the specified startKey.fieldKeyIterator
(Field minKey, Field maxKey, boolean before) Iterate over the records in ascending sorted order starting at the specified startKey.fieldKeyIterator
(Field minKey, Field maxKey, Field startKey) Iterate over the records in ascending sorted order starting at the specified startKey.Field[]
findRecords
(Field field, int columnIndex) Find the primary keys corresponding to those records which contain the specified field value in the specified record column.Get table statistics.int[]
Get the list of columns which are indexedlong
getKey()
Get the next available key.int
getMatchingRecordCount
(Field field, int columnIndex) Get the number of records which contain the specified field value in the specified record column.long
Get the maximum record key which has ever been assigned within this table.getName()
Get table namegetRecord
(long key) Get the record identified by the specified key value.Get the record identified by the specified key value.getRecordAfter
(long key) Get the record with the minimum key value which is greater than the specified key.getRecordAfter
(Field key) Get the record with the minimum key value which is greater than the specified key.getRecordAtOrAfter
(long key) Get the record with the minimum key value which is greater than or equal to the specified key.getRecordAtOrAfter
(Field key) Get the record with the minimum key value which is greater than or equal to the specified key.getRecordAtOrBefore
(long key) Get the record with the maximum key value which is less than or equal to the specified key.getRecordAtOrBefore
(Field key) Get the record with the maximum key value which is less than or equal to the specified key.getRecordBefore
(long key) Get the record with the maximum key value which is less than the specified key.getRecordBefore
(Field key) Get the record with the maximum key value which is less than the specified key.int
Get record countGet this tables schema.Compile table statitics.boolean
hasRecord
(long key) Determine if this table contains a record with the specified key.boolean
Determine if this table contains a record with the specified key.boolean
Determine if a record exists with the specified value within the specified column.indexFieldIterator
(int columnIndex) Iterate over all the unique index field values.indexFieldIterator
(Field minField, Field maxField, boolean before, int columnIndex) Iterate over all the unique index field values within the specified range identified by minField and maxField.indexFieldIterator
(Field minField, Field maxField, Field startField, boolean before, int columnIndex) Iterate over all the unique index field values within the specified range identified by minField and maxField.indexIterator
(int columnIndex) Iterate over the records using a secondary index.indexIterator
(int columnIndex, Field startValue, Field endValue, boolean atStart) Iterate over a range of records using a secondary index.indexIteratorAfter
(int columnIndex, Field startValue) Iterate over the records using a secondary index.indexIteratorAfter
(int columnIndex, Field startValue, Field primaryKey) Iterate over the records using a secondary index.indexIteratorBefore
(int columnIndex, Field startValue) Iterate over the records using a secondary index.indexIteratorBefore
(int columnIndex, Field startValue, Field primaryKey) Iterate over the records using a secondary index.indexKeyIterator
(int columnIndex) Iterate over all primary keys sorted based upon the associated index key.indexKeyIterator
(int columnIndex, Field minField, Field maxField, boolean atMin) Iterate over all primary keys sorted based upon the associated index key.indexKeyIterator
(int columnIndex, Field minField, Field maxField, Field startField, boolean before) Iterate over all primary keys sorted based upon the associated index key.indexKeyIteratorAfter
(int columnIndex, Field startField) Iterate over all primary keys sorted based upon the associated index key.indexKeyIteratorAfter
(int columnIndex, Field startField, Field primaryKey) Iterate over all primary keys sorted based upon the associated index key.indexKeyIteratorBefore
(int columnIndex, Field startField) Iterate over all primary keys sorted based upon the associated index key.indexKeyIteratorBefore
(int columnIndex, Field startField, Field primaryKey) Iterate over all primary keys sorted based upon the associated index key.boolean
isConsistent
(TaskMonitor monitor) Check the consistency of this table and its associated index tables.boolean
iterator()
Iterate over the records in ascending sorted order.iterator
(long startKey) Iterate over the records in ascending sorted order.iterator
(long minKey, long maxKey, long startKey) Iterate over the records in ascending sorted order.Iterate over the records in ascending sorted order.Iterate over the records in ascending sorted order.Iterate over all long primary keys in ascending sorted order.longKeyIterator
(long startKey) Iterate over the long primary keys in ascending sorted order starting at the specified startKey.longKeyIterator
(long minKey, long maxKey, long startKey) Iterate over the long primary keys in ascending sorted order starting at the specified startKey.void
Put the specified record into the stored BTree.void
rebuild
(TaskMonitor monitor) Rebuild table and associated indexes to ensure consistent state.boolean
Change the name of this tabletoString()
boolean
Determine if this table uses FixedField keys.boolean
Determine if this table uses long keys.
-
Method Details
-
useLongKeys
public boolean useLongKeys()Determine if this table uses long keys.- Returns:
- true if this table utilizes long keys.
-
useFixedKeys
public boolean useFixedKeys()Determine if this table uses FixedField keys.- Returns:
- true if this table utilizes FixedField keys.
-
getAllStatistics
Get table statistics.- Returns:
- list of diagnostic statistics data for this table and related index tables.
- Throws:
IOException
- database IO error
-
getStatistics
Compile table statitics.- Returns:
- table statistics data
- Throws:
IOException
- thrown if an IO error occurs
-
rebuild
Rebuild table and associated indexes to ensure consistent state.- Parameters:
monitor
- task monitor- Throws:
IOException
- if unable to rebuildCancelledException
- if task was cancelled
-
isConsistent
Check the consistency of this table and its associated index tables.- Parameters:
monitor
- task monitor- Returns:
- true if consistency check passed, else false
- Throws:
IOException
- thrown if IO error occursCancelledException
- is task was cancelled
-
deleteAll
Delete all records within this table.- Throws:
IOException
- if IO error occurs
-
getIndexedColumns
public int[] getIndexedColumns()Get the list of columns which are indexed- Returns:
- list of indexed columns
-
getSchema
Get this tables schema.- Returns:
- table schema
-
getName
Get table name- Returns:
- table name
-
setName
Change the name of this table- Parameters:
name
- new table name- Returns:
- true if rename successful
- Throws:
DuplicateNameException
- if new table name already exists
-
getRecordCount
public int getRecordCount()Get record count- Returns:
- record count
-
getMaxKey
public long getMaxKey()Get the maximum record key which has ever been assigned within this table. This method is only valid for those tables which employ a long key and may not reflect records which have been removed (i.e., returned key may not correspond to an existing record).- Returns:
- maximum record key.
-
getKey
public long getKey()Get the next available key. This method is only valid for those tables which employ a long key.- Returns:
- next available key.
-
hasRecord
Determine if this table contains a record with the specified key.- Parameters:
key
- record key.- Returns:
- true if record exists with key, else false.
- Throws:
IOException
- thrown if IO error occurs
-
hasRecord
Determine if this table contains a record with the specified key.- Parameters:
key
- record key.- Returns:
- true if record exists with key, else false.
- Throws:
IOException
- throw if an IO Error occurs
-
getRecord
Get the record identified by the specified key value.- Parameters:
key
- unique record key.- Returns:
- Record the record identified by key, or null if record was not found.
- Throws:
IOException
- throw if an IO Error occurs
-
getRecord
Get the record identified by the specified key value.- Parameters:
key
- unique record key.- Returns:
- Record the record identified by key, or null if record was not found.
- Throws:
IOException
- throw if an IO Error occurs
-
getRecordBefore
Get the record with the maximum key value which is less than the specified key.- Parameters:
key
- unique key which may or may not exist within the table.- Returns:
- the first record which has a key value less than the specified key, or null if no record was found.
- Throws:
IOException
- throw if an IO Error occurs
-
getRecordBefore
Get the record with the maximum key value which is less than the specified key.- Parameters:
key
- unique key which may or may not exist within the table.- Returns:
- the first record which has a key value less than the specified key, or null if no record was found.
- Throws:
IOException
- throw if an IO Error occurs
-
getRecordAfter
Get the record with the minimum key value which is greater than the specified key.- Parameters:
key
- unique key which may or may not exist within the table.- Returns:
- the first record which has a key value greater than the specified key, or null if no record was found.
- Throws:
IOException
- throw if an IO Error occurs
-
getRecordAfter
Get the record with the minimum key value which is greater than the specified key.- Parameters:
key
- unique key which may or may not exist within the table.- Returns:
- the first record which has a key value greater than the specified key, or null if no record was found.
- Throws:
IOException
- throw if an IO Error occurs
-
getRecordAtOrBefore
Get the record with the maximum key value which is less than or equal to the specified key.- Parameters:
key
- unique key which may or may not exist within the table.- Returns:
- the first record which has a key value less than or equal to the specified key, or null if no record was found.
- Throws:
IOException
- throw if an IO Error occurs
-
getRecordAtOrBefore
Get the record with the maximum key value which is less than or equal to the specified key.- Parameters:
key
- unique key which may or may not exist within the table.- Returns:
- the first record which has a key value less than or equal to the specified key, or null if no record was found.
- Throws:
IOException
- throw if an IO Error occurs
-
getRecordAtOrAfter
Get the record with the minimum key value which is greater than or equal to the specified key.- Parameters:
key
- unique key which may or may not exist within the table.- Returns:
- the first record which has a key value greater than or equal to the specified key, or null if no record was found.
- Throws:
IOException
- throw if an IO Error occurs
-
getRecordAtOrAfter
Get the record with the minimum key value which is greater than or equal to the specified key.- Parameters:
key
- unique key which may or may not exist within the table.- Returns:
- the first record which has a key value greater than or equal to the specified key, or null if no record was found.
- Throws:
IOException
- throw if an IO Error occurs
-
putRecord
Put the specified record into the stored BTree.- Parameters:
record
- the record to be stored.- Throws:
IOException
- throw if an IO Error occurs
-
deleteRecord
Delete a record identified by the specified key value.- Parameters:
key
- unique record key.- Returns:
- true if record was deleted successfully.
- Throws:
IOException
- throw if an IO Error occurs
-
deleteRecord
Delete a record identified by the specified key value.- Parameters:
key
- unique record key.- Returns:
- true if record was deleted successfully.
- Throws:
IOException
- throw if an IO Error occurs
-
deleteRecords
Delete all records whose keys fall within the specified range, inclusive.- Parameters:
startKey
- minimum key valueendKey
- maximum key value- Returns:
- true if one or more records were deleted.
- Throws:
IOException
- thrown if an IO error occurs
-
deleteRecords
Delete all records whose keys fall within the specified range, inclusive.- Parameters:
startKey
- minimum key valueendKey
- maximum key value- Returns:
- true if one or more records were deleted.
- Throws:
IOException
- thrown if an IO error occurs
-
findRecords
Find the primary keys corresponding to those records which contain the specified field value in the specified record column. The table must have been created with long keys and a secondary index on the specified column index.- Parameters:
field
- the field valuecolumnIndex
- the record schema column which should be searched.- Returns:
- list of primary keys
- Throws:
IOException
- if a secondary index does not exist for the specified column, or the wrong field type was specified, or an I/O error occurs.
-
getMatchingRecordCount
Get the number of records which contain the specified field value in the specified record column. The table must have been created with a secondary index on the specified column index.- Parameters:
field
- the field valuecolumnIndex
- the record schema column which should be searched.- Returns:
- number of records which match the specified field value.
- Throws:
IOException
- if a secondary index does not exist for the specified column, or the wrong field type was specified, or an I/O error occurs.
-
hasRecord
Determine if a record exists with the specified value within the specified column. The table must have been created with a secondary index on the specified column index.- Parameters:
field
- the field valuecolumnIndex
- the record schema column which should be searched.- Returns:
- true if one or more records exis with the specified value.
- Throws:
IOException
- thrown if IO error occurs
-
indexFieldIterator
Iterate over all the unique index field values. Index values are returned in an ascending sorted order with the initial iterator position set to the minimum index value.- Parameters:
columnIndex
- identifies an indexed column.- Returns:
- index field iterator.
- Throws:
IOException
- thrown if IO error occurs
-
indexFieldIterator
public DBFieldIterator indexFieldIterator(Field minField, Field maxField, boolean before, int columnIndex) throws IOException Iterate over all the unique index field values within the specified range identified by minField and maxField. Index values are returned in an ascending sorted order.- Parameters:
minField
- minimum index column value, if null absolute minimum is usedmaxField
- maximum index column value, if null absolute maximum is usedbefore
- if true initial position is before minField, else position is after maxFieldcolumnIndex
- identifies an indexed column.- Returns:
- index field iterator.
- Throws:
IOException
- thrown if IO error occurs
-
indexFieldIterator
public DBFieldIterator indexFieldIterator(Field minField, Field maxField, Field startField, boolean before, int columnIndex) throws IOException Iterate over all the unique index field values within the specified range identified by minField and maxField. Index values are returned in an ascending sorted order with the initial iterator position corresponding to the startField.- Parameters:
minField
- minimum index column value, if null absolute minimum is usedmaxField
- maximum index column value, if null absolute maximum is usedstartField
- index column value corresponding to initial position of iteratorbefore
- if true initial position is before startField value, else position is after startField valuecolumnIndex
- identifies an indexed column.- Returns:
- index field iterator.
- Throws:
IOException
- if a secondary index does not exist for the specified column or an I/O error occurs.
-
indexIterator
Iterate over the records using a secondary index. Sorting occurs on the specified schema column. This table must have been constructed with a secondary index on the specified column.- Parameters:
columnIndex
- schema column to sort on.- Returns:
- RecordIterator record iterator.
- Throws:
IOException
- if a secondary index does not exist for the specified column or an I/O error occurs.
-
indexIterator
public RecordIterator indexIterator(int columnIndex, Field startValue, Field endValue, boolean atStart) throws IOException Iterate over a range of records using a secondary index. Sorting occurs on the specified schema column. The iterator is initially positioned before the startValue. This table must have been constructed with a secondary index on the specified column.- Parameters:
columnIndex
- schema column to sort on.startValue
- the starting and minimum value of the secondary index field.endValue
- the ending and maximum value of the secondary index field.atStart
- if true, position the iterator before the start value. Otherwise, position the iterator after the end value.- Returns:
- record iterator.
- Throws:
IOException
- if a secondary index does not exist for the specified column, or the wrong field type was specified, or an I/O error occurs.
-
indexIteratorAfter
Iterate over the records using a secondary index. Sorting occurs on the specified schema column. The iterator's initial position immediately follows the specified startValue. If this value does not exist, the initial position corresponds to where it would exist. This table must have been constructed with a secondary index on the specified column.- Parameters:
columnIndex
- schema column to sort on.startValue
- the starting value of the secondary index field.- Returns:
- RecordIterator record iterator.
- Throws:
IOException
- if a secondary index does not exist for the specified column, or the wrong field type was specified, or an I/O error occurs.
-
indexIteratorBefore
Iterate over the records using a secondary index. Sorting occurs on the specified schema column. The iterator's initial position immediately precedes the specified startValue. If this value does not exist, the initial position corresponds to where it would exist. This table must have been constructed with a secondary index on the specified column.- Parameters:
columnIndex
- schema column to sort on.startValue
- the starting value of the secondary index field.- Returns:
- RecordIterator record iterator.
- Throws:
IOException
- if a secondary index does not exist for the specified column, or the wrong field type was specified, or an I/O error occurs.
-
indexIteratorAfter
public RecordIterator indexIteratorAfter(int columnIndex, Field startValue, Field primaryKey) throws IOException Iterate over the records using a secondary index. Sorting occurs on the specified schema column. The iterator's initial position immediately follows the specified startValue and primaryKey. If no such entry exists, the initial position corresponds to where it would exist.This table must have been constructed with a secondary index on the specified column.
- Parameters:
columnIndex
- schema column to sort on.startValue
- the starting value of the secondary index field.primaryKey
- the primary key associated with the startField.- Returns:
- RecordIterator record iterator.
- Throws:
IOException
- if a secondary index does not exist for the specified column, or the wrong field type was specified, or an I/O error occurs.
-
indexIteratorBefore
public RecordIterator indexIteratorBefore(int columnIndex, Field startValue, Field primaryKey) throws IOException Iterate over the records using a secondary index. Sorting occurs on the specified schema column. The iterator's initial position immediately precedes the specified startValue and primaryKey. If no such entry exists, the initial position corresponds to where it would exist.This table must have been constructed with a secondary index on the specified column.
- Parameters:
columnIndex
- schema column to sort on.startValue
- the starting value of the secondary index field.primaryKey
- the primary key associated with the startField.- Returns:
- RecordIterator record iterator.
- Throws:
IOException
- if a secondary index does not exist for the specified column, or the wrong field type was specified, or an I/O error occurs.
-
indexKeyIterator
Iterate over all primary keys sorted based upon the associated index key.- Parameters:
columnIndex
- schema column to sort on.- Returns:
- primary key iterator
- Throws:
IOException
- thrown if IO error occurs
-
indexKeyIteratorBefore
Iterate over all primary keys sorted based upon the associated index key. The iterator is initially positioned before the first index buffer whose index key is greater than or equal to the specified startField value.- Parameters:
columnIndex
- schema column to sort onstartField
- index column value which determines initial position of iterator- Returns:
- primary key iterator
- Throws:
IOException
- thrown if IO error occurs
-
indexKeyIteratorAfter
Iterate over all primary keys sorted based upon the associated index key. The iterator is initially positioned after the index buffer whose index key is equal to the specified startField value or immediately before the first index buffer whose index key is greater than the specified startField value.- Parameters:
columnIndex
- schema column to sort onstartField
- index column value which determines initial position of iterator- Returns:
- primary key iterator
- Throws:
IOException
- thrown if IO error occurs
-
indexKeyIteratorBefore
public DBFieldIterator indexKeyIteratorBefore(int columnIndex, Field startField, Field primaryKey) throws IOException Iterate over all primary keys sorted based upon the associated index key. The iterator is initially positioned before the primaryKey within the index buffer whose index key is equal to the specified startField value or immediately before the first index buffer whose index key is greater than the specified startField value.- Parameters:
columnIndex
- schema column to sort onstartField
- index column value which determines initial position of iteratorprimaryKey
- initial position within index buffer if index key matches startField value.- Returns:
- primary key iterator
- Throws:
IOException
- thrown if IO error occurs
-
indexKeyIteratorAfter
public DBFieldIterator indexKeyIteratorAfter(int columnIndex, Field startField, Field primaryKey) throws IOException Iterate over all primary keys sorted based upon the associated index key. The iterator is initially positioned after the primaryKey within the index buffer whose index key is equal to the specified startField value or immediately before the first index buffer whose index key is greater than the specified startField value.- Parameters:
columnIndex
- schema column to sort onstartField
- index column value which determines initial position of iteratorprimaryKey
- initial position within index buffer if index key matches startField value.- Returns:
- primary key iterator
- Throws:
IOException
- thrown if IO error occurs
-
indexKeyIterator
public DBFieldIterator indexKeyIterator(int columnIndex, Field minField, Field maxField, boolean atMin) throws IOException Iterate over all primary keys sorted based upon the associated index key. The iterator is limited to range of index keys of minField through maxField, inclusive. If atMin is true, the iterator is initially positioned before the first index buffer whose index key is greater than or equal to the specified minField value. If atMin is false, the iterator is initially positioned after the first index buffer whose index key is less than or equal to the specified maxField value.- Parameters:
columnIndex
- schema column to sort onminField
- minimum index column valuemaxField
- maximum index column valueatMin
- if true, position iterator before minField value, Otherwise, position iterator after maxField value.- Returns:
- primary key iterator
- Throws:
IOException
- thrown if IO error occurs
-
indexKeyIterator
public DBFieldIterator indexKeyIterator(int columnIndex, Field minField, Field maxField, Field startField, boolean before) throws IOException Iterate over all primary keys sorted based upon the associated index key. The iterator is limited to range of index keys of minField through maxField, inclusive. The iterator is initially positioned before or after the specified startField index value.- Parameters:
columnIndex
- schema column to sort onminField
- minimum index column valuemaxField
- maximum index column valuestartField
- starting indexed value positionbefore
- if true positioned before startField value, else positioned after maxField- Returns:
- primary key iterator
- Throws:
IOException
- thrown if IO error occurs
-
iterator
Iterate over the records in ascending sorted order. Sorting occurs on the primary key value.- Returns:
- record iterator
- Throws:
IOException
- if an I/O error occurs.
-
iterator
Iterate over the records in ascending sorted order. Sorting occurs on the primary key value starting at the specified startKey.- Parameters:
startKey
- the first primary key.- Returns:
- record iterator
- Throws:
IOException
- if an I/O error occurs.
-
iterator
Iterate over the records in ascending sorted order. Sorting occurs on the primary key value starting at the specified startKey.- Parameters:
minKey
- the minimum primary key.maxKey
- the maximum primary key.startKey
- the initial iterator position.- Returns:
- record iterator
- Throws:
IOException
- if an I/O error occurs.IllegalArgumentException
- if long keys are not in use or startKey is less than minKey or greater than maxKey.
-
iterator
Iterate over the records in ascending sorted order. Sorting occurs on the primary key value starting at the specified startKey.- Parameters:
startKey
- the first primary key.- Returns:
- record iterator
- Throws:
IOException
- if an I/O error occurs.
-
iterator
Iterate over the records in ascending sorted order. Sorting occurs on the primary key value starting at the specified startKey.- Parameters:
minKey
- the minimum primary key, may be null.maxKey
- the maximum primary key, may be null.startKey
- the initial iterator position, if null minKey is also start.- Returns:
- record iterator
- Throws:
IOException
- if an I/O error occurs.
-
longKeyIterator
Iterate over all long primary keys in ascending sorted order.- Returns:
- long key iterator
- Throws:
IOException
- if an I/O error occurs.
-
longKeyIterator
Iterate over the long primary keys in ascending sorted order starting at the specified startKey.- Parameters:
startKey
- the first primary key.- Returns:
- long key iterator
- Throws:
IOException
- if an I/O error occurs.
-
longKeyIterator
Iterate over the long primary keys in ascending sorted order starting at the specified startKey.- Parameters:
minKey
- the minimum primary key.maxKey
- the maximum primary key.startKey
- the initial iterator position.- Returns:
- long key iterator
- Throws:
IOException
- if an I/O error occurs.
-
fieldKeyIterator
Iterate over all primary keys in ascending sorted order.- Returns:
- Field type key iterator
- Throws:
IOException
- if an I/O error occurs.
-
fieldKeyIterator
Iterate over the primary keys in ascending sorted order starting at the specified startKey.- Parameters:
startKey
- the first primary key. If null the minimum key value will be assumed.- Returns:
- Field type key iterator
- Throws:
IOException
- if an I/O error occurs.
-
fieldKeyIterator
public DBFieldIterator fieldKeyIterator(Field minKey, Field maxKey, Field startKey) throws IOException Iterate over the records in ascending sorted order starting at the specified startKey.- Parameters:
minKey
- minimum key value. Null corresponds to minimum key value.maxKey
- maximum key value. Null corresponds to maximum key value.startKey
- the initial iterator position. If null minKey will be assumed, if still null the minimum key value will be assumed.- Returns:
- Field type key iterator
- Throws:
IOException
- if an I/O error occurs.
-
fieldKeyIterator
public DBFieldIterator fieldKeyIterator(Field minKey, Field maxKey, boolean before) throws IOException Iterate over the records in ascending sorted order starting at the specified startKey.- Parameters:
minKey
- minimum key value. Null corresponds to minimum key value.maxKey
- maximum key value. Null corresponds to maximum key value.before
- if true initial position is before minKey, else position is after maxKey.- Returns:
- Field type key iterator
- Throws:
IOException
- if an I/O error occurs.
-
isInvalid
public boolean isInvalid()- Returns:
- true if table is valid and has not been invalidated
-
toString
-