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:

Java: ExtObjectContainer#storedClasses()

returns an array of all StoredClass meta-information objects.

MetaInfoExample.java: setObjects
01private static void setObjects() { 02 new File(DB4O_FILE_NAME).delete(); 03 ObjectContainer container = Db4o.openFile(DB4O_FILE_NAME); 04 try { 05 Car car = new Car("BMW", new Pilot("Rubens Barrichello")); 06 container.set(car); 07 car = new Car("Ferrari", new Pilot("Michael Schumacher")); 08 container.set(car); 09 } finally { 10 container.close(); 11 } 12 }
MetaInfoExample.java: getMetaObjects
01private static void getMetaObjects() { 02 ObjectContainer container = Db4o.openFile(DB4O_FILE_NAME); 03 try { 04 System.out 05 .println("Retrieve meta information for class: "); 06 StoredClass sc = container.ext().storedClass( 07 Car.class.getName()); 08 System.out.println("Stored class: " + sc.toString()); 09 10 System.out 11 .println("Retrieve meta information for all classes in database: "); 12 StoredClass sclasses[] = container.ext().storedClasses(); 13 for (int i = 0; i < sclasses.length; i++) { 14 System.out.println(sclasses[i].getName()); 15 } 16 } finally { 17 container.close(); 18 } 19 }