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:
01public static void SetObjects() 02
{ 03
File.Delete(YapFileName); 04
IObjectContainer db = Db4oFactory.OpenFile(YapFileName); 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
}
01Public Shared Sub SetObjects() 02
File.Delete(YapFileName) 03
Dim db As IObjectContainer = Db4oFactory.OpenFile(YapFileName) 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
Now we can update the cars using specially designed singleton:
01public static void UpdateCars() 02
{ 03
// triggering mass updates with a singleton 04
// complete server-side execution 05
IObjectServer server=Db4oFactory.OpenServer(YapFileName,0); 06
try 07
{ 08
IObjectContainer client=server.OpenClient(); 09
IQuery q = client.Query(); 10
q.Constrain(typeof(RemoteExample)); 11
q.Constrain(new UpdateEvaluation()); 12
q.Execute(); 13
client.Close(); 14
} 15
finally 16
{ 17
server.Close(); 18
} 19
CheckCars(); 20
}
01Public Shared Sub UpdateCars() 02
' triggering mass updates with a singleton 03
' complete server-side execution 04
Dim server As IObjectServer = Db4oFactory.OpenServer(YapFileName, 0) 05
Try 06
Dim client As IObjectContainer = server.OpenClient() 07
Dim q As IQuery = client.Query() 08
q.Constrain(GetType(RemoteExample)) 09
q.Constrain(New UpdateEvaluation()) 10
q.Execute() 11
client.Close() 12
Finally 13
server.Close() 14
End Try 15
CheckCars() 16
End Sub
This method has its pros and cons.
Pros:
Cons: