Package db

Class Table


public class Table extends Object
Table implementation class. NOTE: Most public methods are synchronized on the associated DBHandle instance to prevent concurrent modification by multiple threads.
  • 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

      public TableStatistics[] getAllStatistics() throws IOException
      Get table statistics.
      Returns:
      list of diagnostic statistics data for this table and related index tables.
      Throws:
      IOException - database IO error
    • getStatistics

      public TableStatistics getStatistics() throws IOException
      Compile table statitics.
      Returns:
      table statistics data
      Throws:
      IOException - thrown if an IO error occurs
    • rebuild

      public void rebuild(TaskMonitor monitor) throws IOException, CancelledException
      Rebuild table and associated indexes to ensure consistent state.
      Parameters:
      monitor - task monitor
      Throws:
      IOException - if unable to rebuild
      CancelledException - if task was cancelled
    • isConsistent

      public boolean isConsistent(TaskMonitor monitor) throws IOException, CancelledException
      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 occurs
      CancelledException - is task was cancelled
    • deleteAll

      public void deleteAll() throws IOException
      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

      public Schema getSchema()
      Get this tables schema.
      Returns:
      table schema
    • getName

      public String getName()
      Get table name
      Returns:
      table name
    • setName

      public boolean setName(String name) throws DuplicateNameException
      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

      public boolean hasRecord(long key) throws IOException
      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

      public boolean hasRecord(Field key) throws IOException
      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

      public DBRecord getRecord(long key) throws IOException
      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

      public DBRecord getRecord(Field key) throws IOException
      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

      public DBRecord getRecordBefore(long key) throws IOException
      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

      public DBRecord getRecordBefore(Field key) throws IOException
      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

      public DBRecord getRecordAfter(long key) throws IOException
      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

      public DBRecord getRecordAfter(Field key) throws IOException
      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

      public DBRecord getRecordAtOrBefore(long key) throws IOException
      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

      public DBRecord getRecordAtOrBefore(Field key) throws IOException
      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

      public DBRecord getRecordAtOrAfter(long key) throws IOException
      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

      public DBRecord getRecordAtOrAfter(Field key) throws IOException
      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

      public void putRecord(DBRecord record) throws IOException
      Put the specified record into the stored BTree.
      Parameters:
      record - the record to be stored.
      Throws:
      IOException - throw if an IO Error occurs
    • deleteRecord

      public boolean deleteRecord(long key) throws IOException
      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

      public boolean deleteRecord(Field key) throws IOException
      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

      public boolean deleteRecords(long startKey, long endKey) throws IOException
      Delete all records whose keys fall within the specified range, inclusive.
      Parameters:
      startKey - minimum key value
      endKey - maximum key value
      Returns:
      true if one or more records were deleted.
      Throws:
      IOException - thrown if an IO error occurs
    • deleteRecords

      public boolean deleteRecords(Field startKey, Field endKey) throws IOException
      Delete all records whose keys fall within the specified range, inclusive.
      Parameters:
      startKey - minimum key value
      endKey - maximum key value
      Returns:
      true if one or more records were deleted.
      Throws:
      IOException - thrown if an IO error occurs
    • findRecords

      public Field[] findRecords(Field field, int columnIndex) throws IOException
      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 value
      columnIndex - 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

      public int getMatchingRecordCount(Field field, int columnIndex) throws IOException
      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 value
      columnIndex - 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

      public boolean hasRecord(Field field, int columnIndex) throws IOException
      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 value
      columnIndex - 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

      public DBFieldIterator indexFieldIterator(int columnIndex) throws IOException
      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 used
      maxField - maximum index column value, if null absolute maximum is used
      before - if true initial position is before minField, else position is after maxField
      columnIndex - 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 used
      maxField - maximum index column value, if null absolute maximum is used
      startField - index column value corresponding to initial position of iterator
      before - if true initial position is before startField value, else position is after startField value
      columnIndex - 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

      public RecordIterator indexIterator(int columnIndex) throws IOException
      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

      public RecordIterator indexIteratorAfter(int columnIndex, Field startValue) 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. 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

      public RecordIterator indexIteratorBefore(int columnIndex, Field startValue) 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. 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

      public DBFieldIterator indexKeyIterator(int columnIndex) throws IOException
      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

      public DBFieldIterator indexKeyIteratorBefore(int columnIndex, Field startField) throws IOException
      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 on
      startField - index column value which determines initial position of iterator
      Returns:
      primary key iterator
      Throws:
      IOException - thrown if IO error occurs
    • indexKeyIteratorAfter

      public DBFieldIterator indexKeyIteratorAfter(int columnIndex, Field startField) throws IOException
      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 on
      startField - 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 on
      startField - index column value which determines initial position of iterator
      primaryKey - 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 on
      startField - index column value which determines initial position of iterator
      primaryKey - 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 on
      minField - minimum index column value
      maxField - maximum index column value
      atMin - 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 on
      minField - minimum index column value
      maxField - maximum index column value
      startField - starting indexed value position
      before - if true positioned before startField value, else positioned after maxField
      Returns:
      primary key iterator
      Throws:
      IOException - thrown if IO error occurs
    • iterator

      public RecordIterator iterator() throws IOException
      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

      public RecordIterator iterator(long startKey) throws IOException
      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

      public RecordIterator iterator(long minKey, long maxKey, long startKey) throws IOException
      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

      public RecordIterator iterator(Field startKey) throws IOException
      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

      public RecordIterator iterator(Field minKey, Field maxKey, Field startKey) throws IOException
      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

      public DBLongIterator longKeyIterator() throws IOException
      Iterate over all long primary keys in ascending sorted order.
      Returns:
      long key iterator
      Throws:
      IOException - if an I/O error occurs.
    • longKeyIterator

      public DBLongIterator longKeyIterator(long startKey) throws IOException
      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

      public DBLongIterator longKeyIterator(long minKey, long maxKey, long startKey) throws IOException
      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

      public DBFieldIterator fieldKeyIterator() throws IOException
      Iterate over all primary keys in ascending sorted order.
      Returns:
      Field type key iterator
      Throws:
      IOException - if an I/O error occurs.
    • fieldKeyIterator

      public DBFieldIterator fieldKeyIterator(Field startKey) throws IOException
      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

      public String toString()
      Overrides:
      toString in class Object