Remote Execution Through Evaluation API

One of the ways to do that is using evaluation API. Evaluation/candidate classes are serialized and sent to the server. That means that if we will put the selection criteria and update code inside evaluation class, we will have that code on the server and executing a query using evaluation on the client side will run the update code on the server side.

For easier query execution we can use database singleton - a class that have only one instance saved in the database. That actually can be the class calling the query itself.

Let's fill up our server database:

RemoteExample.cs: SetObjects
01private static void SetObjects() 02 { 03 File.Delete(Db4oFileName); 04 IObjectContainer db = Db4oFactory.OpenFile(Db4oFileName); 05 try 06 { 07 for (int i = 0; i < 5; i++) 08 { 09 Car car = new Car("car"+i); 10 db.Set(car); 11 } 12 db.Set(new RemoteExample()); 13 } 14 finally 15 { 16 db.Close(); 17 } 18 CheckCars(); 19 }
RemoteExample.vb: SetObjects
01Private Shared Sub SetObjects() 02 File.Delete(Db4oFileName) 03 Dim db As IObjectContainer = Db4oFactory.OpenFile(Db4oFileName) 04 Try 05 Dim i As Integer 06 For i = 0 To 5 - 1 Step i + 1 07 Dim car As Car = New Car("car" + i.ToString()) 08 db.Set(car) 09 Next 10 db.Set(New RemoteExample()) 11 Finally 12 db.Close() 13 End Try 14 CheckCars() 15 End Sub

[/filter]

Now we can update the cars using specially designed singleton:

This method has its pros and cons.

Pros:

  • any arbitrary code can be executed;
  • the code is executed on the server side;

Cons:

  • the code will have to be serialized and sent over a network connection;
  • changing the code will require update of all clients