|
PJODeThe PersonalJava ODBMS |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.linxpda.PJODe.PJODe
This class is the access point for users to the com.linxpda.PJODe ODBMS system. A typical single-user 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.. }For a multi-user client/server session simply replace the PJODe constructor with a call to the static method getRemoteInstance(String filename, String url), which connects a remote PJODe at location 'url' to the database 'filename'. All other code remains exactly the same.
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(). |
static PJODe |
getRemoteInstance(java.lang.String filename,
java.lang.String url)
Renturns an instance of PJODe that is connected to a remote PJODeRMIServer
for thread-safe client/user access. |
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 |
public PJODe(java.lang.String dbPath) throws java.io.IOException, DBException
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.java.io.IOException
- For typical file I/O errorsDBException
- upon an database specific error.public PJODe(java.lang.String dbPath, int initialCapacity) throws java.io.IOException, DBException
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.java.io.IOException
- For typical file I/O errorsDBException
- upon an database specific error.public PJODe(java.lang.String dbPath, java.lang.String access) throws java.io.IOException, DBException
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.java.io.IOException
- For typical file I/O errorsDBException
- upon an database specific error.Method Detail |
public static PJODe getRemoteInstance(java.lang.String filename, java.lang.String url) throws java.io.IOException, DBException, java.rmi.RemoteException, java.rmi.NotBoundException
PJODeRMIServer
for thread-safe client/user access.filename
- The filename to create or open on the
remote filesystem.url
- The URL encoded location for the PJODeRMIServer. Must
be in the form '//IPAddress:port/remote_name' as defined
in the java.rmi bootstrap whitepapers.java.rmi.RemoteException
- If there is a connection error between the
remote server and this class.java.rmi.NotBoundException
- If the server has not been bound or cannot be found
at the specified URL.DBException
- If there is an access violation creating or opening the
requested database file.java.io.IOException
- Upon a file read/write error.public void set(java.lang.Object object) throws java.io.IOException, DBException
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.java.io.IOException
- For typical file I/O errorsDBException
- upon an database specific error.public ResultSet get(java.lang.Object query) throws java.io.IOException, java.io.OptionalDataException, java.lang.ClassNotFoundException, DBException
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.ResultSet
object that contains all the objects that tested true to
object.equals(query).java.io.IOException
- For typical file I/O errorsDBException
- upon an database specific error.public void remove(java.lang.Object object) throws java.io.IOException, DBException
object
- The object to delete.java.io.IOException
- For typical file I/O errorsDBException
- upon an database specific error.public void close() throws java.io.IOException, DBException
java.io.IOException
- For typical file I/O errorsDBException
- upon an database specific error.
|
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |