What if the mobile device doesn't have enough memory to store all objects? Or if only a subset of the object need to be in both databases? In this case you can replicate only a subset of all objects.
You can ask the dRS to replicate only the objects of a certain class. Instead of getting the change-set with all objects, it will return only the changed objects of that class.
ObjectSet changesOnDesktop = replicationSession.providerA().objectsChangedSinceLastReplication(Pilot.class); for (Object changedObjectOnDesktop : changesOnDesktop) { replicationSession.replicate(changedObjectOnDesktop); } replicationSession.commit();
For more complex cases a simple condition can be a solution. Add a simple condition within the replication loop to select which objects are replicated and which ones not.
ObjectSet changesOnDesktop = replicationSession.providerA().objectsChangedSinceLastReplication(); for (Object changedObjectOnDesktop : changesOnDesktop) { if (changedObjectOnDesktop instanceof Car) { if (((Car) changedObjectOnDesktop).getName().startsWith("M")) { replicationSession.replicate(changedObjectOnDesktop); } } } replicationSession.commit();
It's also possible to query for the objects and the replicate those objects. However in this case, also unchanged objects are replicated again.
ObjectSet<Car> changesOnDesktop = desktopDatabase.query(new Predicate<Car>() { public boolean match(Car p) { return p.getName().startsWith("M"); } }); for (Car changedObjectOnDesktop : changesOnDesktop) { replicationSession.replicate(changedObjectOnDesktop); } replicationSession.commit();
Of course it possible to use a combination of these three possibilities. For example you can request the changes for a certain class and then filter with a condition.