Class SelectableScheme

  • Direct Known Subclasses:
    BlindSearch, CollatedBaseSearch

    public abstract class SelectableScheme
    extends java.lang.Object
    Represents a base class for a mechanism to select ranges from a given set. Such schemes could include BinaryTree, Hashtable or just a blind search.

    A given element in the set is specified through a 'row' integer whose contents can be obtained through the 'table.getCellContents(column, row)'. Every scheme is given a table and column number that the set refers to. While a given set element is refered to as a 'row', the integer is really only a pointer into the set list which can be de-referenced with a call to table.getCellContents(row). Better performance schemes will keep such calls to a minimum.

    A scheme may choose to retain knowledge about a given element when it is added or removed from the set, such as a BinaryTree that catalogs all elements with respect to each other.

    • Field Detail

      • table

        private final TableDataSource table
        The table data source with the column this scheme indexes.
      • column

        private final int column
        The column number in the tree this tree helps.
      • immutable

        private boolean immutable
        Set to true if this scheme is immutable (can't be changed).
    • Constructor Detail

      • SelectableScheme

        public SelectableScheme​(TableDataSource table,
                                int column)
        The constructor for all schemes.
    • Method Detail

      • getSystem

        protected final TransactionSystem getSystem()
        Returns the global transaction system.
      • Debug

        protected final DebugLogger Debug()
        Returns the DebugLogger object to log debug messages to.
      • getColumn

        protected final int getColumn()
        Returns the column this scheme is indexing in the table.
      • getCellContents

        protected final TObject getCellContents​(int row)
        Obtains the given cell in the row from the table.
      • setImmutable

        public final void setImmutable()
        Sets this scheme to immutable.
      • isImmutable

        public final boolean isImmutable()
        Returns true if this scheme is immutable.
      • toString

        public java.lang.String toString()
        Diagnostic information.
        Overrides:
        toString in class java.lang.Object
      • writeTo

        public abstract void writeTo​(java.io.OutputStream out)
                              throws java.io.IOException
        Writes the entire contents of the scheme to an OutputStream object.
        Throws:
        java.io.IOException
      • readFrom

        public abstract void readFrom​(java.io.InputStream in)
                               throws java.io.IOException
        Reads the entire contents of the scheme from a InputStream object. If the scheme is full of any information it throws an exception.
        Throws:
        java.io.IOException
      • copy

        public abstract SelectableScheme copy​(TableDataSource table,
                                              boolean immutable)
        Returns an exact copy of this scheme including any optimization information. The copied scheme is identical to the original but does not share any parts. Modifying any part of the copied scheme will have no effect on the original and vice versa.

        The newly copied scheme can be given a new table source. If 'immutable' is true, then the resultant scheme is an immutable version of the parent. An immutable version may share information with the copied version so can not be changed.

        NOTE: Even if the scheme maintains no state you should still be careful to ensure a fresh SelectableScheme object is returned here.

      • dispose

        public abstract void dispose()
        Dispose and invalidate this scheme.
      • insert

        abstract void insert​(int row)
        Inserts the given element into the set. This is called just after a row has been initially added to a table.
      • remove

        abstract void remove​(int row)
        Removes the given element from the set. This is called just before the row is removed from the table.
      • internalOrderIndexSet

        public BlockIntegerList internalOrderIndexSet​(IntegerVector row_set)
        Returns a BlockIntegerList that represents the given row_set sorted in the order of this scheme. The values in 'row_set' must be references to rows in the domain of the table this scheme represents.

        The returned set must be stable, meaning if values are equal they keep the same ordering.

        Note that the default implementation of this method can often be optimized. For example, InsertSearch uses a secondary RID list to sort items if the given list is over a certain size.

      • getSubsetScheme

        public SelectableScheme getSubsetScheme​(Table subset_table,
                                                int subset_column)
        Asks the Scheme for a SelectableScheme abject that describes a sub-set of the set handled by this Scheme. Since a Table stores a subset of a given DataTable, we pass this as the argument. It returns a new SelectableScheme that orders the rows in the given columns order. The 'column' variable specifies the column index of this column in the given table.
      • selectAll

        public IntegerVector selectAll()
        These are the select operations that are the main purpose of the scheme. They retrieve the given information from the set. Different schemes will have varying performance on different types of data sets. The select operations must *always* return a resultant row set that is sorted from lowest to highest.
      • selectAllNonNull

        public IntegerVector selectAllNonNull()
        Selects all values in the column that are not null.
      • selectRange

        abstract IntegerVector selectRange​(SelectableRange range)
        Selects the given range of values from this index. The SelectableRange must contain a 'start' value that compares <= to the 'end' value.

        This must guarentee that the returned set is sorted from lowest to highest value.

      • selectRange

        abstract IntegerVector selectRange​(SelectableRange[] ranges)
        Selects a set of ranges from this index. The ranges must not overlap and each range must contain a 'start' value that compares <= to the 'end' value. Every range in the array must represent a range that's lower than the preceeding range (if it exists).

        If the above rules are enforced (as they must be) then this method will return a set that is sorted from lowest to highest value.

        This must guarentee that the returned set is sorted from lowest to highest value.