Class SelectableScheme

java.lang.Object
com.mckoi.database.SelectableScheme
Direct Known Subclasses:
BlindSearch, CollatedBaseSearch

public abstract class SelectableScheme extends 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.

Author:
Tobias Downer
  • Field Details

  • Constructor Details

    • SelectableScheme

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

    • getTable

      protected final TableDataSource getTable()
      Returns the Table.
    • 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 String toString()
      Diagnostic information.
      Overrides:
      toString in class Object
    • writeTo

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

      public abstract void readFrom(InputStream in) throws 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:
      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.
    • 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.
    • selectFirst

      public IntegerVector selectFirst()
    • selectNotFirst

      public IntegerVector selectNotFirst()
    • selectLast

      public IntegerVector selectLast()
    • selectNotLast

      public IntegerVector selectNotLast()
    • selectAllNonNull

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

      public IntegerVector selectEqual(TObject ob)
    • selectNotEqual

      public IntegerVector selectNotEqual(TObject ob)
    • selectGreater

      public IntegerVector selectGreater(TObject ob)
    • selectLess

      public IntegerVector selectLess(TObject ob)
    • selectGreaterOrEqual

      public IntegerVector selectGreaterOrEqual(TObject ob)
    • selectLessOrEqual

      public IntegerVector selectLessOrEqual(TObject ob)
    • selectBetween

      public IntegerVector selectBetween(TObject ob1, TObject ob2)