Database Reference
In-Depth Information
all the Test entities. From there, we call -createChildForObject: on the server, ran-
domly using one of the Test entities from the retrieved NSArray . We let the
server handle the actual creation of the relationship between these objects
to ensure there are no issues with the distributed objects themselves. During
testing, Core Data got confused when the relationship was created on the
client as opposed to the server. Therefore, to avoid any risks in this area, we
pass the parent back to the server to let the server both create the child and
set the relationship between the two objects.
DistributedCDClient/AppDelegate.m
- ( void )testChildInsertion
{
NSArray *objects = [server allObjects];
id object = [objects objectAtIndex:(rand() % [objects count])];
id child = [server createChildForObject:object];
[child setValue:GUID forKey:@ "name" ];
}
-testChildDeletion Implementation
The last test method is the deletion of a child object. In this test, we again
retrieve all the Test entities from the server and randomly select one. We then
check to see whether the Test entity has a child, and if it does, we grab one of
them and call -deleteObject: on the server with that child as the parameter.
DistributedCDClient/AppDelegate.m
- ( void )testChildDeletion
{
NSArray *objects = [server allObjects];
int index = (rand() % [objects count]);
id object = [objects objectAtIndex:index];
NSSet *children = [object valueForKey:@ "children" ];
if (![children count]) return ;
id child = [children anyObject];
[server deleteObject:child];
}
11.4
Wrapping Up
Whenever we start working with multiple computers on a network or interap-
plication communication, the code starts to get extremely complex. However,
at least with this design, we can keep the Core Data/persistence separated
from the distributed objects/networking as much as possible. By doing so,
we avoid the need for a large number of locks and synchronization that would
otherwise be required.
 
 
 
Search WWH ::




Custom Search