Global Activation Settings

c#: Db4oFactory.Configure().ActivationDepth(activationDepth)

VB: Db4oFactory.Configure().ActivationDepth(activationDepth)

configures global activation depth, which will be used for all objects instead of the default value. This method should be called before opening a database file.

c#: IExtObjectContainer.Configure().ActivationDepth(activationDepth)

VB: IExtObjectContainer.Configure().ActivationDepth(activationDepth)

has a similar effect, but the setting will be applied to the specific ObjectContainer and can be changed for the open database file.

ActivationExample.cs: TestActivationConfig
01public static void TestActivationConfig() 02 { 03 StoreSensorPanel(); 04 IObjectContainer db = Db4oFactory.OpenFile(YapFileName); 05 try 06 { 07 db.Ext().Configure().ActivationDepth(1); 08 Console.WriteLine("Object container activation depth = 1"); 09 IObjectSet result = db.Get(new SensorPanel(1)); 10 ListResult(result); 11 if (result.Count >0) 12 { 13 SensorPanel sensor = (SensorPanel)result[0]; 14 SensorPanel next = sensor.Next; 15 while (next != null) 16 { 17 Console.WriteLine(next); 18 next = next.Next; 19 } 20 } 21 } 22 finally 23 { 24 db.Close(); 25 } 26 }

ActivationExample.vb: TestActivationConfig
01Public Shared Sub TestActivationConfig() 02 StoreSensorPanel() 03 Dim db As IObjectContainer = Db4oFactory.OpenFile(YapFileName) 04 Try 05 db.Ext().Configure().ActivationDepth(1) 06 Console.WriteLine("Object container activation depth = 1") 07 Dim result As IObjectSet = db.Get(New SensorPanel(1)) 08 ListResult(result) 09 If result.Count > 0 Then 10 Dim sensor As SensorPanel = CType(result(0), SensorPanel) 11 Dim nextSensor As SensorPanel = sensor.NextSensor 12 While Not nextSensor Is Nothing 13 Console.WriteLine(nextSensor) 14 nextSensor = nextSensor.NextSensor 15 End While 16 End If 17 Finally 18 db.Close() 19 End Try 20 End Sub

By configuring db4o you can have full control over activation behavior. The two extremes:

  • using an activationDepth of Integer.MAX_VALUE lets you forget about manual activation, but does not give you the best performance and memory footprint;
  • using an activationDepth of 0 and activating and deactivating all objects manually keeps memory consumption extremely low, but needs more coding and attention.