PJODe

The PersonalJava ODBMS

com.linxpda.PJODe
Class PJODe

java.lang.Object
  |
  +--com.linxpda.PJODe.PJODe

public class PJODe
extends java.lang.Object

This class is the access point for users to the com.linxpda.PJODe ODBMS system. A typical session would go like this:

 Person paul = new Person("Male", 16, 68, 150);
	try {
		PJODe db = new PJODe("test.db", 64);
		// NOTE: The class Person must implement java.io.Serializable
		//       and should override the equals(Object) method
		//       to ensure proper comparison to another Person.
		db.set(paul);
		db.close();
	}
	catch(IOException ioe) {
		//Handle IO errors here..
	}
	catch(DBException rfe) {
		//Handle DB errors here..
	}
	Person query = new Person("Male");
	try {
		PJODe db = new PJODe("test.db", "rw");
		ResultSet results = db.get(query);
		if (! results.isEmpty()) {
			for (int i = 0; i < results.getObjectCount(); i++) {
				System.out.println(results.getObjectAt(i).toString());
			}
		}
	}
	catch(IOException ioe) {
		//IO Error handling here..
	}
	catch(DBException rfe) {
		//DB Error handling here..
	}
	


Constructor Summary
PJODe(java.lang.String dbPath)
          Initializes an PJODe with the default permissions and capacity.
PJODe(java.lang.String dbPath, int initialCapacity)
          Initializes an PJODe with the requested initial capacity and default permissions of "rw".
PJODe(java.lang.String dbPath, java.lang.String access)
          Open an existing PJODe with the requested access permissions.
 
Method Summary
 void close()
          Defragments the database file and closes all connected streams.
 ResultSet get(java.lang.Object query)
          Reads all objects from the datafile and compares them to the supplied query object through a call to equals().
 void remove(java.lang.Object object)
          Deletes the specified object from the data file.
 void set(java.lang.Object object)
          Add (or updates) the object into the persistent file.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PJODe

public PJODe(java.lang.String dbPath)
      throws java.io.IOException,
             DBException
Initializes an PJODe with the default permissions and capacity. The initial capacity is set to 64 and the permissions set to "rw".
Parameters:
dbPath - The relative or absolute path for the database file. If this path points to an existing file, then it is opened, if it does not, then a new file is created.
Throws:
java.io.IOException - For typical file I/O errors
DBException - upon an database specific error.

PJODe

public PJODe(java.lang.String dbPath,
             int initialCapacity)
      throws java.io.IOException,
             DBException
Initializes an PJODe with the requested initial capacity and default permissions of "rw".
Parameters:
dbPath - The relative or absolute path for the database file. If this path points to an existing file, then it is opened, if it does not, then a new file is created.
initialCapacity - The initial capacity (in bytes) for the database. The database file will be created with this capacity and increased by this amount anytime new memory space needs to be made available.
Throws:
java.io.IOException - For typical file I/O errors
DBException - upon an database specific error.

PJODe

public PJODe(java.lang.String dbPath,
             java.lang.String access)
      throws java.io.IOException,
             DBException
Open an existing PJODe with the requested access permissions.
Parameters:
dbPath - The relative or absolute path for the database file. If this path points to an existing file, then it is opened, if it does not, then a new file is created.
access - The access flags for permission setting. Can be "r" for read-only, "w" for write only or "rw" for read and write permissions.
Throws:
java.io.IOException - For typical file I/O errors
DBException - upon an database specific error.
Method Detail

set

public void set(java.lang.Object object)
         throws java.io.IOException,
                DBException
Add (or updates) the object into the persistent file.
Parameters:
Object - The object to add (or update) in the database. This object must implement the java.io.Serializable interface and may override the equals() method to better define how it compares itself to other objects.
Throws:
java.io.IOException - For typical file I/O errors
DBException - upon an database specific error.

get

public ResultSet get(java.lang.Object query)
              throws java.io.IOException,
                     java.io.OptionalDataException,
                     java.lang.ClassNotFoundException,
                     DBException
Reads all objects from the datafile and compares them to the supplied query object through a call to equals(). Custom classes should overload the equals() method inherited from Object to ensure proper comparison. Passing null as an argument here will return all objects in the database.
Parameters:
Object - The template to use for the query. All objects in the database will be compared to this object's equals() method to determine if it should be added to the resulting ResultSet.
Returns:
A ResultSet object that contains all the objects that tested true to object.equals(query).
Throws:
java.io.IOException - For typical file I/O errors
DBException - upon an database specific error.

remove

public void remove(java.lang.Object object)
            throws java.io.IOException,
                   DBException
Deletes the specified object from the data file.
Parameters:
object - The object to delete.
Throws:
java.io.IOException - For typical file I/O errors
DBException - upon an database specific error.

close

public void close()
           throws java.io.IOException,
                  DBException
Defragments the database file and closes all connected streams.
Throws:
java.io.IOException - For typical file I/O errors
DBException - upon an database specific error.

(c)2001 Linxpda, Inc. www.linxpda.com