Class PersistentPageFile<P extends ExternalizablePage>

  • Type Parameters:
    P - Page type
    All Implemented Interfaces:
    PageFile<P>

    public class PersistentPageFile<P extends ExternalizablePage>
    extends AbstractStoringPageFile<P>
    A PersistentPageFile stores objects persistently that implement the Page interface. For convenience each page is represented by a single file. All pages are stored in a specified directory.
    Since:
    0.1
    Author:
    Elke Achtert
    • Constructor Summary

      Constructors 
      Constructor Description
      PersistentPageFile​(int pageSize, java.nio.file.Path filename, java.lang.Class<P> pageclass)
      Creates a new PersistentPageFile from an existing file.
    • Field Detail

      • LOG

        private static final Logging LOG
        Our logger
      • EMPTY_PAGE

        private static final int EMPTY_PAGE
        Indicates an empty page.
        See Also:
        Constant Field Values
      • FILLED_PAGE

        private static final int FILLED_PAGE
        Indicates a filled page.
        See Also:
        Constant Field Values
      • file

        private final java.nio.channels.FileChannel file
        The file storing the pages.
      • header

        protected PageHeader header
        The header of this page file.
      • pageclass

        protected final java.lang.Class<P extends ExternalizablePage> pageclass
        The type of pages we use.
      • existed

        private boolean existed
        Whether we are initializing from an existing file.
    • Constructor Detail

      • PersistentPageFile

        public PersistentPageFile​(int pageSize,
                                  java.nio.file.Path filename,
                                  java.lang.Class<P> pageclass)
        Creates a new PersistentPageFile from an existing file.
        Parameters:
        pageSize - the page size
        pageclass - the class of pages to be used
    • Method Detail

      • readPage

        public P readPage​(int pageID)
        Reads the page with the given id from this file.
        Parameters:
        pageID - the id of the page to be returned
        Returns:
        the page with the given pageId
      • writePage

        public void writePage​(int pageID,
                              P page)
        This method is called by the cache if the page is not longer stored in the cache and has to be written to disk.
        Specified by:
        writePage in class AbstractPageFile<P extends ExternalizablePage>
        Parameters:
        page - the page which has to be written to disk
        pageID - Page id
      • clear

        public void clear()
        Clears this PageFile.
      • byteArrayToPage

        private P byteArrayToPage​(byte[] array)
        Reconstruct a serialized object from the specified byte array.
        Parameters:
        array - the byte array from which the object should be reconstructed
        Returns:
        a serialized object from the specified byte array
      • pageToByteArray

        private byte[] pageToByteArray​(P page)
        Serializes an object into a byte array.
        Parameters:
        page - the object to be serialized
        Returns:
        the byte array
      • getFile

        public java.nio.channels.FileChannel getFile()
        Returns:
        the random access file storing the pages.
      • getHeader

        public PageHeader getHeader()
        Get the header of this persistent page file.
        Returns:
        the header used by this page file
      • setNextPageID

        public void setNextPageID​(int next_page_id)
        Set the next page id to the given value. If this means that any page ids stored in emptyPages are smaller than next_page_id, they are removed from this file's observation stack.
        Specified by:
        setNextPageID in interface PageFile<P extends ExternalizablePage>
        Overrides:
        setNextPageID in class AbstractStoringPageFile<P extends ExternalizablePage>
        Parameters:
        next_page_id - the id of the next page to be inserted (if there are no more empty pages to be filled)