Package com.mckoi.database

## Class JoinedTable

- java.lang.Object
- - com.mckoi.database.Table
  - - com.mckoi.database.JoinedTable

All Implemented Interfaces:
  `TableDataSource`

Direct Known Subclasses:
  `NaturallyJoinedTable`, `VirtualTable`

    public abstract class JoinedTable
    extends Table

A Table that represents the result of one or more other tables joined together. VirtualTable and NaturallyJoinedTable are derived from this class.

Author:
  Tobias Downer

### Field Summary

Fields
`protected int[]` `column_filter` Gives a column filter to the given column to route correctly to the ancestor.
`protected SelectableScheme[]` `column_scheme` The schemes to describe the entity relation in the given column.
`protected int[]` `column_table` Maps the column number in this table to the reference_list array to route to.
`protected Table[]` `reference_list` The list of tables that make up the join.

### Fields inherited from class com.mckoi.database.Table

`DEBUG_QUERY`

### Constructor Summary

Constructors
`protected` `JoinedTable()` Protected constructor.

### Method Summary

All Methods Instance Methods Abstract Methods Concrete Methods
`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()` We simply pick the first table to resolve the Database object.
`DataTableDef` `getDataTableDef()` Returns the DataTableDef object that describes the columns in this table.
`protected Table[]` `getReferenceTables()` Returns the list of Table objects that represent this VirtualTable.
`Variable` `getResolvedVariable​(int column)` Returns a fully qualified Variable object that represents the name of the column at the given index.
`boolean` `hasRootsLocked()` Returns true if the table has its row roots locked (via the lockRoot(int) method.
`protected void` `init​(Table[] tables)` Helper function for initializing the variables in the joined table.
`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.
`void` `printGraph​(java.io.PrintStream out, int indent)` Prints a graph of the table hierarchy to the stream.
`protected abstract void` `resolveAllRowsForTableAt​(IntegerVector row_set, int table_num)` Given an IntegerVector that represents a list of pointers to rows in this table, this resolves the rows to row indexes in the given parent table.
`protected abstract int` `resolveRowForTableAt​(int row_number, int table_num)` Given a row and a table index (to a parent reference table), this will return the row index in the given parent table for the given row.
`RowEnumeration` `rowEnumeration()` Returns an Enumeration of the rows in this table.
`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, getRowCount, getSingleCellContent, getSingleCellContent, getSystem, getTableAccessState, getTTypeForColumn, getTTypeForColumn, join, orderByColumn, orderByColumn, orderByColumn, orderByColumns, orderedRowList, outside, 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

#### reference_list

    protected Table[] reference_list

The list of tables that make up the join.

#### column_scheme

    protected SelectableScheme[] column_scheme

The schemes to describe the entity relation in the given column.

#### column_table

    protected int[] column_table

Maps the column number in this table to the reference_list array to route to.

#### column_filter

    protected int[] column_filter

Gives a column filter to the given column to route correctly to the ancestor.

### Constructor Detail

#### JoinedTable

    protected JoinedTable()

Protected constructor.

### Method Detail

#### init

    protected void init​(Table[] tables)

Helper function for initializing the variables in the joined table.

#### getDatabase

    public Database getDatabase()

We simply pick the first table to resolve the Database object.

Specified by:
  `getDatabase` in class `Table`

#### getColumnCount

    public int getColumnCount()

Returns the number of columns in the table. This simply returns the column counts in the parent table(s).

Specified by:
  `getColumnCount` in class `Table`

#### findFieldName

    public int findFieldName​(Variable v)

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`

#### getResolvedVariable

    public final Variable getResolvedVariable​(int column)

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`

#### getReferenceTables

    protected final Table[] getReferenceTables()

Returns the list of Table objects that represent this VirtualTable.

#### getDataTableDef

    public DataTableDef getDataTableDef()

Returns the DataTableDef object that describes the columns in this table. For a VirtualTable, this object contains the union of all the columns in the children in the order set. The name of a virtual table is the concat of all the parent table names. The schema is set to null.

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

#### getCellContents

    public TObject getCellContents​(int column,
                                   int row)

Returns an object that represents the information in the given cell in the table.

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

#### rowEnumeration

    public RowEnumeration rowEnumeration()

Returns an Enumeration of the rows in this table. The Enumeration is a fast way of retrieving consequtive rows in the table.

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

#### lockRoot

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

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()

Returns true if the table has its row roots locked (via the lockRoot(int) method.

Specified by:
  `hasRootsLocked` in class `Table`

#### printGraph

    public void printGraph​(java.io.PrintStream out,
                           int indent)

Prints a graph of the table hierarchy to the stream.

Overrides:
  `printGraph` in class `Table`

#### resolveRowForTableAt

    protected abstract int resolveRowForTableAt​(int row_number,
                                                int table_num)

Given a row and a table index (to a parent reference table), this will return the row index in the given parent table for the given row.

#### resolveAllRowsForTableAt

    protected abstract void resolveAllRowsForTableAt​(IntegerVector row_set,
                                                     int table_num)

Given an IntegerVector that represents a list of pointers to rows in this table, this resolves the rows to row indexes in the given parent table. This method changes the 'row_set' IntegerVector object.