Modified: incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYClientObjRelationship.h URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYClientObjRelationship.h?rev=437466&r1=437465&r2=437466&view=diff ============================================================================== --- incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYClientObjRelationship.h (original) +++ incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYClientObjRelationship.h Sun Aug 27 14:56:04 2006 @@ -21,6 +21,7 @@ -(NSString *)name; -(void)setTargetEntityName:(NSString *)n; -(NSString *)targetEntityName; +-(BOOL)isToMany; @end
Modified: incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYClientObjRelationship.m URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYClientObjRelationship.m?rev=437466&r1=437465&r2=437466&view=diff ============================================================================== --- incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYClientObjRelationship.m (original) +++ incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYClientObjRelationship.m Sun Aug 27 14:56:04 2006 @@ -53,6 +53,11 @@ return targetEntityName; } +-(BOOL)isToMany +{ + return toMany; +} + -(void)dealloc { [name release]; Modified: incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYDataMap.m URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYDataMap.m?rev=437466&r1=437465&r2=437466&view=diff ============================================================================== --- incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYDataMap.m (original) +++ incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYDataMap.m Sun Aug 27 14:56:04 2006 @@ -16,6 +16,11 @@ [super init]; [self setName:[coder decodeObjectForKey:@"name"]]; [self setObjEntityMap:[coder decodeObjectForKey:@"objEntityMap"]]; + + // remove extra entry created by hessian framework + // TODO: fix in framework? + [[self objEntityMap] removeObjectForKey:@"hessianClassName"]; + return self; } Modified: incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYEntityResolver.h URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYEntityResolver.h?rev=437466&r1=437465&r2=437466&view=diff ============================================================================== --- incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYEntityResolver.h (original) +++ incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYEntityResolver.h Sun Aug 27 14:56:04 2006 @@ -20,5 +20,6 @@ -(NSMutableDictionary *)classMapping; -(void)updateClassMapping; +-(CAYObjEntity *)objEntityForClass:(Class)cl; @end Modified: incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYEntityResolver.m URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYEntityResolver.m?rev=437466&r1=437465&r2=437466&view=diff ============================================================================== --- incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYEntityResolver.m (original) +++ incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYEntityResolver.m Sun Aug 27 14:56:04 2006 @@ -61,25 +61,44 @@ NSString *entityName; while(entityName = [enumerator nextObject]) { - if(![entityName isEqualToString:@"hessianClassName"]) + CAYObjEntity *entity = [objEntityMap objectForKey:entityName]; + + Class cl = NSClassFromString([entity name]); + if(cl) { - CAYObjEntity *entity = [objEntityMap objectForKey:entityName]; - - Class cl = NSClassFromString([entity name]); - if(cl) - { - NSLog(@"mapping client %@ to server %@", [entity name], [entity serverClassName]); - [cm setObject:[entity name] forKey:[entity serverClassName]]; - - } - else - { - NSLog(@"Could not find cocoa class %@ for server class $@", [entity name], [entity serverClassName]); - } - } + NSLog(@"mapping client %@ to server %@", [entity name], [entity serverClassName]); + [cm setObject:[entity name] forKey:[entity serverClassName]]; + } + else + { + NSLog(@"Could not find cocoa class %@ for server class $@", [entity name], [entity serverClassName]); + } } [self setClassMapping:cm]; +} + +-(CAYObjEntity *)objEntityForClass:(Class)cl +{ + // TODO: handle more than one map? + CAYDataMap *dataMap = [[self maps] objectAtIndex:0]; + //NSLog(@"datamap.name: %@", [dataMap valueForKey:@"name"]); + NSMutableDictionary *objEntityMap = [dataMap objEntityMap]; + + // TODO: cache the lookup using a NSDictionary! + NSEnumerator *enumerator = [objEntityMap keyEnumerator]; + NSString *entityName; + while(entityName = [enumerator nextObject]) + { + CAYObjEntity *entity = [objEntityMap objectForKey:entityName]; + Class tc = NSClassFromString([entity name]); + if([cl isEqualTo:tc]) + { + return entity; + } + } + + return nil; } -(void)dealloc Modified: incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYFault.h URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYFault.h?rev=437466&r1=437465&r2=437466&view=diff ============================================================================== --- incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYFault.h (original) +++ incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYFault.h Sun Aug 27 14:56:04 2006 @@ -23,5 +23,6 @@ -(void)setRelationshipName:(NSString *)rn; -(NSString *)relationshipName; +-(id)resolveFault; @end Modified: incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYFault.m URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYFault.m?rev=437466&r1=437465&r2=437466&view=diff ============================================================================== --- incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYFault.m (original) +++ incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYFault.m Sun Aug 27 14:56:04 2006 @@ -7,7 +7,7 @@ // #import "CAYFault.h" - +#import "CAYObjectContext.h" @implementation CAYFault @@ -46,12 +46,17 @@ return relationshipName; } +-(id)resolveFault +{ + NSLog(@"ERROR. CayFault is abstract. use a subclass"); + return nil; +} + -(void)dealloc { [self setSourceObject:nil]; [self setRelationshipName:nil]; [super dealloc]; } - @end Modified: incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYHessianConnection.m URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYHessianConnection.m?rev=437466&r1=437465&r2=437466&view=diff ============================================================================== --- incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYHessianConnection.m (original) +++ incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYHessianConnection.m Sun Aug 27 14:56:04 2006 @@ -13,7 +13,7 @@ - (id) sendMessage:(CAYClientMessage *)message { - NSArray * parameters = [NSArray arrayWithObject:message]; + NSArray *parameters = [NSArray arrayWithObject:message]; id result = [proxy callSynchronous:@"processMessage" withParameters:parameters]; return result; } Modified: incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYObjEntity.h URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYObjEntity.h?rev=437466&r1=437465&r2=437466&view=diff ============================================================================== --- incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYObjEntity.h (original) +++ incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYObjEntity.h Sun Aug 27 14:56:04 2006 @@ -14,7 +14,7 @@ NSArray *attributes; NSString *name; NSString *serverClassName; - NSDictionary *relationships; + NSMutableDictionary *relationships; } @@ -24,7 +24,7 @@ -(NSString *)name; -(void)setServerClassName:(NSString *)n; -(NSString *)serverClassName; --(void)setRelationships:(NSDictionary *)r; --(NSDictionary *)relationships; +-(void)setRelationships:(NSMutableDictionary *)r; +-(NSMutableDictionary *)relationships; @end Modified: incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYObjEntity.m URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYObjEntity.m?rev=437466&r1=437465&r2=437466&view=diff ============================================================================== --- incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYObjEntity.m (original) +++ incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYObjEntity.m Sun Aug 27 14:56:04 2006 @@ -18,6 +18,12 @@ [self setName:[coder decodeObjectForKey:@"name"]]; [self setServerClassName:[coder decodeObjectForKey:@"className"]]; [self setRelationships:[coder decodeObjectForKey:@"relationships"]]; + + // remove extra entry created by hessian framework + // TODO: fix in framework? + [[self relationships] removeObjectForKey:@"hessianClassName"]; + + return self; } @@ -65,14 +71,14 @@ return serverClassName; } --(void)setRelationships:(NSDictionary *)r +-(void)setRelationships:(NSMutableDictionary *)r { [r retain]; [relationships release]; relationships = r; } --(NSDictionary *)relationships +-(NSMutableDictionary *)relationships { return relationships; } Modified: incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYObjectContext.m URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYObjectContext.m?rev=437466&r1=437465&r2=437466&view=diff ============================================================================== --- incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYObjectContext.m (original) +++ incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYObjectContext.m Sun Aug 27 14:56:04 2006 @@ -15,6 +15,11 @@ #import "CAYNodePropertyChangeOperation.h" #import "CAYCompoundDiff.h" #import "CAYSyncMessage.h" +#import "CAYObjEntity.h" +#import "CAYClientObjRelationship.h" +#import "CAYFault.h" +#import "CAYToManyFault.h" +#import "CAYToOneFault.h" @implementation CAYObjectContext @@ -37,7 +42,7 @@ NSArray *results = [result results]; NSArray *rows = [results objectAtIndex:0]; - + // connect objects to the context int n = [rows count]; int i; @@ -50,8 +55,33 @@ // TODO: set initial persistant state // TODO: check for existing objects in context with same ObjectId - - + CAYObjEntity *objEntity = [[self entityResolver] objEntityForClass:[row class]]; + if(objEntity) + { + NSDictionary *relations = [objEntity relationships]; + NSEnumerator *enumerator = [relations keyEnumerator]; + NSString *relname; + while(relname = [enumerator nextObject]) + { + CAYClientObjRelationship *rel = (CAYClientObjRelationship *)[relations objectForKey:relname]; + NSLog(@"create fault for relation named %@: %@", relname, rel); + CAYFault *fault = nil; + if([rel isToMany]) + { + fault = [[CAYToManyFault alloc] initWithSourceObject:row relationshipName:relname]; + } + else + { + fault = [[CAYToOneFault alloc] initWithSourceObject:row relationshipName:relname]; + } + [[row valuesRaw] setValue:fault forKey:relname]; + [fault release]; + } + } + else + { + NSLog(@"ERROR: Could not find ObjEntity for class %@", [row class]); + } } } @@ -64,7 +94,6 @@ NSLog(@"prop %@ changed from %@ to %@", property, oldValue, newValue); CAYNodeDiff *diff = [[CAYNodePropertyChangeOperation alloc] initWithNodeId:[object objectId] property:property oldValue:oldValue newValue:newValue]; - //CAYNodePropertyChangeOperation *diff = [[CAYNodePropertyChangeOperation alloc] initWithNodeId:[object objectId] property:property oldValue:oldValue newValue:newValue]; [diffs addObject:diff]; [diff release]; NSLog(@"%i unsaved changes", [diffs count]); Modified: incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYPersistentObject.h URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYPersistentObject.h?rev=437466&r1=437465&r2=437466&view=diff ============================================================================== --- incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYPersistentObject.h (original) +++ incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYPersistentObject.h Sun Aug 27 14:56:04 2006 @@ -24,5 +24,7 @@ -(void)setObjectContext:(CAYObjectContext *)ctxt; -(CAYObjectContext *)objectContext; +// used for raw access to the value dictionary. use with care! +-(NSMutableDictionary *)valuesRaw; @end Modified: incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYPersistentObject.m URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYPersistentObject.m?rev=437466&r1=437465&r2=437466&view=diff ============================================================================== --- incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYPersistentObject.m (original) +++ incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYPersistentObject.m Sun Aug 27 14:56:04 2006 @@ -68,6 +68,11 @@ return result; } +-(NSMutableDictionary *)valuesRaw +{ + return values; +} + -(void)dealloc { [objectId release]; Modified: incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYQueryMessage.h URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYQueryMessage.h?rev=437466&r1=437465&r2=437466&view=diff ============================================================================== --- incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYQueryMessage.h (original) +++ incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYQueryMessage.h Sun Aug 27 14:56:04 2006 @@ -12,7 +12,6 @@ @interface CAYQueryMessage : CAYClientMessage <NSCoding> { CAYQuery *query; - //id *query; } -(void)setQuery:(CAYQuery *)q; Modified: incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYQueryMessage.m URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYQueryMessage.m?rev=437466&r1=437465&r2=437466&view=diff ============================================================================== --- incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYQueryMessage.m (original) +++ incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYQueryMessage.m Sun Aug 27 14:56:04 2006 @@ -35,7 +35,6 @@ return query; } - -(void)dealloc { [self setQuery:nil]; Modified: incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYToManyFault.m URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYToManyFault.m?rev=437466&r1=437465&r2=437466&view=diff ============================================================================== --- incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYToManyFault.m (original) +++ incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYToManyFault.m Sun Aug 27 14:56:04 2006 @@ -7,8 +7,27 @@ // #import "CAYToManyFault.h" - +#import "CAYFault.h" +#import "CAYRelationshipQuery.h" +#import "CAYObjectContext.h" @implementation CAYToManyFault + +-(id)resolveFault +{ + NSLog(@"resolving toMany fault"); + + CAYRelationshipQuery *q = [[CAYRelationshipQuery alloc] init]; + [q setObjectId:[[self sourceObject] objectId]]; + [q setRelationshipName:[self relationshipName]]; + + CAYObjectContext *ctxt = [[self sourceObject] objectContext]; + NSArray *rows = (NSArray *)[ctxt performQyery:q]; + + // TODO: create a collection that will autoadd new objects to the context? check with Core Data + + [q release]; + return rows; +} @end Modified: incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYToOneFault.m URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYToOneFault.m?rev=437466&r1=437465&r2=437466&view=diff ============================================================================== --- incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYToOneFault.m (original) +++ incubator/cayenne/sandbox/CocoaCayenne/CAYClient/CAYToOneFault.m Sun Aug 27 14:56:04 2006 @@ -7,8 +7,34 @@ // #import "CAYToOneFault.h" - +#import "CAYFault.h" +#import "CAYRelationshipQuery.h" +#import "CAYObjectContext.h" @implementation CAYToOneFault + +-(id)resolveFault +{ + NSLog(@"resolving toOne fault"); + + CAYRelationshipQuery *q = [[CAYRelationshipQuery alloc] init]; + [q setObjectId:[[self sourceObject] objectId]]; + [q setRelationshipName:[self relationshipName]]; + + CAYObjectContext *ctxt = [[self sourceObject] objectContext]; + NSArray *rows = (NSArray *)[ctxt performQyery:q]; + CAYPersistentObject *row = nil; + if([rows count] == 1) + { + row = (CAYPersistentObject *)[rows objectAtIndex:0]; + } + else + { + NSLog(@"ERROR: toOne fault resolve returned %i rows", [rows count]); + } + + [q release]; + return row; +} @end Modified: incubator/cayenne/sandbox/CocoaCayenne/CAYClient/English.lproj/MainMenu.nib/keyedobjects.nib URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CAYClient/English.lproj/MainMenu.nib/keyedobjects.nib?rev=437466&r1=437465&r2=437466&view=diff ============================================================================== Binary files - no diff available. Modified: incubator/cayenne/sandbox/CocoaCayenne/CAYClient/Painting.h URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CAYClient/Painting.h?rev=437466&r1=437465&r2=437466&view=diff ============================================================================== --- incubator/cayenne/sandbox/CocoaCayenne/CAYClient/Painting.h (original) +++ incubator/cayenne/sandbox/CocoaCayenne/CAYClient/Painting.h Sun Aug 27 14:56:04 2006 @@ -13,4 +13,7 @@ } +-(void)setName:(NSString *)n; +-(NSString *)name; + @end Modified: incubator/cayenne/sandbox/CocoaCayenne/CAYClient/Painting.m URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CAYClient/Painting.m?rev=437466&r1=437465&r2=437466&view=diff ============================================================================== --- incubator/cayenne/sandbox/CocoaCayenne/CAYClient/Painting.m (original) +++ incubator/cayenne/sandbox/CocoaCayenne/CAYClient/Painting.m Sun Aug 27 14:56:04 2006 @@ -11,4 +11,28 @@ @implementation Painting +-(id)initWithCoder:(NSCoder*)coder +{ + [super initWithCoder:coder]; + [values setObject:[coder decodeObjectForKey:@"name"] forKey:@"name"]; + return self; +} + +-(void)encodeWithCoder:(NSCoder*)coder +{ + [super encodeWithCoder:coder]; + [coder encodeObject:[values valueForKey:@"name"] forKey:@"name"]; +} + +-(void)setName:(NSString *)n +{ + [[self objectContext] propertyChanged:self forProperty:@"name" fromOld:[values objectForKey:@"name"] toNew:n]; + [values setObject:n forKey:@"name"]; +} + +-(NSString *)name +{ + return [values objectForKey:@"name"]; +} + @end
