Native Queries

We have checked in the SODA topic that SODA queries can work with a server without application classes deployed. So we can expect optimized Native Queries (converted to SODA under the hood) to work as well:

Client.cs: GetPilotsNative
01private static void GetPilotsNative() 02 { 03 Console.WriteLine("Retrieving Pilot objects: Native Query"); 04 IObjectContainer oc = Db4oFactory.OpenClient("localhost", 0xdb40, "db4o", "db4o"); 05 try 06 { 07 IList<Pilot> result = oc.Query<Pilot>(delegate(Pilot pilot) 08 { 09 return pilot.Points == 5; 10 }); 11 ListResult(result); 12 } 13 finally 14 { 15 oc.Close(); 16 } 17 }

Client.vb: GetPilotsNative
01Private Shared Sub GetPilotsNative() 02 Console.WriteLine("Retrieving Pilot objects: Native Query") 03 Dim oc As IObjectContainer = Db4oFactory.OpenClient("localhost", &HDB40, "db4o", "db4o") 04 Try 05 Dim result As IList(Of Pilot) = oc.Query(Of Pilot)(AddressOf Pilot5Points) 06 ListResult(result) 07 Finally 08 oc.Close() 09 End Try 10 End Sub
Client.vb: Pilot5Points
1Private Shared Function Pilot5Points(ByVal pilot As Pilot) As Boolean 2 Return pilot.Points.Equals(5) 3 End Function

Unfortunately, if the query cannot be optimized to SODA, the server needs to instantiate the classes to run the query. This is not possible if the class is not available

This query won't work:

Client.cs: GetPilotsNativeUnoptimized
01private static void GetPilotsNativeUnoptimized() 02 { 03 Console.WriteLine("Retrieving Pilot objects: Native Query Unoptimized"); 04 IObjectContainer oc = Db4oFactory.OpenClient("localhost", 0xdb40, "db4o", "db4o"); 05 try 06 { 07 IList<Pilot> result = oc.Query<Pilot>(delegate(Pilot pilot) 08 { 09 return pilot.Points % 2 == 0; 10 }); 11 ListResult(result); 12 } 13 finally 14 { 15 oc.Close(); 16 } 17 }

Client.vb: GetPilotsNativeUnoptimized
01Private Shared Sub GetPilotsNativeUnoptimized() 02 Console.WriteLine("Retrieving Pilot objects: Native Query Unoptimized") 03 Dim oc As IObjectContainer = Db4oFactory.OpenClient("localhost", &HDB40, "db4o", "db4o") 04 Try 05 Dim result As IList(Of Pilot) = oc.Query(Of Pilot)(AddressOf Pilot5Points) 06 ListResult(result) 07 Finally 08 oc.Close() 09 End Try 10 End Sub
Client.vb: PilotEven
1Private Shared Function PilotEven(ByVal pilot As Pilot) As Boolean 2 Return pilot.Points Mod 2 = 0 3 End Function