Thursday, December 13, 2007

db4o

Summary
  • useful alternative to MySQL for small and embedded environments
  • overcomes object-relational impedance mismatch problems
  • object primary key is its OID (Object Identifier) which is auto-generated
  • uses Query by Example (QBE) to select by comparison against a prototype object
  • use of SODA (Simple Object Database Access) and native queries for efficiency
  • copes with object refactoring e.g. adding/removing fields, primitive type conversion, class rename
  • data is typically stored in files which can be encrypted using eXtended Tiny Encryption Algorithm (XTEA) or 3rd party hook-ins
  • duplicate objects can be stored in the same table
  • data is unaccessible from unsupported languages e.g. non Java or .NET code

Key Classes

  • ObjectContainer - interface to db4o database
  • ObjectSet - query resultset, list of items
  • Db4o - factory class for database engine utilities
  • ExtObjectContainer - volatile experimental methods

Key Methods

  • Db4o.openFile(String fileName) - open the database
  • objectContainer.set(Object obj) - INSERT the object into the database
  • objectContainer.get(Object obj) - SELECT the matching objects from the database
  • objectContainer.delete(Object obj) - DELETE the object from the database
  • objectContainer.commit() - commit the transaction
  • objectSet.next() - iterate through the result set
  • objectContainer.ext().getID(Object obj) - get the OID for the object
  • objectContainer.ext().getByID(long ID) - get the object by the ID
  • Db4o.configure().objectClass("com.gth.org.uk.Person").rename("com.org.uk.Individual") - refactor class name
  • Db4o.configure().activationDepth(int depth) - change the default activation depth to avoid infinite recursion

Alternative OODBMS

Source: The busy Java developer's guide to db4o

2 comments:

olivier said...

Hello,

Another Object Oriented alternative to Db4o is NeoDatis ODB (odb.neodatis.org). NeoDatis is open source too and uses the LGPL license. So it can be used in commercial app.

Gareth Thomas Hill said...

Thanks for the suggestion - I have added it to the post :-)