Databases Reference
In-Depth Information
NSError *error = nil;
NSArray *objects = [context executeFetchRequest:request error:&error];
[request release], request = nil;
if (error) {
NSLog(@ "%@:%s error: %@" , [self class], __PRETTY_FUNCTION__, error);
return nil;
}
return objects;
}
In this method, we retrieve a reference to the NSManagedObjectContext and build
an NSFetchRequest to retrieve all the Test entities from the persistent store. If
there are any errors, we log them and return nil . Otherwise, we return the
resulting NSArray .
This method, although useful for demonstrating distributed objects and Core
Data, is a very poor performer. When we're working with tens of thousands
of entities in the persistent store, they take a long time to pass over the net-
work. This hampers the performance of not just the client making the request
but every client waiting in line to make a request on the server. If our
requirements involve data of this size, we should consider other options. One
option that has met great success is to keep a local copy of the entire reposi-
tory on each machine and, when the machines sync, merely pass deltas back
and forth instead of a true client-server environment.
-createObject Implementation
DistributedCDServer/AppDelegate.m
- (byref NSManagedObject*)createObject;
{
NSManagedObjectContext *context = [self managedObjectContext];
NSManagedObject *object = nil;
object = [NSEntityDescription insertNewObjectForEntityForName:@ "Test"
inManagedObjectContext:context];
return object;
}
The -createObject method demonstrates a more performant distributed object
method. In this method, we again retrieve a reference to the NSManagedObject-
Context and use that reference to create a new Test object. We create and delete
all objects on the server as opposed to pulling the NSManagedObjectContext to the
client and trying to delete it remotely. This helps prevent any threading issues
while working with the NSManagedObjectContext .
 
 
 
Search WWH ::




Custom Search