com.mckoi.database
Class CompositeTable

java.lang.Object
  extended by com.mckoi.database.Table
      extended by com.mckoi.database.CompositeTable
All Implemented Interfaces:
RootTable, TableDataSource

public class CompositeTable
extends Table
implements RootTable

A composite of two or more datasets used to implement UNION, INTERSECTION, and DIFFERENCE.

Author:
Tobias Downer

Field Summary
static int EXCEPT
          The composite function for finding the difference of the tables.
static int INTERSECT
          The composite function for finding the interestion of the tables.
static int UNION
          The composite function for finding the union of the tables.
 
Fields inherited from class com.mckoi.database.Table
DEBUG_QUERY
 
Constructor Summary
CompositeTable(Table[] composite_list)
          Consturcts the composite table assuming the first item in the list is the master table.
CompositeTable(Table master_table, Table[] composite_list)
          Constructs the composite table given the 'master_table' (the field structure this composite dataset is based on), and a list of tables to be the composite of this table.
 
Method Summary
 int findFieldName(Variable v)
          Given a fully qualified variable field name, ie.
 TObject getCellContents(int column, int row)
          Returns an object that represents the information in the given cell in the table.
 int getColumnCount()
          Returns the number of columns in the table.
 Database getDatabase()
          Returns the Database object that this table is derived from.
 DataTableDef getDataTableDef()
          Returns a DataTableDef object that defines the name of the table and the layout of the columns of the table.
 Variable getResolvedVariable(int column)
          Returns a fully qualified Variable object that represents the name of the column at the given index.
 int getRowCount()
          Returns the number of rows stored in the table.
 boolean hasRootsLocked()
          Returns true if the table has its row roots locked (via the lockRoot(int) method.
 void lockRoot(int lock_key)
          Locks the root table(s) of this table so that it is impossible to overwrite the underlying rows that may appear in this table.
 RowEnumeration rowEnumeration()
          Returns an Enumeration of the rows in this table.
 void setupIndexesForCompositeFunction(int function, boolean all)
          Sets up the indexes in this composite table by performing for composite function on the tables.
 boolean typeEquals(RootTable table)
          This is function is used to check that two root tables are identical.
 void unlockRoot(int lock_key)
          Unlocks the root tables so that the underlying rows may once again be used if they are not locked and have been removed.
 
Methods inherited from class com.mckoi.database.Table
all, allColumnMatchesValue, any, columnContainsCell, columnContainsValue, columnMatchesValue, columnMerge, compareCells, Debug, distinct, distinct, dumpTo, emptySelect, exhaustiveSelect, fastFindFieldName, getColumnDefAt, getColumnScheme, getFirstCellContent, getFirstCellContent, getLastCellContent, getLastCellContent, getSingleCellContent, getSingleCellContent, getSystem, getTableAccessState, getTTypeForColumn, getTTypeForColumn, join, orderByColumn, orderByColumn, orderByColumn, orderByColumns, orderedRowList, outside, printGraph, rangeSelect, selectAll, selectAll, selectFirst, selectLast, selectRange, selectRest, simpleJoin, simpleSelect, singleRowSelect, toMap, toString, union
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

UNION

public static int UNION
The composite function for finding the union of the tables.


INTERSECT

public static int INTERSECT
The composite function for finding the interestion of the tables.


EXCEPT

public static int EXCEPT
The composite function for finding the difference of the tables.

Constructor Detail

CompositeTable

public CompositeTable(Table master_table,
                      Table[] composite_list)
Constructs the composite table given the 'master_table' (the field structure this composite dataset is based on), and a list of tables to be the composite of this table. The 'master_table' must be one of the elements of the 'composite_list' array.

NOTE: This does not set up table indexes for a composite function.


CompositeTable

public CompositeTable(Table[] composite_list)
Consturcts the composite table assuming the first item in the list is the master table.

Method Detail

setupIndexesForCompositeFunction

public void setupIndexesForCompositeFunction(int function,
                                             boolean all)
Sets up the indexes in this composite table by performing for composite function on the tables. If the 'all' parameter is true then duplicate rows are removed.


getDatabase

public Database getDatabase()
Description copied from class: Table
Returns the Database object that this table is derived from.

Specified by:
getDatabase in class Table

getColumnCount

public int getColumnCount()
Description copied from class: Table
Returns the number of columns in the table.

Specified by:
getColumnCount in class Table

getRowCount

public int getRowCount()
Description copied from class: Table
Returns the number of rows stored in the table.

Specified by:
getRowCount in interface TableDataSource
Specified by:
getRowCount in class Table

findFieldName

public int findFieldName(Variable v)
Description copied from class: Table
Given a fully qualified variable field name, ie. 'APP.CUSTOMER.CUSTOMERID' this will return the column number the field is at. Returns -1 if the field does not exist in the table.

Specified by:
findFieldName in class Table

getDataTableDef

public DataTableDef getDataTableDef()
Description copied from class: Table
Returns a DataTableDef object that defines the name of the table and the layout of the columns of the table. Note that for tables that are joined with other tables, the table name and schema for this object become mangled. For example, a table called 'PERSON' joined with a table called 'MUSIC' becomes a table called 'PERSON#MUSIC' in a null schema.

Specified by:
getDataTableDef in interface TableDataSource
Specified by:
getDataTableDef in class Table

getResolvedVariable

public Variable getResolvedVariable(int column)
Description copied from class: Table
Returns a fully qualified Variable object that represents the name of the column at the given index. For example, new Variable(new TableName("APP", "CUSTOMER"), "ID")

Specified by:
getResolvedVariable in class Table

getCellContents

public TObject getCellContents(int column,
                               int row)
Description copied from class: Table
Returns an object that represents the information in the given cell in the table. This will generally be an expensive algorithm, so calls to it should be kept to a minimum. Note that the offset between two rows is not necessarily 1. Use 'rowEnumeration' to get the contents of a set.

Specified by:
getCellContents in interface TableDataSource
Specified by:
getCellContents in class Table

rowEnumeration

public RowEnumeration rowEnumeration()
Description copied from class: Table
Returns an Enumeration of the rows in this table. Each call to 'RowEnumeration.nextRowIndex()' returns the next valid row in the table. Note that the order that rows are retreived depend on a number of factors. For a DataTable the rows are accessed in the order they are in the data file. For a VirtualTable, the rows are accessed in the order of the last select operation.

If you want the rows to be returned by a specific column order then use the 'selectxxx' methods.

Specified by:
rowEnumeration in interface TableDataSource
Specified by:
rowEnumeration in class Table

lockRoot

public void lockRoot(int lock_key)
Description copied from class: Table
Locks the root table(s) of this table so that it is impossible to overwrite the underlying rows that may appear in this table. This is used when cells in the table need to be accessed 'outside' the lock. So we may have late access to cells in the table. 'lock_key' is a given key that will also unlock the root table(s). NOTE: This is nothing to do with the 'LockingMechanism' object.

Specified by:
lockRoot in class Table

unlockRoot

public void unlockRoot(int lock_key)
Description copied from class: Table
Unlocks the root tables so that the underlying rows may once again be used if they are not locked and have been removed. This should be called some time after the rows have been locked.

Specified by:
unlockRoot in class Table

hasRootsLocked

public boolean hasRootsLocked()
Description copied from class: Table
Returns true if the table has its row roots locked (via the lockRoot(int) method.

Specified by:
hasRootsLocked in class Table

typeEquals

public boolean typeEquals(RootTable table)
Description copied from interface: RootTable
This is function is used to check that two root tables are identical. This is used if we need to chect that the form of the table is the same. Such as in a union operation, when we can only union two tables with the identical columns.

Specified by:
typeEquals in interface RootTable