jhplot.io
Class HDataBase

java.lang.Object
  extended by jhplot.io.HDataBase

public class HDataBase
extends java.lang.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


Field Summary
 RecordsFile recordsFile
           
 RecordReader rr
           
 RecordWriter rw
           
 
Constructor Summary
HDataBase(java.lang.String file)
          Open the database file for reading.
HDataBase(java.lang.String file, java.lang.String option)
          Create a new persistent database.
 
Method Summary
 boolean close()
          Close the file
 java.lang.Object get(java.lang.String key)
          Get object from the database using a key
 java.util.Enumeration getKeys()
          Returns an enumeration of all the keys in the database.
 int getRecords()
          Returns the current number of records in the database.
 boolean insert(java.lang.String key, java.lang.Object obj)
          Insert an object with a key
 boolean isExists(java.lang.String key)
          Checks if there is a record belonging to the given key.
 boolean remove(java.lang.String key)
          Remove object from the database using the key
 boolean update(java.lang.Object ob, java.lang.String key)
          Update the database with a new value
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

recordsFile

public RecordsFile recordsFile

rw

public RecordWriter rw

rr

public RecordReader rr
Constructor Detail

HDataBase

public HDataBase(java.lang.String file,
                 java.lang.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(java.lang.String file)
Open the database file for reading.

Parameters:
file - File name
Method Detail

getKeys

public java.util.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(java.lang.String key)
Checks if there is a record belonging to the given key.


insert

public boolean insert(java.lang.String key,
                      java.lang.Object obj)
Insert an object with a key

Parameters:
key - key for object
obj - Object for this key
Returns:
true if success

get

public java.lang.Object get(java.lang.String key)
Get object from the database using a key

Parameters:
key - Key to get the object
Returns:
Object

update

public boolean update(java.lang.Object ob,
                      java.lang.String key)
Update the database with a new value

Parameters:
ob - Object
key - key
Returns:
true if success

remove

public boolean remove(java.lang.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:


jHepWork 2.1 (C) S.Chekanov