From 820b4e5e934f5998c9e7998859a30b6abf9af56f Mon Sep 17 00:00:00 2001 From: helge Date: Fri, 5 Aug 2005 10:27:29 +0000 Subject: [PATCH] improved kv unarchiving git-svn-id: http://svn.opengroupware.org/SOPE/trunk@975 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- sope-core/EOCoreData/ChangeLog | 4 ++++ sope-core/EOCoreData/EOCoreDataSource.m | 29 +++++++++++++++++-------- sope-core/EOCoreData/Version | 2 +- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/sope-core/EOCoreData/ChangeLog b/sope-core/EOCoreData/ChangeLog index ebecd628..4cfdc70a 100644 --- a/sope-core/EOCoreData/ChangeLog +++ b/sope-core/EOCoreData/ChangeLog @@ -1,5 +1,9 @@ 2005-08-04 Helge Hess + * EOCoreDataSource.m: print a warning if no object-context was decoded + from an archive, improved decoding of 'isFetchEnabled' (set to yes in + case no value was set) (v4.5.7) + * NSEntityDescription+EO.m: added EO compatible attribute/relship lookup methods (v4.5.6) diff --git a/sope-core/EOCoreData/EOCoreDataSource.m b/sope-core/EOCoreData/EOCoreDataSource.m index 8d328eec..9a084617 100644 --- a/sope-core/EOCoreData/EOCoreDataSource.m +++ b/sope-core/EOCoreData/EOCoreDataSource.m @@ -29,6 +29,8 @@ static NSString *EODataSourceDidChangeNotification = @implementation EOCoreDataSource +static BOOL debugOn = NO; + - (id)initWithManagedObjectContext:(NSManagedObjectContext *)_moc entity:(NSEntityDescription *)_entity { @@ -256,6 +258,8 @@ static NSString *EODataSourceDidChangeNotification = EOFetchSpecification *fs; NSError *error = nil; NSArray *results; + + if (debugOn) NSLog(@"fetchObjects"); if (![self isFetchEnabled]) return [NSArray array]; @@ -265,6 +269,8 @@ static NSString *EODataSourceDidChangeNotification = fs = [self fetchSpecificationForFetch]; self->fetchRequest = [[fs fetchRequestWithEntity:[self entity]] retain]; } + + if (debugOn) NSLog(@" request: %@", self->fetchRequest); results = [[self managedObjectContext] executeFetchRequest:self->fetchRequest error:&error]; @@ -275,6 +281,8 @@ static NSString *EODataSourceDidChangeNotification = return nil; } + if (debugOn) NSLog(@"=> got %d records.", [results count]); + // TODO: add grouping support? return results; @@ -315,9 +323,7 @@ static NSString *EODataSourceDidChangeNotification = /* archiving */ - (id)initWithKeyValueUnarchiver:(EOKeyValueUnarchiver *)_unarchiver { - id lEntity; - id fs; - id ec; + id lEntity, fs, ec, tmp; /* fetch object context */ @@ -329,7 +335,11 @@ static NSString *EODataSourceDidChangeNotification = 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"]; @@ -345,7 +355,7 @@ static NSString *EODataSourceDidChangeNotification = /* 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]; } @@ -362,8 +372,9 @@ static NSString *EODataSourceDidChangeNotification = [_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; } @@ -397,9 +408,9 @@ static NSString *EODataSourceDidChangeNotification = 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; diff --git a/sope-core/EOCoreData/Version b/sope-core/EOCoreData/Version index f3879a62..e25d7408 100644 --- a/sope-core/EOCoreData/Version +++ b/sope-core/EOCoreData/Version @@ -1,3 +1,3 @@ # version file -SUBMINOR_VERSION:=6 +SUBMINOR_VERSION:=7 -- 2.39.5