Class OnDiskArrayPageFile<P extends Page>

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

    public class OnDiskArrayPageFile<P extends Page>
    extends AbstractStoringPageFile<P>
    A OnDiskArrayPageFile 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
    • Field Detail

      • LOG

        private static final Logging LOG
        Class 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
      • filename

        private java.nio.file.Path filename
        The file name to use
      • file

        private OnDiskArray file
        The file storing the pages.
      • header

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

        private final boolean existed
        Whether or not the file originally existed
    • Constructor Detail

      • OnDiskArrayPageFile

        public OnDiskArrayPageFile​(int pageSize,
                                   java.nio.file.Path filename)
        Creates a new OnDiskArrayPageFile from an existing file.
        Parameters:
        pageSize - page size
        filename - the name of the file
    • 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)
        Write page to disk.
        Specified by:
        writePage in class AbstractPageFile<P extends Page>
        Parameters:
        pageID - page id
        page - the page which has to be written to disk
      • clear

        public void clear()
        Clears this PageFile.
      • byteBufferToPage

        private P byteBufferToPage​(java.nio.ByteBuffer buffer)
        Reconstruct a serialized object from the specified byte array.
        Parameters:
        buffer - the buffer 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