Package com.mckoi.database
Class FunctionTable
java.lang.Object
com.mckoi.database.Table
com.mckoi.database.AbstractDataTable
com.mckoi.database.DefaultDataTable
com.mckoi.database.FunctionTable
- All Implemented Interfaces:
RootTable
,TableDataSource
A table that has a number of columns and as many rows as the refering
table. Tables of this type are used to construct aggregate and function
columns based on an expression. They are joined with the result table in
the last part of the query processing.
For example, a query like 'select id, id * 2, 8 * 9 from Part' the columns 'id * 2' and '8 * 9' would be formed from this table.
SYNCHRONIZATION ISSUE: Instances of this object are NOT thread safe. The reason it's not is because if 'getCellContents' is used concurrently it's possible for the same value to be added into the cache causing an error. It is not expected that this object will be shared between threads.
- Author:
- Tobias Downer
-
Field Summary
Fields inherited from class com.mckoi.database.DefaultDataTable
row_count
Fields inherited from class com.mckoi.database.Table
DEBUG_QUERY
-
Constructor Summary
ConstructorsConstructorDescriptionFunctionTable
(Expression[] exp_list, String[] col_names, DatabaseQueryContext context) FunctionTable
(Table cross_ref_table, Expression[] in_exp_list, String[] col_names, DatabaseQueryContext context) Constructs the FunctionTable. -
Method Summary
Modifier and TypeMethodDescriptionvoid
createGroupMatrix
(Variable[] col_list) Creates a grouping matrix for the given tables.getCellContents
(int column, int row) Returns an object that represents the information in the given cell in the table.Returns the DataTableDef object that represents the columns in this function table.Returns the Table this function is based on.groupRows
(int group_number) Returns an IntegerVector that represents the list of all rows in the group the index is at.int
groupSize
(int group_number) The size of the group with the given number.boolean
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.mergeWithReference
(Variable max_column) Returns a Table that is this function table merged with the cross reference table.static Table
resultTable
(DatabaseQueryContext context, int result_val) Returns a FunctionTable that has an int value made into a BigDecimal.static Table
resultTable
(DatabaseQueryContext context, Expression expression) Returns a FunctionTable that has a single Expression evaluated in it.static Table
resultTable
(DatabaseQueryContext context, TObject ob) Returns a FunctionTable that has a single TObject in it.static Table
resultTable
(DatabaseQueryContext context, Object ob) Returns a FunctionTable that has a single Object in it.Returns an Enumeration of the rows in this table.int
rowGroup
(int row_index) Returns the group of the row at the given index.void
Sets the whole reference table as a single group.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.DefaultDataTable
blankSelectableSchemes, blankSelectableSchemes, clearColumnScheme, findFieldName, getColumnCount, getDatabase, getResolvedVariable, getRootColumnScheme, getRowCount
Methods inherited from class com.mckoi.database.AbstractDataTable
getTableName, toString, typeEquals
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, union
-
Constructor Details
-
FunctionTable
public FunctionTable(Table cross_ref_table, Expression[] in_exp_list, String[] col_names, DatabaseQueryContext context) Constructs the FunctionTable. -
FunctionTable
-
-
Method Details
-
setWholeTableAsGroup
public void setWholeTableAsGroup()Sets the whole reference table as a single group. -
createGroupMatrix
Creates a grouping matrix for the given tables. The grouping matrix is arranged so that each row of the referring table that is in the group is given a number that refers to the top group entry in the group list. The group list is a linked integer list that chains through each row item in the list. -
getReferenceTable
Returns the Table this function is based on. We need to provide this method for aggregate functions. -
rowGroup
public int rowGroup(int row_index) Returns the group of the row at the given index. -
groupSize
public int groupSize(int group_number) The size of the group with the given number. -
groupRows
Returns an IntegerVector that represents the list of all rows in the group the index is at. -
mergeWithReference
Returns a Table that is this function table merged with the cross reference table. The result table includes only one row from each group.The 'max_column' argument is optional (can be null). If it's set to a column in the reference table, then the row with the max value from the group is used as the group row. For example, 'Part.id' will return the row with the maximum part.id from each group.
-
getDataTableDef
Returns the DataTableDef object that represents the columns in this function table.- Specified by:
getDataTableDef
in interfaceTableDataSource
- Specified by:
getDataTableDef
in classTable
-
getCellContents
Returns an object that represents the information in the given cell in the table. This can be used to obtain information about the given table cells.- Specified by:
getCellContents
in interfaceTableDataSource
- Specified by:
getCellContents
in classTable
-
rowEnumeration
Returns an Enumeration of the rows in this table. Each call to 'nextRowIndex' returns the next valid row index in the table.- Specified by:
rowEnumeration
in interfaceTableDataSource
- Specified by:
rowEnumeration
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
-
resultTable
Returns a FunctionTable that has a single Expression evaluated in it. The column name is 'result'. -
resultTable
Returns a FunctionTable that has a single TObject in it. The column title is 'result'. -
resultTable
Returns a FunctionTable that has a single Object in it. The column title is 'result'. -
resultTable
Returns a FunctionTable that has an int value made into a BigDecimal. The column title is 'result'.
-