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.
c#: IExtObjectContainer#StoredClass(typeof(Foo))
VB: IExtObjectContainer#StoredClass(GetType(Foo))
returns StoredClass for the specified clazz, which can be specified as:
c#: IExtObjectContainer#StoredClasses()
VB: IExtObjectContainer#StoredClasses()
returns an array of all StoredClass meta-information objects.
01public static void SetObjects() 02
{ 03
File.Delete(YapFileName); 04
IObjectContainer oc = Db4oFactory.OpenFile(YapFileName); 05
try 06
{ 07
Car car = new Car("BMW", new Pilot("Rubens Barrichello")); 08
oc.Set(car); 09
car = new Car("Ferrari", new Pilot("Michael Schumacher")); 10
oc.Set(car); 11
} 12
finally 13
{ 14
oc.Close(); 15
} 16
}
01Public Shared Sub SetObjects() 02
File.Delete(YapFileName) 03
Dim oc As IObjectContainer = Db4oFactory.OpenFile(YapFileName) 04
Try 05
Dim car As 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
End Try 12
End Sub
01public static void GetMetaObjects() 02
{ 03
IObjectContainer oc = Db4oFactory.OpenFile(YapFileName); 04
try 05
{ 06
System.Console.WriteLine("Retrieve meta information for class: "); 07
IStoredClass sc = oc.Ext().StoredClass(typeof(Car)); 08
System.Console.WriteLine("Stored class: "+ sc.ToString()); 09
10
System.Console.WriteLine("Retrieve meta information for all classes in database: "); 11
IStoredClass[] sclasses = oc.Ext().StoredClasses(); 12
for (int i=0; i< sclasses.Length; i++) 13
{ 14
System.Console.WriteLine(sclasses[i].GetName()); 15
} 16
} 17
finally 18
{ 19
oc.Close(); 20
} 21
}
01Public Shared Sub GetMetaObjects() 02
Dim oc As IObjectContainer = Db4oFactory.OpenFile(YapFileName) 03
Try 04
System.Console.WriteLine("Retrieve meta information for class: ") 05
Dim sc As IStoredClass = oc.Ext().StoredClass(GetType(Car)) 06
System.Console.WriteLine("Stored class: " + sc.GetName()) 07
08
System.Console.WriteLine("Retrieve meta information for all classes in database: ") 09
Dim sclasses() As IStoredClass = oc.Ext().StoredClasses() 10
Dim i As Integer 11
For i = 0 To sclasses.Length - 1 Step i + 1 12
System.Console.WriteLine(sclasses(i).GetName()) 13
Next 14
Finally 15
oc.Close() 16
End Try 17
End Sub