net.aerith.misao.database
Class PrimitiveFileManager

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

public class PrimitiveFileManager
extends PrimitiveManager

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

The elements are stored in 1.xml, 2.xml, ..., Each XML file contains some elements and restricted not to be much larger than the specified limit of file size.


Field Summary
protected  int limit_filesize
          The limit of one XML file (50KB).
protected  java.io.File path
          The folder of the database.
 
Fields inherited from class net.aerith.misao.database.PrimitiveManager
holder_class, record_class
 
Constructor Summary
PrimitiveFileManager(java.io.File path, XmlDBHolder holder_class, XmlDBRecord record_class)
          Constructs a PrimitiveFileManager 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.
 int getLimitFileSize()
          Gets the limit of one XML file.
 java.io.File getPath()
          Gets the folder path.
 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

path

protected java.io.File path
The folder of the database.

limit_filesize

protected int limit_filesize
The limit of one XML file (50KB).
Constructor Detail

PrimitiveFileManager

public PrimitiveFileManager(java.io.File path,
                            XmlDBHolder holder_class,
                            XmlDBRecord record_class)
                     throws java.io.IOException
Constructs a PrimitiveFileManager in the specified folder, which consists of the XML elements of the specified class.
Parameters:
path - the folder to create the database.
holder_class - the holder class object of the XML records.
record_class - the class object of the XML records.
Throws:
java.io.IOException - if I/O error occurs.
Method Detail

getPath

public java.io.File getPath()
Gets the folder path.
Returns:
the folder path.

getLimitFileSize

public int getLimitFileSize()
Gets the limit of one XML file.
Returns:
the limit of one XML file.

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.