@implementation EOCoreDataSource
+static BOOL debugOn = NO;
+
- (id)initWithManagedObjectContext:(NSManagedObjectContext *)_moc
entity:(NSEntityDescription *)_entity
{
EOFetchSpecification *fs;
NSError *error = nil;
NSArray *results;
+
+ if (debugOn) NSLog(@"fetchObjects");
if (![self isFetchEnabled])
return [NSArray array];
fs = [self fetchSpecificationForFetch];
self->fetchRequest = [[fs fetchRequestWithEntity:[self entity]] retain];
}
+
+ if (debugOn) NSLog(@" request: %@", self->fetchRequest);
results = [[self managedObjectContext]
executeFetchRequest:self->fetchRequest error:&error];
return nil;
}
+ if (debugOn) NSLog(@"=> got %d records.", [results count]);
+
// TODO: add grouping support?
return results;
/* archiving */
- (id)initWithKeyValueUnarchiver:(EOKeyValueUnarchiver *)_unarchiver {
- id lEntity;
- id fs;
- id ec;
+ id lEntity, fs, ec, tmp;
/* fetch object context */
NSLog(@"WARNING(%s): decode object context is of unexpected class: %@",
__PRETTY_FUNCTION__, ec);
}
-
+ if (ec == nil) {
+ NSLog(@"WARNING(%s): decoded no object context from archive!",
+ __PRETTY_FUNCTION__);
+ }
+
/* fetch fetch specification */
fs = [_unarchiver decodeObjectForKey:@"fetchRequest"];
/* try to determine entity from fetch-spec */
lEntity = [(EOFetchSpecification *)fs entityName];
}
- if ([lEntity isKindOfClass:[NSString class]]) {
+ if ([lEntity isKindOfClass:[NSString class]] && ec != nil) {
lEntity = [NSEntityDescription entityForName:lEntity
inManagedObjectContext:ec];
}
[_unarchiver decodeObjectForKey:@"auxiliaryQualifier"]];
[self setQualifierBindings:
[_unarchiver decodeObjectForKey:@"qualifierBindings"]];
-
- [self setIsFetchEnabled:[_unarchiver decodeBoolForKey:@"isFetchEnabled"]];
+
+ if ((tmp = [_unarchiver decodeObjectForKey:@"isFetchEnabled"]) != nil)
+ [self setIsFetchEnabled:[tmp boolValue]];
return self;
}
if (self->auxiliaryQualifier != nil)
[ms appendFormat:@" aux=%@", self->auxiliaryQualifier];
-
+
if (self->entity != nil)
- [ms appendFormat:@" entity=%@", self->entity];
+ [ms appendFormat:@" entity=%@", [self->entity name]];
[ms appendString:@">"];
return ms;