db4o - persistence made easy
There has been an announcement recently that the db4o database has gone opensource. Db4o? Heard about it, visited the website years ago, remember it looked nice....
The download is small, even smaller is the jar: 320kb - nothing more is needed.
Checking it out reveals really cool features. All kinds of persistence I've seen so far needed some kind of prerequisites to be taken: special base classes, enhancements, mapping scripts, precompilers or even hand-crafted read/write code. At least some DB initialisation. Nothing of that in db4o. Take any object, present it to the database and consider it persisted. It's really that easy:
ObjectContainer db = Db4o.openFile("myDB");
MyObject o = new MyObject( "Hello", "World" );
db.set( o );
Retrieving is not more difficult:
query.constrain( MyObject.class );
ObjectSet result = query.execute();
System.out.println( result.next() );
For now, I didn't dig very deep. Updating and deleting is easy as well. For it is a database, there are query APIs implementing QBE and S.O.D.A.. This is everything I need and maybe already more than I can handle :). The magic words 'transaction' and 'client/server' also show up in the tutorial, so I suppose I will not be left alone when it gets more complex.
The database itself is just a plain, very small file. If you are looking for a truely lightweight persister and can live with the GPL, give it a try. It's so light that it makes sense to replace even property files with db4o.