September 01, 2002

More db4o experiences

All is not 100% rosy with db4o. Their retrieval mechanism uses query-by-example, which I actually dislike quite a bit in the abstract. After you use it and reach the “yeah, I get it” stage, it’s too basic and has a low utility ceiling. Plus you’re supposed to use it to get all objects of a particular class

The other problem with the QBE: its performance sucks rocks for objects with lots of properties. Querying a db of five objects with the following takes over a minute:

  ObjectSet set = db.get( new CustomerData() );
  while ( set.hasNext() ) {
      (CustomerData) custData = (CustomerData)set.next();
  }

Clearly unacceptable. There's a backdoor way - you can ask the database for all internal IDs of a class, then fetch each object by ID:

 String className = "com.optiron.readi.data.CustomerData";
 StoredClass sc = db.storedClass( className );
 long[] idList = sc.getIDs();
 for ( int i = 0; i < idList.length; i++ ) {
     CustomerData custData = (CustomerData)db.getByID( idList[i] );
     db.activate( custData, 1 );
 }

This fetches the objects instantly, cool. (The activate() is necessary to fill in the object values, since you basically only retrieve a handle to the object using getByID().) So for my testing purposes I can just pass the list of objects to my own Query object, which is more flexible and (hopefully!) faster than the QBE stuff. More soon.

Next: New issue of Perl Review
Previous: Messiness of race identification