HDataBase
jhplot.io

Class HDataBase



  • public class HDataBaseextends Object
    This raw-level database allows to store and retrieve objects. It associates a key of type String with each record. The keys will be limited to a maximum length, although the record data will not be limited. The record will consist of only one "blob" of binary data. The number of records is not fixed at creation time. The file can grow and shrink as records are inserted and removed. Because our index and record data will be stored in the same file, this restriction will cause us to add extra logic to dynamically increase the index space by reorganizing records. The database operations not depend on the number of records in the file. In other words, they'll be of constant order time with respect to file accesses. The index is small enough to load into memory. This will make it easier for our implementation to fulfill the requirement that dictates access time. The code is based on: http://www.javaworld.com/javaworld/jw-01-1999/jw-01-step.html
    • Constructor Detail

      • HDataBase

        public HDataBase(String file,         String option)
        Create a new persistent database. If file exists, and the option "w" is set, the old file will be removed!
        Parameters:
        file - File name
        option - Option to create the file . If "w" - write a file (or read) file, if "r" only read created file.
      • HDataBase

        public HDataBase(String file)
        Open the database file for reading.
        Parameters:
        file - File name
    • Method Detail

      • getKeys

        public Enumeration getKeys()
        Returns an enumeration of all the keys in the database.
      • getRecords

        public int getRecords()
        Returns the current number of records in the database.
      • isExists

        public boolean isExists(String key)
        Checks if there is a record belonging to the given key.
      • insert

        public boolean insert(String key,             Object obj)
        Insert an object with a key
        Parameters:
        key - key for object
        obj - Object for this key
        Returns:
        true if success
      • get

        public Object get(String key)
        Get object from the database using a key
        Parameters:
        key - Key to get the object
        Returns:
        Object
      • update

        public boolean update(Object ob,             String key)
        Update the database with a new value
        Parameters:
        ob - Object
        key - key
        Returns:
        true if success
      • remove

        public boolean remove(String key)
        Remove object from the database using the key
        Parameters:
        key - input key
        Returns:
        true if success
      • close

        public boolean close()
        Close the file
        Returns:

SCaVis 1.7 © jWork.org