What if the handheld doesn't have enough memory to store a complete set of all of the data objects? Well, then we should check, which objects are to be replicated:
01public static void ReplicatePilots() 02
{ 03
IObjectContainer desktop = Db4oFactory.OpenFile(DtFileName); 04
IObjectContainer handheld = Db4oFactory.OpenFile(HhFileName); 05
IReplicationSession replication = Db4objects.Drs.Replication.Begin(handheld, desktop); 06
IObjectSet changed = replication.ProviderB().ObjectsChangedSinceLastReplication(); 07
//Iterate changed objects, replicate them 08
while (changed.HasNext()) 09
{ 10
object p = changed .Next(); 11
if ( p is Pilot) 12
{ 13
if (((Pilot)p).Name.StartsWith("S")) 14
{ 15
replication.Replicate(p); 16
} 17
} 18
} 19
replication.Commit(); 20
}
01Public Shared Sub ReplicatePilots() 02
Dim desktop As IObjectContainer = Db4oFactory.OpenFile(DtFileName) 03
Dim handheld As IObjectContainer = Db4oFactory.OpenFile(HhFileName) 04
Dim replic As IReplicationSession = Replication.Begin(handheld, desktop) ' 05
' There is no need to replicate all the objects each time. 06
' ObjectsChangedSinceLastReplication methods gives us 07
' a list of modified objects 08
Dim changed As IObjectSet = replic.ProviderB().ObjectsChangedSinceLastReplication() 09
' Iterate through the changed objects, 10
' check if the name starts with "S" and replicate only those items 11
While changed.HasNext() 12
Dim p As Object = changed.Next 13
If (p Is GetType(Pilot)) Then 14
If (CType(p, Pilot)).Name.StartsWith("S") Then 15
replic.Replicate(p) 16
End If 17
End If 18
End While 19
replic.Commit() 20
End Sub
Now, only Pilots whose name starts with "S" will be replicated to the handheld database.