Class 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.
    • 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.
    • Constructor Detail

      • JoinedTable

        JoinedTable​(Table[] tables)
        Constructs the JoinedTable with the list of tables in the parent.
      • JoinedTable

        JoinedTable​(Table table)
        Constructs the JoinedTable with a single table.
      • JoinedTable

        protected JoinedTable()
        Protected constructor.
    • 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 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.
      • 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 class Table
      • 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 class Table
      • 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.
      • 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
      • 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 class Table
      • 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 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.