Accessing db4o meta-information

Db4o provides an access to the database meta-information through its extended object container interface (ExtObjectContainer(Java)/IExtObjectContainer(.NET)).

Within the object database meta-schema is represented by classes and their fields. To access their meta-information db4o provides special interfaces:

The following ExtObjectContainer methods give you access to the StoredClass.

Java: ExtObjectContainer#storedClass(Foo.class)

returns StoredClass for the specified clazz, which can be specified as:

  • a fully qualified classname;
  • a Class/Type object;
  • any object to be used as a template.

Java: ExtObjectContainer#storedClasses()

returns an array of all StoredClass meta-information objects.

MetaInfExample.java: setObjects
01public static void setObjects(){ 02 new File(Util.YAPFILENAME).delete(); 03 ObjectContainer oc = Db4o.openFile(Util.YAPFILENAME); 04 try { 05 Car car = new Car("BMW", new Pilot("Rubens Barrichello")); 06 oc.set(car); 07 car = new Car("Ferrari", new Pilot("Michael Schumacher")); 08 oc.set(car); 09 } finally { 10 oc.close(); 11 } 12 }

MetaInfExample.java: getMetaObjects
01public static void getMetaObjects(){ 02 ObjectContainer oc = Db4o.openFile(Util.YAPFILENAME); 03 try { 04 System.out.println("Retrieve meta information for class: "); 05 StoredClass sc = oc.ext().storedClass(Car.class.getName()); 06 System.out.println("Stored class: "+ sc.toString()); 07 08 System.out.println("Retrieve meta information for all classes in database: "); 09 StoredClass sclasses[] = oc.ext().storedClasses(); 10 for (int i=0; i< sclasses.length; i++){ 11 System.out.println(sclasses[i].getName()); 12 } 13 } finally { 14 oc.close(); 15 } 16 }