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.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.mckoi.database.Table
Table.TableVariableResolver
-
-
Field Summary
Fields Modifier and Type Field Description 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.private byte
roots_locked
Incremented when the roots are locked.private int
sorted_against_column
The column that we are sorted against.private DataTableDef
vt_table_def
The DataTableDef object that describes the columns and name of this table.-
Fields inherited from class com.mckoi.database.Table
DEBUG_QUERY
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
JoinedTable()
Protected constructor.(package private)
JoinedTable(Table table)
Constructs the JoinedTable with a single table.(package private)
JoinedTable(Table[] tables)
Constructs the JoinedTable with the list of tables in the parent.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description (package private) void
addDataTableListener(DataTableListener listener)
Adds a DataTableListener to the DataTable objects at the root of this table tree hierarchy.private IntegerVector
calculateRowReferenceList()
Returns a row reference list.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.(package private) SelectableScheme
getSelectableSchemeFor(int column, int original_column, Table table)
Returns a SelectableScheme for the given column in the given VirtualTable row domain.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.(package private) void
optimisedPostSet(int column)
This is an optimisation that should only be called _after_ a 'set' method has been called.void
printGraph(java.io.PrintStream out, int indent)
Prints a graph of the table hierarchy to the stream.(package private) void
removeDataTableListener(DataTableListener listener)
Removes a DataTableListener from the DataTable objects at the root of this table tree hierarchy.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.(package private) RawTableInformation
resolveToRawTable(RawTableInformation info)
Return the list of DataTable and row sets that make up the raw information in this table.(package private) RawTableInformation
resolveToRawTable(RawTableInformation info, IntegerVector row_set)
Returns an object that contains fully resolved, one level only information about the DataTable and the row indices of the data in this table.RowEnumeration
rowEnumeration()
Returns an Enumeration of the rows in this table.(package private) void
setToRowTableDomain(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.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, allRowsIn, allRowsNotIn, 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, getVariableResolver, join, orderByColumn, orderByColumn, orderByColumn, orderByColumns, orderedRowList, outside, rangeSelect, selectAll, selectAll, selectFirst, selectFromPattern, selectFromRegex, selectLast, selectRange, selectRest, selectRows, selectRows, selectRows, simpleJoin, simpleSelect, singleRowSelect, toMap, toString, union
-
-
-
-
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.
-
sorted_against_column
private int sorted_against_column
The column that we are sorted against. This is an optimization set by the 'optimisedPostSet' method.
-
vt_table_def
private DataTableDef vt_table_def
The DataTableDef object that describes the columns and name of this table.
-
roots_locked
private byte roots_locked
Incremented when the roots are locked. See the 'lockRoot' and 'unlockRoot' methods. NOTE: This should only ever be 1 or 0.
-
-
Method Detail
-
init
protected void init(Table[] tables)
Helper function for initializing the variables in the joined table.
-
calculateRowReferenceList
private IntegerVector calculateRowReferenceList()
Returns a row reference list. This is an IntegerVector that represents a 'reference' to the rows in our virtual table.ISSUE: We should be able to optimise these types of things out.
-
getDatabase
public Database getDatabase()
We simply pick the first table to resolve the Database object.- Specified by:
getDatabase
in classTable
-
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 classTable
-
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 classTable
-
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 classTable
-
getReferenceTables
protected final Table[] getReferenceTables()
Returns the list of Table objects that represent this VirtualTable.
-
optimisedPostSet
void optimisedPostSet(int column)
This is an optimisation that should only be called _after_ a 'set' method has been called. Because the 'select' operation returns a set that is ordered by the given column, we can very easily generate a SelectableScheme object that can handle this column. So 'column' is the column in which this virtual table is naturally ordered by. NOTE: The internals of this method may be totally commented out and the database will still operate correctly. However this greatly speeds up situations when you perform multiple consequtive operations on the same column.
-
getSelectableSchemeFor
SelectableScheme getSelectableSchemeFor(int column, int original_column, Table table)
Returns a SelectableScheme for the given column in the given VirtualTable row domain. This searches down through the tables ancestors until it comes across a table with a SelectableScheme where the given column is fully resolved. In most cases, this will be the root DataTable.- Specified by:
getSelectableSchemeFor
in classTable
-
setToRowTableDomain
void setToRowTableDomain(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. 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:
setToRowTableDomain
in classTable
-
resolveToRawTable
RawTableInformation resolveToRawTable(RawTableInformation info, IntegerVector row_set)
Returns an object that contains fully resolved, one level only information about the DataTable and the row indices of the data in this table. This information can be used to construct a new VirtualTable. We need to supply an empty RawTableInformation object.
-
resolveToRawTable
RawTableInformation resolveToRawTable(RawTableInformation info)
Return the list of DataTable and row sets that make up the raw information in this table.- Specified by:
resolveToRawTable
in classTable
-
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 interfaceTableDataSource
- Specified by:
getDataTableDef
in classTable
-
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 interfaceTableDataSource
- Specified by:
getCellContents
in classTable
-
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 interfaceTableDataSource
- Specified by:
rowEnumeration
in classTable
-
addDataTableListener
void addDataTableListener(DataTableListener listener)
Adds 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:
addDataTableListener
in classTable
-
removeDataTableListener
void removeDataTableListener(DataTableListener listener)
Removes 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:
removeDataTableListener
in classTable
-
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.
-
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 classTable
-
hasRootsLocked
public boolean hasRootsLocked()
Returns true if the table has its row roots locked (via the lockRoot(int) method.- Specified by:
hasRootsLocked
in classTable
-
printGraph
public void printGraph(java.io.PrintStream out, int indent)
Prints a graph of the table hierarchy to the stream.- Overrides:
printGraph
in classTable
-
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.
-
-