Class HeaderPage


  • public class HeaderPage
    extends java.lang.Object

    This class contains constants and basic functionality for accessing and manipulating the contents of the header page of a heap table-file. Note that the first two bytes of the first page is always devoted to the type and page-size of the data file. (See DBFile for details.) All other values must follow the first two bytes.

    Heap table-file header pages are laid out as follows:

    • As with all DBFiles, the first two bytes are the file type and page size, as always.
    • After this come several values specifying the sizes of various areas in the header page, including the size of the table's schema specification, the statistics for the table, and the number of columns.
    • Next the table's schema is recorded in the header page. See the SchemaWriter class for details on how a table's schema is stored.
    • Finally, the table's statistics are stored. See the StatsWriter class for details on how a table's statistics are stored.

    Even with all this information, usually only a few hundred bytes are required for storing the details of most tables.

    Design Note:
    (Donnie) Why is this class a static class, instead of a wrapper class around the DBPage? No particular reason, really. The class is used relatively briefly when a table is being accessed, and there is no real need for it to manage its own object-state, so it was just as convenient to provide all functionality as static methods. This avoids the (small) overhead of instantiating an object as well. But really, these are not particularly strong reasons.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static org.apache.logging.log4j.Logger logger
      A logging object for reporting anything interesting that happens.
      static int OFFSET_SCHEMA_SIZE
      The offset in the header page where the size of the table schema is stored.
      static int OFFSET_SCHEMA_START
      The offset in the header page where the table schema starts.
      static int OFFSET_STATS_SIZE
      The offset in the header page where the size of the table statistics are stored.
    • Constructor Summary

      Constructors 
      Constructor Description
      HeaderPage()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int getSchemaSize​(DBPage dbPage)
      Returns the number of bytes that the table's schema occupies for storage in the header page.
      static int getStatsOffset​(DBPage dbPage)
      Returns the offset in the header page that the table statistics start at.
      static int getStatsSize​(DBPage dbPage)
      Returns the number of bytes that the table's statistics occupy for storage in the header page.
      static void setSchemaSize​(DBPage dbPage, int numBytes)
      Sets the number of bytes that the table's schema occupies for storage in the header page.
      static void setStatsSize​(DBPage dbPage, int numBytes)
      Sets the number of bytes that the table's statistics occupy for storage in the header page.
      private static void verifyIsHeaderPage​(DBPage dbPage)
      This helper method simply verifies that the data page provided to the HeaderPage class is in fact a header-page (i.e.
      • Methods inherited from class java.lang.Object

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

      • logger

        private static org.apache.logging.log4j.Logger logger
        A logging object for reporting anything interesting that happens.
      • OFFSET_SCHEMA_SIZE

        public static final int OFFSET_SCHEMA_SIZE
        The offset in the header page where the size of the table schema is stored. This value is an unsigned short.
        See Also:
        Constant Field Values
      • OFFSET_STATS_SIZE

        public static final int OFFSET_STATS_SIZE
        The offset in the header page where the size of the table statistics are stored. This value is an unsigned short.
        See Also:
        Constant Field Values
      • OFFSET_SCHEMA_START

        public static final int OFFSET_SCHEMA_START
        The offset in the header page where the table schema starts. This value is an unsigned short.
        See Also:
        Constant Field Values
    • Constructor Detail

      • HeaderPage

        public HeaderPage()
    • Method Detail

      • verifyIsHeaderPage

        private static void verifyIsHeaderPage​(DBPage dbPage)
        This helper method simply verifies that the data page provided to the HeaderPage class is in fact a header-page (i.e. page 0 in the data file).
        Parameters:
        dbPage - the page to check
        Throws:
        java.lang.IllegalArgumentException - if dbPage is null, or if it's not actually page 0 in the table file
      • getSchemaSize

        public static int getSchemaSize​(DBPage dbPage)
        Returns the number of bytes that the table's schema occupies for storage in the header page.
        Parameters:
        dbPage - the header page of the heap table file
        Returns:
        the number of bytes that the table's schema occupies
      • setSchemaSize

        public static void setSchemaSize​(DBPage dbPage,
                                         int numBytes)
        Sets the number of bytes that the table's schema occupies for storage in the header page.
        Parameters:
        dbPage - the header page of the heap table file
        numBytes - the number of bytes that the table's schema occupies
      • getStatsSize

        public static int getStatsSize​(DBPage dbPage)
        Returns the number of bytes that the table's statistics occupy for storage in the header page.
        Parameters:
        dbPage - the header page of the heap table file
        Returns:
        the number of bytes that the table's statistics occupy
      • setStatsSize

        public static void setStatsSize​(DBPage dbPage,
                                        int numBytes)
        Sets the number of bytes that the table's statistics occupy for storage in the header page.
        Parameters:
        dbPage - the header page of the heap table file
        numBytes - the number of bytes that the table's statistics occupy
      • getStatsOffset

        public static int getStatsOffset​(DBPage dbPage)
        Returns the offset in the header page that the table statistics start at. This value changes because the table schema resides before the stats, and therefore the stats don't live at a fixed location.
        Parameters:
        dbPage - the header page of the heap table file
        Returns:
        the offset within the header page that the table statistics reside at