Below are details and examples on using PJODeCS in both single-user and client/server modes.
Connecting to a database file
Connections to a PJODe database are obtained by creating an instance of PJODe through any of it's public constructors. Once an instance is created, the database is ready for data manipulation:/** * Connect to database 'test.db' */ PJODe db = new PJODe("test.db"); System.out.println("Ready for data manipulation");
Adding objects to the database
Adding objects to a PJODe database is done through calls to {@link com.linxpda.PJODe.PJODe#set(Object) set(Object)}. This method performs add and update features automatically. Objects in PJODe are referenced through an integer ID number that is unique to each object added. Therefore if the same instance of an object is added to the database, it overwrites the current instance. There is no need for an update method:/** * Add an object to our database.. */ Person person1 = new Person("Tom Cole", "tcole@eclipsetel.com"); db.add(person1); System.out.println("Added person1");
Removing objects from the database
Removing objects from PJODe is done through calls to {@link com.linxpda.PJODe.PJODe#remove(Object) remove(Object)}. As with the add method, the same instance of Object, as determined by it's ID number, will be removed from the database:/** * Remove persone1 from our database... */ db.remove(person1); System.out.println("person1 removed.");
Retrieving objects from the database
Retrieving objects from PJODe is done through a user defined query-by-example method. This definition occurs in the class's equals(Object) method. User defined classes may override this method to provide custom comparisons to other instances of the same object for determination of equality. In our person example (which will have only two fields, name and email) we will assume that any occurence of a string within a query field will be considered equals (as defined by String.indexOf(String)) and any fields that are null should be ignored and considered not essential in determing equality:/** * Person class that defines custom query capabilities.. */ import java.io.Serializable; public class Person implements Serializable { protected String name; protected String email; public Person(String name, String email) { this.name = name; this.email = email; } public String toString() { return name + ", " + email; } public boolean equals(Object query) { if (query instanceof Person) { Person p = (Person) query; if (! p.name == null) { if (name.indexOf(p.name) < )) return false; } if (! p.email == null) { if (email.indexOf(p.email) < 0) return false; } return true; } else { return false; } } }Once we have a custom class defined, we create a query instance of Person to find anyone who has "Tom" in their name field:
Person query = new Person("Tom", null);Now we call {@link com.linxpda.PJODe.PJODe#get(Object) get(Object)} passing it the query object. The results of a search are returned in an instance of {@link com.linxpda.PJODe.ResultSet ResultSet} which provides a simple API for navigating through a collection of Objects:/** * Get all people with "Tom" in their names. * Email is irrelevant. */ ResultSet results = db.get(query); System.out.println("Found " + results.getObjectCount() + " instances."); for (int i = 0; i < results.getObjectCount(); i++) { System.out.println(" " + results.getObjectAt(i).toString()); }Passing a null to get will return all objects in the database.
Closing a database
Now we're ready to close the database. Note that all transactions are performed in real-time so we do not need to close a db to commit data updates. This method simply closes any remote or local connections to the databae file./** * Close the database... */ db.close(); db = null;That's it!
java com.linxpda.PJODe.server.PJODeRMIServer <remote_name> <port>
The above would bind a PJODeRMIServer with the name "remote_name" listening on
port "port".
If you have any questions or difficulties in using PJODe, please contact us
at support@linxpda.com
Starting the PJODeRMIServer
NOTE: You need only start one PJODeRMIServer to access any and all PJODe databases
on the remote system.
Obtain Remote Instance of PJODe