Class MasterTableJournal


  • final class MasterTableJournal
    extends java.lang.Object
    A journal of changes that occured to a table in a data conglomerate during a transaction.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private byte[] command_journal
      A byte[] array that represents the set of commands a transaction performed on this table.
      private IntegerVector command_parameters
      An IntegerVector that is filled with parameters from the command journal.
      private long commit_id
      The commit id given to this change when it is committed.
      private int journal_entries
      The number of entries in this journal.
      (package private) static byte TABLE_ADD
      Journal commands.
      private int table_id
      The master table id.
      (package private) static byte TABLE_REMOVE  
      (package private) static byte TABLE_UPDATE_ADD  
      (package private) static byte TABLE_UPDATE_REMOVE  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void addCommand​(byte command)
      Adds a command to the journal.
      (package private) void addEntry​(byte command, int row_index)
      Adds a new command to this journal.
      private void addParameter​(int param)
      Adds a parameter to the journal command parameters.
      (package private) IntegerVector[] allChangeInformation()
      Returns three lists - a list of all rows that were inserted, a list of all rows that were deleted, and a list of all updates.
      (package private) int entries()
      Returns the total number of journal entries.
      (package private) byte getCommand​(int n)
      Returns the command of the nth entry in the journal.
      (package private) long getCommitID()
      Returns the commit_id that has been set for this journal.
      (package private) int getRowIndex​(int n)
      Returns the row index of the nth entry in the journal.
      (package private) int getTableID()
      Returns the table id of the master table this journal is for.
      (package private) static boolean isAddCommand​(byte command)
      Returns true if the given command is an addition command.
      (package private) static boolean isRemoveCommand​(byte command)
      Returns true if the given command is a removal command.
      (package private) int[] normalizedAddedRows()
      Returns a normalized list of all rows that were added in this journal, but not including those rows also removed.
      (package private) int[] normalizedRemovedRows()
      Returns a normalized list of all rows that were removed from this journal.
      (package private) void readFrom​(java.io.DataInputStream din)
      Reads the journal entries from the given DataInputStream to this object.
      private void removeTopEntries​(int n)
      Removes the top n entries from the journal.
      (package private) void rollbackEntries​(int n)
      Rolls back the last n entries of this journal.
      (package private) void setCommitID​(long commit_id)
      Sets the 'commit_id'.
      (package private) void testCommitClash​(DataTableDef table_def, MasterTableJournal journal)
      Throws a transaction clash exception if it detects a clash between journal entries.
      java.lang.String toString()
      Debugging.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • commit_id

        private long commit_id
        The commit id given to this change when it is committed. This is only set when the journal is a committed change to the database.
      • table_id

        private int table_id
        The master table id.
      • journal_entries

        private int journal_entries
        The number of entries in this journal.
      • command_journal

        private byte[] command_journal
        A byte[] array that represents the set of commands a transaction performed on this table.
      • command_parameters

        private IntegerVector command_parameters
        An IntegerVector that is filled with parameters from the command journal. For example, a 'TABLE_ADD' journal log will have as parameters the row_index that was added to this table.
    • Constructor Detail

      • MasterTableJournal

        MasterTableJournal​(int table_id)
        Constructs the master table journal.
      • MasterTableJournal

        MasterTableJournal()
    • Method Detail

      • setCommitID

        void setCommitID​(long commit_id)
        Sets the 'commit_id'. This is only set when this change becomes a committed change to the database.
      • isAddCommand

        static boolean isAddCommand​(byte command)
        Returns true if the given command is an addition command.
      • isRemoveCommand

        static boolean isRemoveCommand​(byte command)
        Returns true if the given command is a removal command.
      • addCommand

        private void addCommand​(byte command)
        Adds a command to the journal.
      • addParameter

        private void addParameter​(int param)
        Adds a parameter to the journal command parameters.
      • removeTopEntries

        private void removeTopEntries​(int n)
        Removes the top n entries from the journal.
      • addEntry

        void addEntry​(byte command,
                      int row_index)
        Adds a new command to this journal.
      • getCommitID

        long getCommitID()
        Returns the commit_id that has been set for this journal.
      • getTableID

        int getTableID()
        Returns the table id of the master table this journal is for.
      • entries

        int entries()
        Returns the total number of journal entries.
      • getCommand

        byte getCommand​(int n)
        Returns the command of the nth entry in the journal.
      • getRowIndex

        int getRowIndex​(int n)
        Returns the row index of the nth entry in the journal.
      • normalizedAddedRows

        int[] normalizedAddedRows()
        Returns a normalized list of all rows that were added in this journal, but not including those rows also removed. For example, if rows 1, 2, and 3 were added and 2 was removed, this will return a list of 1 and 3.
      • normalizedRemovedRows

        int[] normalizedRemovedRows()
        Returns a normalized list of all rows that were removed from this journal.
      • allChangeInformation

        IntegerVector[] allChangeInformation()
        Returns three lists - a list of all rows that were inserted, a list of all rows that were deleted, and a list of all updates. All the lists are ordered by the order of the command. The update list contains two entries per 'update', the row that was removed and the row that was added with the updated info.

        This method is useful for collecting all modification information on the table.

      • rollbackEntries

        void rollbackEntries​(int n)
        Rolls back the last n entries of this journal. This method takes into account the transient nature of rows (all added rows in the journal are exclusively referenced by this journal). The algorithm works as follows; any rows added are deleted, and rows deleted (that weren't added) are removed from the journal.
      • testCommitClash

        void testCommitClash​(DataTableDef table_def,
                             MasterTableJournal journal)
                      throws TransactionException
        Throws a transaction clash exception if it detects a clash between journal entries. It assumes that this journal is the journal that is attempting to be compatible with the given journal. A journal clashes when they both contain a row that is deleted.
        Throws:
        TransactionException
      • readFrom

        void readFrom​(java.io.DataInputStream din)
               throws java.io.IOException
        Reads the journal entries from the given DataInputStream to this object.

        This method is only around because we might need it to convert a 0.91 era database that stored index data as journals in the file system.

        Throws:
        java.io.IOException
      • toString

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