(IStoredClass and IStoredField in .NET)
Let's look closer at the class meta-information interfaces.
They look quite similar to reflection API, but unlike reflection there is no information about methods and constructors.
You can only use StoredClass to get the class's fields:
Java: StoredClass#getStoredFields()
returns all stored fields of this stored class.
Java: StoredClass#storedField(name, type)
returns an existing stored field of this stored class.
You can also use this interface to explore classes hierarchy.
Java: StoredClass#getParentStoredClass
returns the parent of the class.
StoredField interface gives you access to various meta-field information, such as field name, field type. It also provides some helpful methods for manipulating fields accepting their object as a variable (see db4o API for more information).
01private static void getMetaObjectsInfo() { 02
ObjectContainer container = Db4o.openFile(DB4O_FILE_NAME); 03
try { 04
System.out 05
.println("Retrieve meta information for field: "); 06
StoredClass sc = container.ext().storedClass( 07
Car.class.getName()); 08
StoredField sf = sc.storedField("pilot", Pilot.class); 09
System.out 10
.println("Field info: " + sf.getName() + "/" 11
+ sf.getStoredType() + "/isArray=" 12
+ sf.isArray()); 13
14
System.out.println("Retrieve all fields: "); 15
StoredField sfields[] = sc.getStoredFields(); 16
for (int i = 0; i < sfields.length; i++) { 17
System.out.println("Stored field: " 18
+ sfields[i].getName() + "/" 19
+ sfields[i].getStoredType()); 20
} 21
} finally { 22
container.close(); 23
} 24
}