TA Enhancement With Db4oTool

This topic applies to .NET version only 

TA instrumentation can be done by appilying

Db4oTool utility to the ready .NET assemblies:

Db4oTool -ta assembly

Let's look at a simple example. We will use SensorPanel class from Activation example:

SensorPanelTA.cs
01/* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com */ 02using Db4objects.Db4o; 03using Db4objects.Db4o.Activation; 04using Db4objects.Db4o.TA; 05 06namespace Db4ojects.Db4odoc.TAExamples 07{ 08 public class SensorPanelTA /*must implement Activatable for TA*/ 09 { 10 private object _sensor; 11 12 private SensorPanelTA _next; 13 14 15 public SensorPanelTA() 16 { 17 // default constructor for instantiation 18 } 19 20 public SensorPanelTA(int value) 21 { 22 _sensor = value; 23 } 24 25 26 public SensorPanelTA Next 27 { 28 get 29 { 30 return _next; 31 } 32 } 33 34 public object Sensor 35 { 36 get 37 { 38 return _sensor; 39 } 40 } 41 42 public SensorPanelTA CreateList(int length) 43 { 44 return CreateList(length, 1); 45 } 46 47 public SensorPanelTA CreateList(int length, int first) 48 { 49 int val = first; 50 SensorPanelTA root = NewElement(first); 51 SensorPanelTA list = root; 52 while (--length > 0) 53 { 54 list._next = NewElement(++val); 55 list = list.Next; 56 } 57 return root; 58 } 59 60 protected SensorPanelTA NewElement(int value) 61 { 62 return new SensorPanelTA(value); 63 } 64 65 public override string ToString() 66 { 67 return "Sensor #" + Sensor; 68 } 69 70 } 71 72}
SensorPanelTA.vb
01' Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com 02Imports Db4objects.Db4o 03Imports Db4objects.Db4o.Activation 04Imports Db4objects.Db4o.TA 05 06Namespace Db4ojects.Db4odoc.TAExamples 07 08 Public Class SensorPanelTA 09 10 Private _sensor As Object 11 Private _next As SensorPanelTA 12 13 14 Public Sub New() 15 End Sub 16 17 Public Sub New(ByVal value As Integer) 18 _sensor = value 19 End Sub 20 21 22 Public ReadOnly Property NextSensor() As SensorPanelTA 23 Get 24 Return _next 25 End Get 26 End Property 27 28 Public ReadOnly Property Sensor() As Object 29 Get 30 Return _sensor 31 End Get 32 End Property 33 34 Public Function CreateList(ByVal length As Integer) As SensorPanelTA 35 Return CreateList(length, 1) 36 End Function 37 38 Public Function CreateList(ByVal length As Integer, ByVal first As Integer) As SensorPanelTA 39 Dim val As Integer = first 40 Dim root As SensorPanelTA = NewElement(first) 41 Dim list As SensorPanelTA = root 42 While System.Threading.Interlocked.Decrement(length) > 0 43 list._next = NewElement(System.Threading.Interlocked.Increment(val)) 44 list = list.NextSensor 45 End While 46 Return root 47 End Function 48 49 Protected Function NewElement(ByVal value As Integer) As SensorPanelTA 50 Return New SensorPanelTA(value) 51 End Function 52 53 Public Overloads Overrides Function ToString() As String 54 If Sensor Is Nothing Then 55 Return "" 56 Else 57 Return "Sensor #" + Sensor.ToString() 58 End If 59 End Function 60 End Class 61End Namespace

In your code you will need to add Transparent Activation support to the configuration:

TAExample.cs: ConfigureTA
1private static IConfiguration ConfigureTA() 2 { 3 IConfiguration configuration = Db4oFactory.NewConfiguration(); 4 // set normal activation to 0 5 configuration.ActivationDepth(0); 6 // add TA support 7 configuration.Add(new TransparentActivationSupport()); 8 return configuration; 9 }
TAExample.cs: StoreSensorPanel
01private static void StoreSensorPanel() 02 { 03 File.Delete(Db4oFileName); 04 IObjectContainer container = Database(Db4oFactory.NewConfiguration()); 05 if (container != null) 06 { 07 try 08 { 09 // create a linked list with length 10 10 SensorPanelTA list = new SensorPanelTA().CreateList(10); 11 container.Set(list); 12 } 13 finally 14 { 15 CloseDatabase(); 16 } 17 } 18 }
TAExample.cs: TestActivation
01private static void TestActivation() 02 { 03 StoreSensorPanel(); 04 IConfiguration configuration = ConfigureTA(); 05 06 IObjectContainer container = Database(configuration); 07 if (container != null) 08 { 09 try 10 { 11 System.Console.WriteLine("Zero activation depth"); 12 IObjectSet result = container.Get(new SensorPanelTA(1)); 13 ListResult(result); 14 if (result.Size() > 0) 15 { 16 SensorPanelTA sensor = (SensorPanelTA)result[0]; 17 // the object is a linked list, so each call to next() 18 // will need to activate a new object 19 SensorPanelTA next = sensor.Next; 20 while (next != null) 21 { 22 System.Console.WriteLine(next); 23 next = next.Next; 24 } 25 } 26 } 27 finally 28 { 29 CloseDatabase(); 30 } 31 } 32 }
TAExample.vb: ConfigureTA
1Private Shared Function ConfigureTA() As IConfiguration 2 Dim configuration As IConfiguration = Db4oFactory.NewConfiguration 3 ' set normal activation to 0 4 configuration.ActivationDepth(0) 5 ' add TA support 6 configuration.Add(New TransparentActivationSupport) 7 Return configuration 8 End Function
TAExample.vb: StoreSensorPanel
01Private Shared Sub StoreSensorPanel() 02 File.Delete(Db4oFileName) 03 Dim container As IObjectContainer = Database(Db4oFactory.NewConfiguration) 04 If Not (container Is Nothing) Then 05 Try 06 ' create a linked list with length 10 07 Dim list As SensorPanelTA = (New SensorPanelTA).CreateList(10) 08 container.Set(list) 09 Finally 10 CloseDatabase() 11 End Try 12 End If 13 End Sub
TAExample.vb: TestActivation
01Private Shared Sub TestActivation() 02 StoreSensorPanel() 03 Dim configuration As IConfiguration = ConfigureTA() 04 Dim container As IObjectContainer = Database(configuration) 05 If Not (container Is Nothing) Then 06 Try 07 System.Console.WriteLine("Zero activation depth") 08 Dim result As IObjectSet = container.Get(New SensorPanelTA(1)) 09 ListResult(result) 10 If result.Size > 0 Then 11 Dim sensor As SensorPanelTA = CType(result(0), SensorPanelTA) 12 ' the object is a linked list, so each call to next() 13 ' will need to activate a new object 14 Dim nextSensor As SensorPanelTA = sensor.NextSensor 15 While Not (nextSensor Is Nothing) 16 System.Console.WriteLine(nextSensor.ToString()) 17 nextSensor = nextSensor.NextSensor 18 End While 19 End If 20 Finally 21 CloseDatabase() 22 End Try 23 End If 24 End Sub

Compile and run the application. Now, you can add TA support by using the following command-line:

Db4oTool -ta TAExamples.exe

use -vv option for verbose output:

Db4oTool -ta -vv TAExamples.exe

You can also apply type filter to TA enable only selected types:

Db4oTool.exe -vv -ta -by-name:S* TAExamples.exe

Db4oTool uses .NET regex to parse the -by-name parameter, in the example above all types starting with "S" will be TA enabled.

Run TA enabled assembly and compare results to the previous run.