net.aerith.misao.database
Class PrimitiveMemoryManager

java.lang.Object
  |
  +--net.aerith.misao.database.PrimitiveManager
        |
        +--net.aerith.misao.database.PrimitiveMemoryManager

public class PrimitiveMemoryManager
extends PrimitiveManager

The PrimitiveMemoryManager represents a database manager which covers one folder containing XML elements of the same type.

The elements are kept on memory and stored in the hash table. In fact, only one holder of the XML elements is stored in the hash table.


Field Summary
protected  java.util.Hashtable hash_folder
          The hash table of the folder.
protected  XmlDBHolder holder
          The holder of the XML element.
protected static java.lang.String holder_key
          The key of the hash table to access to the holder.
 
Fields inherited from class net.aerith.misao.database.PrimitiveManager
holder_class, record_class
 
Constructor Summary
PrimitiveMemoryManager(java.util.Hashtable hash_folder, XmlDBHolder holder_class, XmlDBRecord record_class)
          Constructs a PrimitiveMemoryManager in the specified folder, which consists of the XML elements of the specified class.
 
Method Summary
 void addElement(XmlDBRecord element)
          Adds the specified XML element into the database.
 void addElements(java.util.Vector list)
          Adds the XML elements in the specified list into the database.
 XmlDBRecord deleteElement(java.lang.String id)
          Deletes the element of the specified ID.
 void deleteElements(java.util.Hashtable hash)
          Deletes the elements in the specified hash table.
 XmlDBAccessor getAccessor()
          Gets the sequential accessor to the elements in the database.
 XmlDBHolder getHolder()
          Gets the holder of the XML elements.
 XmlDBRecord setElement(XmlDBRecord element)
          Adds or updates the specified XML element into the database.
 
Methods inherited from class net.aerith.misao.database.PrimitiveManager
createHolder, getElement
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

hash_folder

protected java.util.Hashtable hash_folder
The hash table of the folder.

holder

protected XmlDBHolder holder
The holder of the XML element.

holder_key

protected static final java.lang.String holder_key
The key of the hash table to access to the holder.
Constructor Detail

PrimitiveMemoryManager

public PrimitiveMemoryManager(java.util.Hashtable hash_folder,
                              XmlDBHolder holder_class,
                              XmlDBRecord record_class)
Constructs a PrimitiveMemoryManager in the specified folder, which consists of the XML elements of the specified class.
Parameters:
hash_folder - the hash table of the folder.
holder_class - the holder class object of the XML records.
record_class - the class object of the XML records.
Method Detail

getHolder

public XmlDBHolder getHolder()
Gets the holder of the XML elements.
Returns:
the holder of the XML elements.

addElement

public void addElement(XmlDBRecord element)
                throws java.io.IOException
Adds the specified XML element into the database.
Overrides:
addElement in class PrimitiveManager
Parameters:
element - the XML element.
Throws:
java.io.IOException - if I/O error occurs.

addElements

public void addElements(java.util.Vector list)
                 throws java.io.IOException
Adds the XML elements in the specified list into the database. All elements in the list are saved in one new XML file. Because the total file size is uncertain, the limitation of the size of an XML file does not work when using this method.
Overrides:
addElements in class PrimitiveManager
Parameters:
list - the list of XML elements.
Throws:
java.io.IOException - if I/O error occurs.

setElement

public XmlDBRecord setElement(XmlDBRecord element)
                       throws java.io.IOException
Adds or updates the specified XML element into the database. It checks if the element whose ID is the same as the specified element already exists or not. When it does, the data is updated. Otherwise, the element is newly added.
Overrides:
setElement in class PrimitiveManager
Parameters:
element - the XML element.
Returns:
the old XML element if the element of the specified ID already exists, or null.
Throws:
java.io.IOException - if I/O error occurs.

deleteElement

public XmlDBRecord deleteElement(java.lang.String id)
                          throws java.io.IOException
Deletes the element of the specified ID.
Overrides:
deleteElement in class PrimitiveManager
Parameters:
id - the ID.
Returns:
the deleted XML element, or null if the element of the specified ID does not exist.
Throws:
java.io.IOException - if I/O error occurs.

deleteElements

public void deleteElements(java.util.Hashtable hash)
                    throws java.io.IOException
Deletes the elements in the specified hash table. After the operation, some of the elements in the specified hash table are deleted, which are in this database. Others are remained. The IDs of the deleted elements are also deleted from the hash table.
Overrides:
deleteElements in class PrimitiveManager
Parameters:
hash - the hash table whose keys are IDs of the elements to be deleted.
Throws:
java.io.IOException - if I/O error occurs.

getAccessor

public XmlDBAccessor getAccessor()
Gets the sequential accessor to the elements in the database.
Overrides:
getAccessor in class PrimitiveManager
Returns:
the sequential accessor.