com.mckoi.database
Class SelectableScheme

java.lang.Object
  extended by com.mckoi.database.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.

Author:
Tobias Downer

Field Summary
protected static BlockIntegerList EMPTY_LIST
          Some statics.
protected static BlockIntegerList ONE_LIST
           
 
Constructor Summary
SelectableScheme(TableDataSource table, int column)
          The constructor for all schemes.
 
Method Summary
abstract  SelectableScheme copy(TableDataSource table, boolean immutable)
          Returns an exact copy of this scheme including any optimization information.
protected  DebugLogger Debug()
          Returns the DebugLogger object to log debug messages to.
abstract  void dispose()
          Dispose and invalidate this scheme.
protected  TObject getCellContents(int row)
          Obtains the given cell in the row from the table.
protected  int getColumn()
          Returns the column this scheme is indexing in the table.
 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.
protected  TransactionSystem getSystem()
          Returns the global transaction system.
protected  TableDataSource getTable()
          Returns the Table.
 BlockIntegerList internalOrderIndexSet(IntegerVector row_set)
          Returns a BlockIntegerList that represents the given row_set sorted in the order of this scheme.
 boolean isImmutable()
          Returns true if this scheme is immutable.
abstract  void readFrom(java.io.InputStream in)
          Reads the entire contents of the scheme from a InputStream object.
 IntegerVector selectAll()
          These are the select operations that are the main purpose of the scheme.
 IntegerVector selectAllNonNull()
          Selects all values in the column that are not null.
 IntegerVector selectBetween(TObject ob1, TObject ob2)
           
 IntegerVector selectEqual(TObject ob)
           
 IntegerVector selectFirst()
           
 IntegerVector selectGreater(TObject ob)
           
 IntegerVector selectGreaterOrEqual(TObject ob)
           
 IntegerVector selectLast()
           
 IntegerVector selectLess(TObject ob)
           
 IntegerVector selectLessOrEqual(TObject ob)
           
 IntegerVector selectNotEqual(TObject ob)
           
 IntegerVector selectNotFirst()
           
 IntegerVector selectNotLast()
           
 void setImmutable()
          Sets this scheme to immutable.
 java.lang.String toString()
          Diagnostic information.
abstract  void writeTo(java.io.OutputStream out)
          Writes the entire contents of the scheme to an OutputStream object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

EMPTY_LIST

protected static final BlockIntegerList EMPTY_LIST
Some statics.


ONE_LIST

protected static final BlockIntegerList ONE_LIST
Constructor Detail

SelectableScheme

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

Method Detail

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 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.


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)