<< back to johnspurlock.com

projects/java
   ProjectGhostData
     dist
     src
   ProjectRevere
     dist
     src
   ProjectUtil
     dist
     src
   lib
     cloudscape
     commons-httpclient
     commons-lang
     commons-logging
     hsqldb
     informa
     jaf
     jaimlib
     javamail
     jdom
     jgmail
     junit
     mssql
     postgresql
     smtpmailer
     soap
     swt
     timer
     xerces
     xstream
john spurlock 2008
ProjectGhostData



A basic framework for object persistence.











Description:

This is meant to be a simple mechanism for storing regular java objects to (and retrieving them from) a "datastore". Some features:

  • Very few lines of code to persist regular java domain objects.
  • Underlying storage details of the datastore are completely hidden (no JDBC needed to persist to a SQL database).
  • No object-level xml mapping documents (doing my part to cut down on xml overload...)
  • Object transformations are basic java constructs, no reflection or runtime trickery.
  • Zero-impact on the existing domain objects, the persistence can be completely separate if necessary.
  • Rudimentary query language to limit results

To make an existing object persistable, you write two proxy classes: the proxy to put a simple java object into a datastore is the IFieldProvider, and the proxy to pull an object out of a datastore is the IObjectBuilder.

(Domain Object) -> (IFieldProvider) -> (IDatastore)

(Domain Object) <- (IObjectBuilder) <- (IDatastore)

There are five tested sql datastore implementations included, for Postgres, Hsql, Cloudscape, Microsoft Sql Server & Access.

Example:

     Album album = whatever.getAlbum();
     
     
     // define the datastore, in this case it is a sql server database
     IDatastore datastore = GhostDataMinistry.getDatastore("mssql|servername|instancename|databasename|username|password");
     
     
     // store the album
     datastore.add(album.new DefaultFieldProvider());
     
     
     // retrieve a list of albums using a query
     List results = datastore.getObjects(new Album.DefaultObjectBuilder(),"where artist = 'Wilco'");
     
     // retrieve a single album
     Album album123 = (Album)datastore.getObjects(new Album.DefaultObjectBuilder(),"where artist = 'Wilco' and album='A ghost is born'");