Package db

Class Table


  • public class Table
    extends java.lang.Object
    Table implementation class. NOTE: Most public methods are synchronized on the associated DBHandle instance to prevent concurrent modification by multiple threads.
    • Method Detail

      • useLongKeys

        public boolean useLongKeys()
        Determine if this table uses long keys.
        Returns:
        true if this table utilizes long keys. If false, the table uses a Field type key.
      • getAllStatistics

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

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

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

        public boolean isConsistent​(TaskMonitor monitor)
                             throws java.io.IOException,
                                    CancelledException
        Check the consistency of this table and its associated index tables.
        Returns:
        true if consistency check passed, else false
        Throws:
        java.io.IOException
        CancelledException
      • deleteAll

        public void deleteAll()
                       throws java.io.IOException
        Delete all records within this table.
        Throws:
        java.io.IOException
      • 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 java.lang.String getName()
        Get table name
        Returns:
        table name
      • 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 java.io.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:
        java.io.IOException
      • hasRecord

        public boolean hasRecord​(Field key)
                          throws java.io.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:
        java.io.IOException - throw if an IO Error occurs
      • getRecord

        public Record getRecord​(long key)
                         throws java.io.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:
        java.io.IOException - throw if an IO Error occurs
      • getRecord

        public Record getRecord​(Field key)
                         throws java.io.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:
        java.io.IOException - throw if an IO Error occurs
      • getRecordBefore

        public Record getRecordBefore​(long key)
                               throws java.io.IOException
        Get the first record which has a key value 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:
        java.io.IOException - throw if an IO Error occurs
      • getRecordBefore

        public Record getRecordBefore​(Field key)
                               throws java.io.IOException
        Get the first record which has a key value 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:
        java.io.IOException - throw if an IO Error occurs
      • getRecordAfter

        public Record getRecordAfter​(long key)
                              throws java.io.IOException
        Get the first record which has a key value 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:
        java.io.IOException - throw if an IO Error occurs
      • getRecordAfter

        public Record getRecordAfter​(Field key)
                              throws java.io.IOException
        Get the first record which has a key value 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:
        java.io.IOException - throw if an IO Error occurs
      • getRecordAtOrBefore

        public Record getRecordAtOrBefore​(long key)
                                   throws java.io.IOException
        Get the first record which has a key value 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:
        java.io.IOException - throw if an IO Error occurs
      • getRecordAtOrBefore

        public Record getRecordAtOrBefore​(Field key)
                                   throws java.io.IOException
        Get the first record which has a key value 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:
        java.io.IOException - throw if an IO Error occurs
      • getRecordAtOrAfter

        public Record getRecordAtOrAfter​(long key)
                                  throws java.io.IOException
        Get the first record which has a key value 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:
        java.io.IOException - throw if an IO Error occurs
      • getRecordAtOrAfter

        public Record getRecordAtOrAfter​(Field key)
                                  throws java.io.IOException
        Get the first record which has a key value 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:
        java.io.IOException - throw if an IO Error occurs
      • putRecord

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

        public boolean deleteRecord​(long key)
                             throws java.io.IOException
        Delete a record identified by the specified key value.
        Parameters:
        key - unique record key.
        Returns:
        true if record was deleted successfully.
        Throws:
        java.io.IOException - throw if an IO Error occurs
      • deleteRecord

        public boolean deleteRecord​(Field key)
                             throws java.io.IOException
        Delete a record identified by the specified key value.
        Parameters:
        key - unique record key.
        Returns:
        true if record was deleted successfully.
        Throws:
        java.io.IOException - throw if an IO Error occurs
      • deleteRecords

        public boolean deleteRecords​(long startKey,
                                     long endKey)
                              throws java.io.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:
        java.io.IOException - thrown if an IO error occurs
      • deleteRecords

        public boolean deleteRecords​(Field startKey,
                                     Field endKey)
                              throws java.io.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:
        java.io.IOException - thrown if an IO error occurs
      • findRecords

        public long[] findRecords​(Field field,
                                  int columnIndex)
                           throws java.io.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 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:
        java.io.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 java.io.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:
        java.io.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 java.io.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:
        java.io.IOException
      • indexFieldIterator

        public DBFieldIterator indexFieldIterator​(int columnIndex)
                                           throws java.io.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:
        java.io.IOException
      • indexFieldIterator

        public DBFieldIterator indexFieldIterator​(Field minField,
                                                  Field maxField,
                                                  boolean before,
                                                  int columnIndex)
                                           throws java.io.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:
        java.io.IOException
      • indexFieldIterator

        public DBFieldIterator indexFieldIterator​(Field minField,
                                                  Field maxField,
                                                  Field startField,
                                                  boolean before,
                                                  int columnIndex)
                                           throws java.io.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:
        java.io.IOException
      • indexIterator

        public RecordIterator indexIterator​(int columnIndex)
                                     throws java.io.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:
        java.io.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 java.io.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.
        primaryKey - the primary key associated with the startField.
        atStart - if true, position the iterator before the start value. Otherwise, position the iterator after the end value.
        Returns:
        RecordIterator record iterator.
        Throws:
        java.io.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 java.io.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:
        java.io.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 java.io.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:
        java.io.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,
                                                 long primaryKey)
                                          throws java.io.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:
        java.io.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,
                                                  long primaryKey)
                                           throws java.io.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:
        java.io.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 DBLongIterator indexKeyIterator​(int columnIndex)
                                        throws java.io.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:
        java.io.IOException - thrown if IO error occurs
      • indexKeyIteratorBefore

        public DBLongIterator indexKeyIteratorBefore​(int columnIndex,
                                                     Field startField)
                                              throws java.io.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:
        java.io.IOException - thrown if IO error occurs
      • indexKeyIteratorAfter

        public DBLongIterator indexKeyIteratorAfter​(int columnIndex,
                                                    Field startField)
                                             throws java.io.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:
        java.io.IOException - thrown if IO error occurs
      • indexKeyIteratorBefore

        public DBLongIterator indexKeyIteratorBefore​(int columnIndex,
                                                     Field startField,
                                                     long primaryKey)
                                              throws java.io.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:
        java.io.IOException - thrown if IO error occurs
      • indexKeyIteratorAfter

        public DBLongIterator indexKeyIteratorAfter​(int columnIndex,
                                                    Field startField,
                                                    long primaryKey)
                                             throws java.io.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:
        java.io.IOException - thrown if IO error occurs
      • indexKeyIterator

        public DBLongIterator indexKeyIterator​(int columnIndex,
                                               Field minField,
                                               Field maxField,
                                               boolean atMin)
                                        throws java.io.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:
        java.io.IOException - thrown if IO error occurs
      • indexKeyIterator

        public DBLongIterator indexKeyIterator​(int columnIndex,
                                               LongField minField,
                                               LongField maxField,
                                               LongField startField,
                                               boolean before)
                                        throws java.io.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:
        java.io.IOException - thrown if IO error occurs
      • iterator

        public RecordIterator iterator()
                                throws java.io.IOException
        Iterate over the records in ascending sorted order. Sorting occurs on the primary key value.
        Returns:
        record iterator
        Throws:
        java.io.IOException - if an I/O error occurs.
      • iterator

        public RecordIterator iterator​(long startKey)
                                throws java.io.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:
        java.io.IOException - if an I/O error occurs.
      • iterator

        public RecordIterator iterator​(long minKey,
                                       long maxKey,
                                       long startKey)
                                throws java.io.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.
        endKey - the maximum primary key.
        startKey - the initial iterator position.
        Returns:
        record iterator
        Throws:
        java.io.IOException - if an I/O error occurs.
        java.lang.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 java.io.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:
        java.io.IOException - if an I/O error occurs.
      • iterator

        public RecordIterator iterator​(Field minKey,
                                       Field maxKey,
                                       Field startKey)
                                throws java.io.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.
        endKey - the maximum primary key, may be null.
        startKey - the initial iterator position, if null minKey is also start.
        Returns:
        record iterator
        Throws:
        java.io.IOException - if an I/O error occurs.
      • longKeyIterator

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

        public DBLongIterator longKeyIterator​(long startKey)
                                       throws java.io.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:
        java.io.IOException - if an I/O error occurs.
      • longKeyIterator

        public DBLongIterator longKeyIterator​(long minKey,
                                              long maxKey,
                                              long startKey)
                                       throws java.io.IOException
        Iterate over the long primary keys in ascending sorted order starting at the specified startKey.
        Parameters:
        minKey - the minimum primary key.
        endKey - the maximum primary key.
        startKey - the initial iterator position.
        Returns:
        long key iterator
        Throws:
        java.io.IOException - if an I/O error occurs.
      • fieldKeyIterator

        public DBFieldIterator fieldKeyIterator()
                                         throws java.io.IOException
        Iterate over all primary keys in ascending sorted order.
        Parameters:
        startKey - the first primary key, may be null.
        Returns:
        Field type key iterator
        Throws:
        java.io.IOException - if an I/O error occurs.
      • fieldKeyIterator

        public DBFieldIterator fieldKeyIterator​(Field startKey)
                                         throws java.io.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:
        java.io.IOException - if an I/O error occurs.
      • fieldKeyIterator

        public DBFieldIterator fieldKeyIterator​(Field minKey,
                                                Field maxKey,
                                                Field startKey)
                                         throws java.io.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:
        java.io.IOException - if an I/O error occurs.
      • fieldKeyIterator

        public DBFieldIterator fieldKeyIterator​(Field minKey,
                                                Field maxKey,
                                                boolean before)
                                         throws java.io.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:
        java.io.IOException - if an I/O error occurs.
      • isInvalid

        public boolean isInvalid()
        Returns:
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object