Package com.mckoi.database
Class CompositeTable
- java.lang.Object
-
- com.mckoi.database.Table
-
- 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.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.mckoi.database.Table
Table.TableVariableResolver
-
-
Field Summary
Fields Modifier and Type Field Description private SelectableScheme[]column_schemeThe schemes to describe the entity relation in the given column.private Table[]composite_tablesThe tables being made a composite of.static intEXCEPTThe composite function for finding the difference of the tables.static intINTERSECTThe composite function for finding the interestion of the tables.private Tablemaster_tableThe 'master table' used to resolve information about this table such as fields and field types.private introots_lockedThe number of root locks on this table.private IntegerVector[]table_indexesThe list of indexes of rows to include in each table.static intUNIONThe composite function for finding the union of the tables.-
Fields inherited from class com.mckoi.database.Table
DEBUG_QUERY
-
-
Constructor Summary
Constructors Constructor Description 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) voidaddDataTableListener(DataTableListener listener)Adds a DataTableListener to the DataTable objects at the root of this table tree hierarchy.intfindFieldName(Variable v)Given a fully qualified variable field name, ie.TObjectgetCellContents(int column, int row)Returns an object that represents the information in the given cell in the table.intgetColumnCount()Returns the number of columns in the table.DatabasegetDatabase()Returns the Database object that this table is derived from.DataTableDefgetDataTableDef()Returns a DataTableDef object that defines the name of the table and the layout of the columns of the table.VariablegetResolvedVariable(int column)Returns a fully qualified Variable object that represents the name of the column at the given index.intgetRowCount()Returns the number of rows stored in the table.(package private) SelectableSchemegetSelectableSchemeFor(int column, int original_column, Table table)Returns a SelectableScheme for the given column in the given VirtualTable row domain.booleanhasRootsLocked()Returns true if the table has its row roots locked (via the lockRoot(int) method.voidlockRoot(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.(package private) voidremoveDataTableListener(DataTableListener listener)Removes a DataTableListener from the DataTable objects at the root of this table tree hierarchy.private voidremoveDuplicates(boolean pre_sorted)Removes duplicate rows from the table.(package private) RawTableInformationresolveToRawTable(RawTableInformation info)Return the list of DataTable and row sets that make up the raw information in this table.RowEnumerationrowEnumeration()Returns an Enumeration of the rows in this table.(package private) voidsetToRowTableDomain(int column, IntegerVector row_set, TableDataSource ancestor)Given a set, this trickles down through the Table hierarchy resolving the given row_set to a form that the given ancestor understands.voidsetupIndexesForCompositeFunction(int function, boolean all)Sets up the indexes in this composite table by performing for composite function on the tables.booleantypeEquals(RootTable table)This is function is used to check that two root tables are identical.voidunlockRoot(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, allRowsIn, allRowsNotIn, 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, getVariableResolver, join, orderByColumn, orderByColumn, orderByColumn, orderByColumns, orderedRowList, outside, printGraph, rangeSelect, selectAll, selectAll, selectFirst, selectFromPattern, selectFromRegex, selectLast, selectRange, selectRest, selectRows, selectRows, selectRows, simpleJoin, simpleSelect, singleRowSelect, toMap, toString, union
-
-
-
-
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.
-
master_table
private Table master_table
The 'master table' used to resolve information about this table such as fields and field types.
-
composite_tables
private Table[] composite_tables
The tables being made a composite of.
-
table_indexes
private IntegerVector[] table_indexes
The list of indexes of rows to include in each table.
-
column_scheme
private SelectableScheme[] column_scheme
The schemes to describe the entity relation in the given column.
-
roots_locked
private int roots_locked
The number of root locks on this table.
-
-
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
-
removeDuplicates
private void removeDuplicates(boolean pre_sorted)
Removes duplicate rows from the table. If 'pre_sorted' is true then each composite index is already in sorted order.
-
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:TableReturns the Database object that this table is derived from.- Specified by:
getDatabasein classTable
-
getColumnCount
public int getColumnCount()
Description copied from class:TableReturns the number of columns in the table.- Specified by:
getColumnCountin classTable
-
getRowCount
public int getRowCount()
Description copied from class:TableReturns the number of rows stored in the table.- Specified by:
getRowCountin interfaceTableDataSource- Specified by:
getRowCountin classTable
-
findFieldName
public int findFieldName(Variable v)
Description copied from class:TableGiven 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:
findFieldNamein classTable
-
getDataTableDef
public DataTableDef getDataTableDef()
Description copied from class:TableReturns 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:
getDataTableDefin interfaceTableDataSource- Specified by:
getDataTableDefin classTable
-
getResolvedVariable
public Variable getResolvedVariable(int column)
Description copied from class:TableReturns 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:
getResolvedVariablein classTable
-
getSelectableSchemeFor
SelectableScheme getSelectableSchemeFor(int column, int original_column, Table table)
Description copied from class:TableReturns a SelectableScheme for the given column in the given VirtualTable row domain. The 'column' variable may be modified as it traverses through the tables, however the 'original_column' retains the link to the column in 'table'.- Specified by:
getSelectableSchemeForin classTable
-
setToRowTableDomain
void setToRowTableDomain(int column, IntegerVector row_set, TableDataSource ancestor)Description copied from class:TableGiven a set, this trickles down through the Table hierarchy resolving the given row_set to a form that the given ancestor understands. Say you give the set { 0, 1, 2, 3, 4, 5, 6 }, this function may check down three levels and return a new 7 element set with the rows fully resolved to the given ancestors domain.- Specified by:
setToRowTableDomainin classTable
-
resolveToRawTable
RawTableInformation resolveToRawTable(RawTableInformation info)
Description copied from class:TableReturn the list of DataTable and row sets that make up the raw information in this table.- Specified by:
resolveToRawTablein classTable
-
getCellContents
public TObject getCellContents(int column, int row)
Description copied from class:TableReturns 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:
getCellContentsin interfaceTableDataSource- Specified by:
getCellContentsin classTable
-
rowEnumeration
public RowEnumeration rowEnumeration()
Description copied from class:TableReturns 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:
rowEnumerationin interfaceTableDataSource- Specified by:
rowEnumerationin classTable
-
addDataTableListener
void addDataTableListener(DataTableListener listener)
Description copied from class:TableAdds a DataTableListener to the DataTable objects at the root of this table tree hierarchy. If this table represents the join of a number of tables then the DataTableListener is added to all the DataTable objects at the root.A DataTableListener is notified of all modifications to the raw entries of the table. This listener can be used for detecting changes in VIEWs, for triggers or for caching of common queries.
- Specified by:
addDataTableListenerin classTable
-
removeDataTableListener
void removeDataTableListener(DataTableListener listener)
Description copied from class:TableRemoves a DataTableListener from the DataTable objects at the root of this table tree hierarchy. If this table represents the join of a number of tables, then the DataTableListener is removed from all the DataTable objects at the root.- Specified by:
removeDataTableListenerin classTable
-
lockRoot
public void lockRoot(int lock_key)
Description copied from class:TableLocks 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.
-
unlockRoot
public void unlockRoot(int lock_key)
Description copied from class:TableUnlocks 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:
unlockRootin classTable
-
hasRootsLocked
public boolean hasRootsLocked()
Description copied from class:TableReturns true if the table has its row roots locked (via the lockRoot(int) method.- Specified by:
hasRootsLockedin classTable
-
typeEquals
public boolean typeEquals(RootTable table)
Description copied from interface:RootTableThis 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:
typeEqualsin interfaceRootTable
-
-