Class V1MasterTableDataSource


  • public final class V1MasterTableDataSource
    extends MasterTableDataSource
    A MasterTableDataSource that uses IndexStore and VariableSizeDataStore as its backing mechanism for representing the table structure in a file on disk.

    The MasterTableDataSource is basically backed by a VariableSizeDataStore for data and an IndexStore for storing indexing information.

    • Field Detail

      • file_name

        private java.lang.String file_name
        The file name of this store in the conglomerate path.
      • data_store

        private VariableSizeDataStore data_store
        A VariableSizeDataStore object that physically contains the information stored in the file system in the contents of the data source.
      • index_store

        private IndexStore index_store
        An IndexStore object that manages the indexes for this table.
      • data_cell_serializer

        private final DataCellSerialization data_cell_serializer
        The object we use to serialize TObject objects.
      • cell_in

        private CellInputStream cell_in
        The persistent object we use to read information from a row stream.
      • s_run_total_hits

        private short s_run_total_hits
      • s_run_file_hits

        private short s_run_file_hits
      • OPT_last_row

        private int OPT_last_row
        Some variables that are used for optimization in the 'getCellContents' method.
      • OPT_last_col

        private int OPT_last_col
      • OPT_last_skip_offset

        private int OPT_last_skip_offset
    • Method Detail

      • getFileName

        java.lang.String getFileName()
        Returns the name of the file in the conglomerate that represents this store in the file system.
      • getPath

        java.io.File getPath()
        Returns the path of where this table is located.
      • create

        void create​(int table_id,
                    DataTableDef table_def,
                    int data_sector_size,
                    int index_sector_size)
             throws java.io.IOException
        Physically create this master table in the file system at the given path. This will initialise the various file objects and result in a new empty master table to store data in.

        The 'data_sector_size' and 'index_sector_size' are for fine grain performance and size optimization of the data files. The default 'index_sector_size' is 1024.

        Parameters:
        data_sector_size - used to configure the size of the sectors in the data files. For tables with small records this number should be low.
        index_sector_size - used to configure the size of the sectors in the index file. For small tables it is best to keep the index sector size low. Recommend 1024 for normal use, 128 for minimalist use.
        Throws:
        java.io.IOException
      • exists

        boolean exists​(java.lang.String file_name)
                throws java.io.IOException
        Returns true if the master table data source with the given filename exists.
        Throws:
        java.io.IOException
      • open

        void open​(java.lang.String file_name)
           throws java.io.IOException
        Opens an existing master table from the file system at the path of the conglomerate this belongs to. This will set up the internal state of this object with the data read in.
        Throws:
        java.io.IOException
      • dirtyOpen

        void dirtyOpen​(java.lang.String file_name)
                throws java.io.IOException
        Opens this source in the most minimal way. This should only be used for diagnostics of the data. This will not load the index.
        Throws:
        java.io.IOException
      • close

        void close()
            throws java.io.IOException
        Closes this master table in the file system. This frees up all the resources associated with this master table.

        This method is typically called when the database is shut down.

        Throws:
        java.io.IOException
      • rawRecordSize

        int rawRecordSize​(int row_number)
                   throws java.io.IOException
        Returns the number of bytes the row takes up in the data file. This is the actual space used. If a cell is compressed then it includes the compressed size, not the uncompressed.
        Throws:
        java.io.IOException
      • rawDataSectorSize

        int rawDataSectorSize()
                       throws java.io.IOException
        Returns the current sector size for this data source.
        Throws:
        java.io.IOException
      • rebuildAllIndices

        private void rebuildAllIndices​(java.io.File path,
                                       java.lang.String file_name)
                                throws java.io.IOException
        This may only be called from the 'fix' method. It performs a full scan of the records and rebuilds all the index information from the information.

        This should only be used as a recovery mechanism and may not accurately rebuild in some cases (but should rebuild as best as possible non the less).

        Throws:
        java.io.IOException
      • copyTo

        void copyTo​(java.io.File path)
             throws java.io.IOException
        Copies the persistant information in this table data source to the given directory in the file system. This makes an exact copy of the table as it currently is. It is recommended that when this is used, there is a lock to prevent committed changes to the database.
        Throws:
        java.io.IOException
      • checkAndRepair

        public void checkAndRepair​(java.lang.String file_name,
                                   UserTerminal terminal)
                            throws java.io.IOException
        Performs a complete check and repair of the table. The table must not have been opened before this method is called. The given UserTerminal parameter is an implementation of a user interface that is used to ask any questions and output the results of the check.
        Throws:
        java.io.IOException
      • checkForCleanup

        public void checkForCleanup()
        Description copied from class: MasterTableDataSource
        Checks to determine if it is safe to clean up any resources in the table, and if it is safe to do so, the space is reclaimed.
        Specified by:
        checkForCleanup in class MasterTableDataSource
      • getSourceIdent

        java.lang.String getSourceIdent()
        Description copied from class: MasterTableDataSource
        Returns a string that uniquely identifies this table within the conglomerate context. For example, the filename of the table. This string can be used to open and initialize the table also.
        Specified by:
        getSourceIdent in class MasterTableDataSource
      • synchAll

        void synchAll()
               throws java.io.IOException
        Throws:
        java.io.IOException
      • writeRecordType

        int writeRecordType​(int row_index,
                            int row_state)
                     throws java.io.IOException
        Description copied from class: MasterTableDataSource
        Sets the record type for the given record in the table and returns the previous state of the record. This is used to change the state of a row in the table.
        Specified by:
        writeRecordType in class MasterTableDataSource
        Throws:
        java.io.IOException
      • readRecordType

        int readRecordType​(int row_index)
                    throws java.io.IOException
        Description copied from class: MasterTableDataSource
        Reads the record state for the given record in the table.
        Specified by:
        readRecordType in class MasterTableDataSource
        Throws:
        java.io.IOException
      • recordDeleted

        boolean recordDeleted​(int row_index)
                       throws java.io.IOException
        Description copied from class: MasterTableDataSource
        Returns true if the record with the given index is deleted from the table. A deleted row can not be read.
        Specified by:
        recordDeleted in class MasterTableDataSource
        Throws:
        java.io.IOException
      • rawRowCount

        int rawRowCount()
                 throws java.io.IOException
        Description copied from class: MasterTableDataSource
        Returns the raw count or rows in the table, including uncommited, committed and deleted rows. This is basically the maximum number of rows we can iterate through.
        Specified by:
        rawRowCount in class MasterTableDataSource
        Throws:
        java.io.IOException
      • internalDeleteRow

        void internalDeleteRow​(int row_index)
                        throws java.io.IOException
        Description copied from class: MasterTableDataSource
        Removes the row at the given index so that any resources associated with the row may be immediately available to be recycled.
        Specified by:
        internalDeleteRow in class MasterTableDataSource
        Throws:
        java.io.IOException
      • createIndexSet

        IndexSet createIndexSet()
        Description copied from class: MasterTableDataSource
        Creates and returns an IndexSet object that is used to create indices for this table source. The IndexSet represents a snapshot of the table and the given point in time.

        NOTE: Not synchronized because we synchronize in the IndexStore object.

        Specified by:
        createIndexSet in class MasterTableDataSource
      • loadDataTableDef

        DataTableDef loadDataTableDef()
                               throws java.io.IOException
        Throws:
        java.io.IOException
      • saveDataTableDef

        void saveDataTableDef​(DataTableDef def)
                       throws java.io.IOException
        Throws:
        java.io.IOException
      • internalAddRow

        int internalAddRow​(RowData data)
                    throws java.io.IOException
        Description copied from class: MasterTableDataSource
        Adds a new row to this table and returns an index that is used to reference this row by the 'getCellContents' method.

        Note that this method will not effect the master index or column schemes. This is a low level mechanism for adding unreferenced data into a conglomerate. The data is referenced by committing the change where it eventually migrates into the master index and schemes.

        Specified by:
        internalAddRow in class MasterTableDataSource
        Throws:
        java.io.IOException
      • internalGetCellContents

        TObject internalGetCellContents​(int column,
                                        int row)
        Description copied from class: MasterTableDataSource
        Returns the cell contents of the given cell in the table. It is the responsibility of the implemented method to perform caching as it deems fit. Some representations may not require such extensive caching as others.
        Specified by:
        internalGetCellContents in class MasterTableDataSource
      • setUniqueID

        void setUniqueID​(long value)
        Description copied from class: MasterTableDataSource
        Sets the unique id for this store. This must only be used under extraordinary circumstances, such as restoring from a backup, or converting from one file to another.
        Specified by:
        setUniqueID in class MasterTableDataSource
      • dispose

        void dispose​(boolean pending_close)
              throws java.io.IOException
        Description copied from class: MasterTableDataSource
        Disposes of all in-memory resources associated with this table and invalidates this object. If 'pending_drop' is true then the table is to be disposed pending a call to 'drop'. If 'pending_drop' is true then any persistant resources that are allocated may be freed.
        Specified by:
        dispose in class MasterTableDataSource
        Throws:
        java.io.IOException
      • drop

        boolean drop()
              throws java.io.IOException
        Description copied from class: MasterTableDataSource
        Disposes and drops this table. If the dispose failed for any reason, it returns false, otherwise true. If the drop failed, it should be retried at a later time.
        Specified by:
        drop in class MasterTableDataSource
        Throws:
        java.io.IOException
      • shutdownHookCleanup

        void shutdownHookCleanup()
        Description copied from class: MasterTableDataSource
        Called by the 'shutdown hook' on the conglomerate. This method should block until the table can by put into a safe mode and then prevent any further access to the object after it returns. It must operate very quickly.
        Specified by:
        shutdownHookCleanup in class MasterTableDataSource
      • toString

        public java.lang.String toString()
        For diagnostic.
        Overrides:
        toString in class java.lang.Object