This topic applies to .NET version only
Let's look at an example. We will use SensorPanel class from Activation example, which represents a simple linked list.
In order to check if SensorPanel is TA enabled in the runtime we will add the following Diagnostic listener:
1private static void ActivateDiagnostics(IConfiguration configuration) 2
{ 3
// Add diagnostic listener that will show all the classes that are not 4
// TA aware. 5
configuration.Diagnostic().AddListener(new TaDiagListener()); 6
}
01public class TaDiagListener: DiagnosticToConsole 02
{ 03
override public void OnDiagnostic(Db4objects.Db4o.Diagnostic.IDiagnostic d) 04
{ 05
if (d.GetType().Equals(typeof(Db4objects.Db4o.TA.NotTransparentActivationEnabled))) 06
{ 07
System.Console.WriteLine(d.ToString()); 08
} 09
} 10
}
1Private Shared Sub ActivateDiagnostics(ByVal configuration As IConfiguration) 2
' Add diagnostic listener that will show all the classes that are not 3
' TA aware. 4
configuration.Diagnostic().AddListener(New TaDiagListener()) 5
End Sub
1Public Class TaDiagListener 2
Inherits DiagnosticToConsole 3
Public Overloads Overrides Sub OnDiagnostic(ByVal d As IDiagnostic) 4
If TypeOf d Is NotTransparentActivationEnabled Then 5
System.Console.WriteLine(d) 6
End If 7
End Sub 8
End Class
10 linked instances of SensorPanel will be stored and retrieved:
01private static void StoreCollection() 02
{ 03
File.Delete(Db4oFileName); 04
IObjectContainer db = Database(ConfigureTA()); 05
if (db != null) 06
{ 07
try 08
{ 09
// create a linked list with length 10 10
SensorPanel sensorPanel = new SensorPanel().CreateList(10); 11
// store all elements with one statement, since all elements are new 12
db.Set(sensorPanel); 13
} 14
finally 15
{ 16
CloseDatabase(); 17
} 18
} 19
}
01private static void TestCollection() 02
{ 03
StoreCollection(); 04
IObjectContainer db = Database(ConfigureTA()); 05
if (db != null) 06
{ 07
try 08
{ 09
IList<SensorPanel> result = db.Query<SensorPanel>(delegate(SensorPanel sensorPanel) 10
{ 11
if (sensorPanel.Sensor.Equals(1)) 12
{ 13
return true; 14
} 15
return false; 16
}); 17
Console.WriteLine(result.Count); 18
if (result.Count > 0) 19
{ 20
SensorPanel sensor = (SensorPanel)result[0]; 21
SensorPanel next = sensor.Next; 22
while (next != null) 23
{ 24
Console.WriteLine(next); 25
next = next.Next; 26
} 27
} 28
} 29
finally 30
{ 31
CloseDatabase(); 32
} 33
} 34
}
01Private Shared Sub StoreCollection() 02
File.Delete(Db4oFileName) 03
Dim db As IObjectContainer = Database(ConfigureTA()) 04
If db IsNot Nothing Then 05
Try 06
' create a linked list with length 10 07
Dim sensorPanel As SensorPanel = New SensorPanel().CreateList(10) 08
' store all elements with one statement, since all elements are new 09
db.[Set](sensorPanel) 10
Finally 11
CloseDatabase() 12
End Try 13
End If 14
End Sub
01Private Shared Sub TestCollection() 02
StoreCollection() 03
Dim db As IObjectContainer = Database(ConfigureTA()) 04
If db IsNot Nothing Then 05
Try 06
Dim result As IList(Of SensorPanel) = db.Query(Of SensorPanel)(AddressOf FirstPanel) 07
Console.WriteLine(result.Count) 08
If result.Count > 0 Then 09
Dim sensor As SensorPanel = DirectCast(result(0), SensorPanel) 10
Dim [next] As SensorPanel = sensor.Next 11
While [next] IsNot Nothing 12
Console.WriteLine([next].ToString) 13
[next] = [next].Next 14
End While 15
End If 16
Finally 17
CloseDatabase() 18
End Try 19
End If 20
End Sub