cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From torehal...@apache.org
Subject svn commit: r440455 - in /incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne: ./ CocoaCayenne.xcodeproj/
Date Tue, 05 Sep 2006 19:31:43 GMT
Author: torehalset
Date: Tue Sep  5 12:31:41 2006
New Revision: 440455

URL: http://svn.apache.org/viewvc?view=rev&rev=440455
Log:
more work on relationship handling++

Removed:
    incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYManagedArray.h
    incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYManagedArray.m
Modified:
    incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYArcCreateOperation.m
    incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYArcDeleteOperation.m
    incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYClientObjRelationship.h
    incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYClientObjRelationship.m
    incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYEntityResolver.h
    incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYEntityResolver.m
    incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYFault.m
    incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYNodeCreateOperation.m
    incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYNodeDeleteOperation.m
    incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYNodePropertyChangeOperation.m
    incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjEntity.h
    incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjEntity.m
    incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectContext.h
    incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectContext.m
    incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectId.m
    incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYPersistentObject.h
    incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYPersistentObject.m
    incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYToManyFault.m
    incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CocoaCayenne.xcodeproj/project.pbxproj

Modified: incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYArcCreateOperation.m
URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYArcCreateOperation.m?view=diff&rev=440455&r1=440454&r2=440455
==============================================================================
--- incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYArcCreateOperation.m (original)
+++ incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYArcCreateOperation.m Tue Sep  5
12:31:41 2006
@@ -72,6 +72,14 @@
     return arcId;
 }
 
+-(NSString *)description
+{
+    NSString *result;
+    result = [[NSString alloc] initWithFormat:@"CAYArcCreateOperation {nodeId = %@; arcId
= %@; targetNodeId = %@ }", [self nodeId], [self arcId], [self targetNodeId]];
+    [result autorelease];
+    return result;
+}
+
 -(void)dealloc
 {
 	[self setTargetNodeId:nil];

Modified: incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYArcDeleteOperation.m
URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYArcDeleteOperation.m?view=diff&rev=440455&r1=440454&r2=440455
==============================================================================
--- incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYArcDeleteOperation.m (original)
+++ incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYArcDeleteOperation.m Tue Sep  5
12:31:41 2006
@@ -72,6 +72,14 @@
     return arcId;
 }
 
+-(NSString *)description
+{
+    NSString *result;
+    result = [[NSString alloc] initWithFormat:@"CAYArcDeleteOperation {nodeId = %@; arcId
= %@; targetNodeId = %@ }", [self nodeId], [self arcId], [self targetNodeId]];
+    [result autorelease];
+    return result;
+}
+
 -(void)dealloc
 {
 	[self setTargetNodeId:nil];

Modified: incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYClientObjRelationship.h
URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYClientObjRelationship.h?view=diff&rev=440455&r1=440454&r2=440455
==============================================================================
--- incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYClientObjRelationship.h (original)
+++ incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYClientObjRelationship.h Tue Sep
 5 12:31:41 2006
@@ -25,14 +25,16 @@
 	BOOL toMany;
 	NSString *name;
 	NSString *targetEntityName;
+    NSString *reverseRelationshipName;
 	
 }
 
 -(void)setName:(NSString *)n;
 -(NSString *)name;
+-(void)setReverseRelationshipName:(NSString *)n;
+-(NSString *)reverseRelationshipName;
 -(void)setTargetEntityName:(NSString *)n;
 -(NSString *)targetEntityName;
 -(BOOL)isToMany;
-
 
 @end

Modified: incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYClientObjRelationship.m
URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYClientObjRelationship.m?view=diff&rev=440455&r1=440454&r2=440455
==============================================================================
--- incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYClientObjRelationship.m (original)
+++ incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYClientObjRelationship.m Tue Sep
 5 12:31:41 2006
@@ -29,6 +29,7 @@
 	toMany = [coder decodeBoolForKey:@"clientToMany"];
 	[self setName:[coder decodeObjectForKey:@"name"]];
 	[self setTargetEntityName:[coder decodeObjectForKey:@"targetEntityName"]];
+	[self setReverseRelationshipName:[coder decodeObjectForKey:@"reverseRelationshipName"]];
 	return self;
 }
 
@@ -38,6 +39,7 @@
 	[coder encodeBool:toMany forKey:@"clientToMany"];
 	[coder encodeObject:name forKey:@"name"];
 	[coder encodeObject:targetEntityName forKey:@"targetEntityName"];
+	[coder encodeObject:reverseRelationshipName forKey:@"reverseRelationshipName"];
 }
 
 -(void)setName:(NSString *)n
@@ -52,6 +54,18 @@
 	return name;
 }
 
+-(void)setReverseRelationshipName:(NSString *)n
+{
+    [n retain];
+    [reverseRelationshipName release];
+    reverseRelationshipName = n;
+}
+
+-(NSString *)reverseRelationshipName
+{
+    return reverseRelationshipName;
+}
+
 -(void)setTargetEntityName:(NSString *)n
 {
 	[n retain];
@@ -69,10 +83,21 @@
     return toMany;
 }
 
+/*
+-(NSString *)description
+{
+    NSString *result;
+    result = [[NSString alloc] initWithFormat:@"CAYClientObjRelationship {toMany = %@; name
= %@; targetEntityName = %@; reverseRelationshipName = %@}", [self class], [self isToMany],
[self name], [self targetEntityName], [self reverseRelationshipName]];
+    [result autorelease];
+    return result;
+}
+*/
+
 -(void)dealloc
 {
-	[name release];
-	[targetEntityName release];
+    [self setName:nil];
+    [self setTargetEntityName:nil];
+    [self setReverseRelationshipName:nil];
 	[super dealloc];
 }
 

Modified: incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYEntityResolver.h
URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYEntityResolver.h?view=diff&rev=440455&r1=440454&r2=440455
==============================================================================
--- incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYEntityResolver.h (original)
+++ incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYEntityResolver.h Tue Sep  5 12:31:41
2006
@@ -19,6 +19,9 @@
 
 #import <Cocoa/Cocoa.h>
 #import "CAYObjEntity.h"
+#import "CAYPersistentObject.h"
+
+@class CAYPersistentObject;
 
 @interface CAYEntityResolver : NSObject {
     NSArray *maps;
@@ -32,5 +35,6 @@
 
 -(void)updateClassMapping;
 -(CAYObjEntity *)objEntityForClass:(Class)cl;
+-(CAYObjEntity *)lookupObjEntity:(CAYPersistentObject *)dataObject;
 
 @end

Modified: incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYEntityResolver.m
URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYEntityResolver.m?view=diff&rev=440455&r1=440454&r2=440455
==============================================================================
--- incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYEntityResolver.m (original)
+++ incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYEntityResolver.m Tue Sep  5 12:31:41
2006
@@ -21,7 +21,6 @@
 #import "CAYDataMap.h"
 #import "CAYObjEntity.h"
 #import "CAYCocoaCayenne.h"
-#import <HessianObjC/BBSHessianObjC.h>
 
 @implementation CAYEntityResolver
 
@@ -98,12 +97,6 @@
             NSLog(@"Could not find cocoa class %@ for server class $@", [entity name], [entity
serverClassName]);
         }
     }
-    
-    // hack to update hessian proxy with latest class mapping. 
-    // TODO: move to hessian connection 
-    //[BBSHessianProxy setClassMapping:[self classMapping]];
-
-    //[self setClassMapping:cm];
 }
 
 -(CAYObjEntity *)objEntityForClass:(Class)cl
@@ -127,6 +120,11 @@
     }
     
     return nil;
+}
+
+-(CAYObjEntity *)lookupObjEntity:(CAYPersistentObject *)dataObject
+{
+    return [self objEntityForClass:[dataObject class]];
 }
 
 -(void)dealloc

Modified: incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYFault.m
URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYFault.m?view=diff&rev=440455&r1=440454&r2=440455
==============================================================================
--- incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYFault.m (original)
+++ incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYFault.m Tue Sep  5 12:31:41 2006
@@ -35,8 +35,9 @@
 
 -(void)setSourceObject:(CAYPersistentObject *)so
 {
-    [so retain];
-    [sourceObject release];
+    // source object will be our master
+    // [so retain];
+    // [sourceObject release];
     sourceObject = so;
 }
 

Modified: incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYNodeCreateOperation.m
URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYNodeCreateOperation.m?view=diff&rev=440455&r1=440454&r2=440455
==============================================================================
--- incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYNodeCreateOperation.m (original)
+++ incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYNodeCreateOperation.m Tue Sep 
5 12:31:41 2006
@@ -32,4 +32,12 @@
     [super encodeWithCoder:coder];
 }
 
+-(NSString *)description
+{
+    NSString *result;
+    result = [[NSString alloc] initWithFormat:@"CAYNodeCreateOperation {nodeId = %@}", [self
nodeId]];
+    [result autorelease];
+    return result;
+}
+
 @end

Modified: incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYNodeDeleteOperation.m
URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYNodeDeleteOperation.m?view=diff&rev=440455&r1=440454&r2=440455
==============================================================================
--- incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYNodeDeleteOperation.m (original)
+++ incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYNodeDeleteOperation.m Tue Sep 
5 12:31:41 2006
@@ -33,4 +33,12 @@
     [super encodeWithCoder:coder];
 }
 
+-(NSString *)description
+{
+    NSString *result;
+    result = [[NSString alloc] initWithFormat:@"CAYNodeDeleteOperation {nodeId = %@}", [self
nodeId]];
+    [result autorelease];
+    return result;
+}
+
 @end

Modified: incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYNodePropertyChangeOperation.m
URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYNodePropertyChangeOperation.m?view=diff&rev=440455&r1=440454&r2=440455
==============================================================================
--- incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYNodePropertyChangeOperation.m (original)
+++ incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYNodePropertyChangeOperation.m Tue
Sep  5 12:31:41 2006
@@ -91,6 +91,14 @@
     return newValue;
 }
 
+-(NSString *)description
+{
+    NSString *result;
+    result = [[NSString alloc] initWithFormat:@"CAYNodePropertyChangeOperation {nodeId =
%@; property = %@; oldValue = %@; newValue = %@}", [self nodeId], [self property], [self oldValue],
[self newValue]];
+    [result autorelease];
+    return result;
+}
+
 -(void)dealloc
 {
 	[property release];

Modified: incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjEntity.h
URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjEntity.h?view=diff&rev=440455&r1=440454&r2=440455
==============================================================================
--- incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjEntity.h (original)
+++ incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjEntity.h Tue Sep  5 12:31:41
2006
@@ -22,15 +22,15 @@
 
 @interface CAYObjEntity : NSObject <NSCoding> {
 
-	NSArray *attributes;
+	NSMutableDictionary *attributes;
 	NSString *name;
     NSString *serverClassName;
 	NSMutableDictionary *relationships;
 	
 }
 
--(void)setAttributes:(NSArray *)a;
--(NSArray *)attributes;
+-(void)setAttributes:(NSMutableDictionary *)a;
+-(NSMutableDictionary *)attributes;
 -(void)setName:(NSString *)n;
 -(NSString *)name;
 -(void)setServerClassName:(NSString *)n;

Modified: incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjEntity.m
URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjEntity.m?view=diff&rev=440455&r1=440454&r2=440455
==============================================================================
--- incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjEntity.m (original)
+++ incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjEntity.m Tue Sep  5 12:31:41
2006
@@ -33,7 +33,7 @@
     // remove extra entry created by hessian framework
     // TODO: fix in framework?
     [[self relationships] removeObjectForKey:@"hessianClassName"];
-    
+    [[self attributes] removeObjectForKey:@"hessianClassName"];
     
 	return self;
 }
@@ -46,14 +46,14 @@
 	[coder encodeObject:relationships forKey:@"relationships"];
 }
 
--(void)setAttributes:(NSArray *)a
+-(void)setAttributes:(NSMutableDictionary *)a
 {
 	[a retain];
 	[attributes release];
 	attributes = a;
 }
 
--(NSArray *)attributes
+-(NSMutableDictionary *)attributes
 {
 	return attributes;
 }

Modified: incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectContext.h
URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectContext.h?view=diff&rev=440455&r1=440454&r2=440455
==============================================================================
--- incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectContext.h (original)
+++ incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectContext.h Tue Sep  5 12:31:41
2006
@@ -22,7 +22,7 @@
 #import "CAYEntityResolver.h"
 #import "CAYPersistentObject.h"
 
-@class CAYPersistentObject, CAYClientConnection, CAYPersistentObject;
+@class CAYPersistentObject, CAYClientConnection, CAYPersistentObject, CAYEntityResolver;
 
 @interface CAYObjectContext : NSObject {
 	CAYClientConnection *connection;
@@ -37,6 +37,7 @@
 -(CAYClientConnection *)connection;
 
 -(void) propertyChanged:(CAYPersistentObject *)object forProperty:(NSString *)property fromOld:(NSObject
*)oldValue toNew:(NSObject *)newValue;
+-(void) arcPropertyChanged:(CAYPersistentObject *)object forProperty:(NSString *)property
fromOld:(NSObject *)oldValue toNew:(NSObject *)newValue;
 
 -(void)commitChanges;
 

Modified: incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectContext.m
URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectContext.m?view=diff&rev=440455&r1=440454&r2=440455
==============================================================================
--- incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectContext.m (original)
+++ incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectContext.m Tue Sep  5 12:31:41
2006
@@ -34,6 +34,8 @@
 #import "CAYNodeDeleteOperation.h"
 #import "CAYCocoaCayenne.h"
 #import "CAYBootstrapMessage.h"
+#import "CAYArcCreateOperation.h"
+#import "CAYArcDeleteOperation.h"
 
 @implementation CAYObjectContext
 
@@ -82,7 +84,6 @@
         
             [row setObjectContext:self];
             // TODO: set initial persistant state
-            // TODO: check for existing objects in context with same ObjectId
             
             CAYObjEntity *objEntity = [[self entityResolver] objEntityForClass:[row class]];
             if(objEntity)
@@ -130,6 +131,29 @@
     NSLog(@"%i unsaved changes", [diffs count]);
 }
 
+-(void) arcPropertyChanged:(CAYPersistentObject *)object forProperty:(NSString *)property
fromOld:(NSObject *)oldValue toNew:(NSObject *)newValue
+{
+    NSLog(@"arc prop %@ changed from %@ to %@", property, oldValue, newValue);
+    
+    if([oldValue isKindOfClass:[CAYPersistentObject class]])
+    {
+        NSLog(@"add a arcDelete");
+        CAYPersistentObject *ov = (CAYPersistentObject *)oldValue;
+        CAYArcDeleteOperation *diff = [[CAYArcDeleteOperation alloc] initWithNodeId:[object
objectId] targetNodeId:[ov objectId] arcId:property];
+        [diffs addObject:diff];
+        [diff release];
+    }
+
+    if([newValue isKindOfClass:[CAYPersistentObject class]])
+    {
+        NSLog(@"add a arcCreate");
+        CAYPersistentObject *nv = (CAYPersistentObject *)newValue;
+        CAYArcCreateOperation *diff = [[CAYArcCreateOperation alloc] initWithNodeId:[object
objectId] targetNodeId:[nv objectId] arcId:property];
+        [diffs addObject:diff];
+        [diff release];
+    }
+}
+
 -(void)setConnection:(CAYClientConnection *)c
 {
 	[c retain];
@@ -163,7 +187,7 @@
 
 -(void)commitChanges
 {
-    NSLog(@"%i unsaved changes before commit", [diffs count]);
+    NSLog(@"%i unsaved changes before commit. %@", [diffs count], diffs);
     CAYCompoundDiff *diffWithDiffs = [[CAYCompoundDiff alloc] initWithDiffs:diffs];
     // TODO: handle different types?
     CAYSyncMessage *msg = [[CAYSyncMessage alloc] initWithObjectSource:nil type:2 senderChanges:diffWithDiffs];
@@ -212,13 +236,14 @@
     {
         randombytes[i] = rand();
     }
-    NSData *randomdata = [[NSData alloc] initWithBytesNoCopy:&randombytes length:8];
+    NSData *randomdata = [[NSData alloc] initWithBytes:&randombytes length:8];
     
     CAYObjectId *oid = [[CAYObjectId alloc] init];
     CAYObjEntity *objEntity = [[self entityResolver] objEntityForClass:[o class]];
     [oid setEntityName:[objEntity name]];
     [oid setTempKey:randomdata];
     [o setObjectId:oid];
+    [randomdata release];
     
     CAYNodeDiff *diff = [[CAYNodeCreateOperation alloc] initWithNodeId:oid];
     [diffs addObject:diff];
@@ -226,9 +251,8 @@
     
     [objectByObjectId setObject:o forKey:oid];
     
-    // TODO: init values with NSNull objects?
-    
-    NSEnumerator *enumerator = [[objEntity attributes] objectEnumerator];
+    // init values with NSNull objects
+    NSEnumerator *enumerator = [[objEntity attributes] keyEnumerator];
     NSString *attribute;
     while(attribute = [enumerator nextObject])
     {
@@ -239,6 +263,8 @@
             [[o valuesRaw] setObject:[NSNull null] forKey:attribute];
         }
     }
+    
+    // TODO: init relationship values to NSNull as well?
     
     [randomdata release];
     [oid release];

Modified: incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectId.m
URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectId.m?view=diff&rev=440455&r1=440454&r2=440455
==============================================================================
--- incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectId.m (original)
+++ incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectId.m Tue Sep  5 12:31:41
2006
@@ -190,7 +190,19 @@
 -(NSString *)description
 {
     NSString *result;
-    result = [[NSString alloc] initWithFormat:@"CAYObjectId {entityName = %@; objectIdKeys
= %@; singleKey = %@; singleValue = %@; tempKey = %@}", [self entityName], [self objectIdKeys],
[self singleKey], [self singleValue], [self tempKey]];
+    if([self tempKey])
+    {
+        result = [[NSString alloc] initWithFormat:@"CAYObjectId {entityName = %@; tempKey
= %@}", [self entityName], [self tempKey]];
+    }
+    else if ([self singleKey])
+    {
+        result = [[NSString alloc] initWithFormat:@"CAYObjectId {entityName = %@; singleKey
= %@; singleValue = %@}", [self entityName], [self singleKey], [self singleValue]];
+    }
+    else
+    {
+        // should match one of the above. if not, output all values
+        result = [[NSString alloc] initWithFormat:@"CAYObjectId {entityName = %@; objectIdKeys
= %@; singleKey = %@; singleValue = %@; tempKey = %@}", [self entityName], [self objectIdKeys],
[self singleKey], [self singleValue], [self tempKey]];
+    }
     [result autorelease];
     return result;
 }

Modified: incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYPersistentObject.h
URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYPersistentObject.h?view=diff&rev=440455&r1=440454&r2=440455
==============================================================================
--- incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYPersistentObject.h (original)
+++ incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYPersistentObject.h Tue Sep  5 12:31:41
2006
@@ -21,7 +21,7 @@
 #import "CAYObjectId.h"
 #import "CAYObjectContext.h"
 
-@class CAYObjectContext;
+@class CAYObjectContext, CAYPersistentObject;
 
 @interface CAYPersistentObject : NSObject <NSCoding> {
 	CAYObjectId *objectId;

Modified: incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYPersistentObject.m
URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYPersistentObject.m?view=diff&rev=440455&r1=440454&r2=440455
==============================================================================
--- incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYPersistentObject.m (original)
+++ incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYPersistentObject.m Tue Sep  5 12:31:41
2006
@@ -21,7 +21,8 @@
 #import "CAYObjectId.h"
 #import "CAYObjectContext.h"
 #import "CAYFault.h"
-
+#import "CAYObjEntity.h"
+#import "CAYClientObjRelationship.h"
 
 @implementation CAYPersistentObject
 
@@ -99,25 +100,70 @@
 {
     NSLog(@"set value %@ for key %@ of type %@", value, key, [value class]);
     
-    if([value isKindOfClass:[NSArray class]])
+    // see if the key is a relationship
+    CAYObjEntity *objEntity = [[[self objectContext] entityResolver] lookupObjEntity:self];
+    CAYClientObjRelationship *relationship = [[objEntity relationships] valueForKey:key];
+    
+    //if([value isKindOfClass:[NSArray class]])
+    if (relationship)
     {
-        NSEnumerator *enumerator = [value objectEnumerator];
-        // TODO: handle and give error if not CAYPersistentObject
-        CAYPersistentObject *element;
-        while(element = [enumerator nextObject])
+        
+        if ([relationship isToMany])
         {
-            if(![element objectContext])
+            // check that arg are NSArray
+            if(![value isKindOfClass:[NSArray class]])
+            {
+                NSLog(@"ERROR: toMany argument should be of type NSArray, not %@", [value
class]);
+            }
+            
+            NSEnumerator *enumerator = [value objectEnumerator];
+            // TODO: handle and give error if not CAYPersistentObject
+            CAYPersistentObject *element;
+            while(element = [enumerator nextObject])
             {
-                [[self objectContext] registerNewObject:element];
-                // TODO: set relation both ways
+                
+                // find reverse relationship. could be nil.
+                // CAYObjEntity *revObjEntity = [[[self objectContext] entityResolver] lookupObjEntity:element];
+                // CAYClientObjRelationship *revRelationship = [[revObjEntity relationships]
valueForKey:[relationship reverseRelationshipName]];
+                
+                if(![element objectContext])
+                {
+                    [[self objectContext] registerNewObject:element];
+                    
+                    // TODO: set relation both ways
+                    [[self objectContext] arcPropertyChanged:self forProperty:key fromOld:nil
toNew:element];
+                    [[self objectContext] arcPropertyChanged:element forProperty:[relationship
reverseRelationshipName] fromOld:nil toNew:self];
+                    // TODO: or perhaps use 'element's setValue:forKey? could lead to infinite
loop..
+                }
             }
+            // TODO: check for new objects that have a objectContext
+            // TODO: check for objects that are not present any more
         }
-        // TODO: check for objects that are not present any more
+        else 
+        {
+            // check that arg are CAYPersistentObject
+            if(![value isKindOfClass:[CAYPersistentObject class]])
+            {
+                NSLog(@"ERROR: toMany argument should be of type CAYPersistentObject, not
%@", [value class]);
+            }
+            
+            // a to one relationship
+            [[self objectContext] arcPropertyChanged:self forProperty:key fromOld:[values
objectForKey:key] toNew:value];
+            
+            // find reverse relationship. could be nil.
+            // CAYObjEntity *revObjEntity = [[[self objectContext] entityResolver] lookupObjEntity:value];
+            // CAYClientObjRelationship *revRelationship = [[revObjEntity relationships]
valueForKey:[relationship reverseRelationshipName]];
+        }
+        
+        // handle reverse relationship
+        // TODO: handle reverse relationship without creating a neverending loop...
     }
-
-    // TODO: is this for simple properties only? not for relations?
-    [[self objectContext] propertyChanged:self forProperty:key fromOld:[values objectForKey:key]
toNew:value];
-
+    else
+    {
+        // a none-relationship property
+        [[self objectContext] propertyChanged:self forProperty:key fromOld:[values objectForKey:key]
toNew:value];
+    }
+    
     [values setValue:value forKey:key];
 }
 

Modified: incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYToManyFault.m
URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYToManyFault.m?view=diff&rev=440455&r1=440454&r2=440455
==============================================================================
--- incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYToManyFault.m (original)
+++ incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYToManyFault.m Tue Sep  5 12:31:41
2006
@@ -21,7 +21,6 @@
 #import "CAYFault.h"
 #import "CAYRelationshipQuery.h"
 #import "CAYObjectContext.h"
-#import "CAYManagedArray.h"
 
 @implementation CAYToManyFault
 
@@ -36,14 +35,7 @@
     CAYObjectContext *ctxt = [[self sourceObject] objectContext];
     NSArray *rows = (NSArray *)[ctxt performQuery:q];
     [q release];
-    //return rows;
-    
-    // TODO: create a collection that will autoadd new objects to the context? check with
Core Data
-    CAYManagedArray *managedRows = [[CAYManagedArray alloc] init];
-    [managedRows setArray:rows];
-    [managedRows setObjectContext:ctxt];
-    
-    return [managedRows autorelease];
+    return rows;
 }
 
 @end

Modified: incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CocoaCayenne.xcodeproj/project.pbxproj
URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CocoaCayenne.xcodeproj/project.pbxproj?view=diff&rev=440455&r1=440454&r2=440455
==============================================================================
--- incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CocoaCayenne.xcodeproj/project.pbxproj
(original)
+++ incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CocoaCayenne.xcodeproj/project.pbxproj
Tue Sep  5 12:31:41 2006
@@ -63,11 +63,9 @@
 		4448AA440AA4C55F002C2FA7 /* CAYNodeDeleteOperation.m in Sources */ = {isa = PBXBuildFile;
fileRef = 4448AA420AA4C55F002C2FA7 /* CAYNodeDeleteOperation.m */; };
 		444DA8050AA61E54006E1768 /* CAYCocoaCayenne.h in Headers */ = {isa = PBXBuildFile; fileRef
= 444DA8030AA61E54006E1768 /* CAYCocoaCayenne.h */; settings = {ATTRIBUTES = (Public, ); };
};
 		444DA8060AA61E54006E1768 /* CAYCocoaCayenne.m in Sources */ = {isa = PBXBuildFile; fileRef
= 444DA8040AA61E54006E1768 /* CAYCocoaCayenne.m */; };
-		444DA9FD0AA640B8006E1768 /* CAYManagedArray.h in Headers */ = {isa = PBXBuildFile; fileRef
= 444DA9FB0AA640B8006E1768 /* CAYManagedArray.h */; settings = {ATTRIBUTES = (Public, ); };
};
-		444DA9FE0AA640B8006E1768 /* CAYManagedArray.m in Sources */ = {isa = PBXBuildFile; fileRef
= 444DA9FC0AA640B8006E1768 /* CAYManagedArray.m */; };
-		444DAB190AACB74C006E1768 /* CAYArcCreateOperation.h in Headers */ = {isa = PBXBuildFile;
fileRef = 444DAB170AACB74C006E1768 /* CAYArcCreateOperation.h */; };
+		444DAB190AACB74C006E1768 /* CAYArcCreateOperation.h in Headers */ = {isa = PBXBuildFile;
fileRef = 444DAB170AACB74C006E1768 /* CAYArcCreateOperation.h */; settings = {ATTRIBUTES =
(Public, ); }; };
 		444DAB1A0AACB74C006E1768 /* CAYArcCreateOperation.m in Sources */ = {isa = PBXBuildFile;
fileRef = 444DAB180AACB74C006E1768 /* CAYArcCreateOperation.m */; };
-		444DAB270AACB7B1006E1768 /* CAYArcDeleteOperation.h in Headers */ = {isa = PBXBuildFile;
fileRef = 444DAB250AACB7B1006E1768 /* CAYArcDeleteOperation.h */; };
+		444DAB270AACB7B1006E1768 /* CAYArcDeleteOperation.h in Headers */ = {isa = PBXBuildFile;
fileRef = 444DAB250AACB7B1006E1768 /* CAYArcDeleteOperation.h */; settings = {ATTRIBUTES =
(Public, ); }; };
 		444DAB280AACB7B1006E1768 /* CAYArcDeleteOperation.m in Sources */ = {isa = PBXBuildFile;
fileRef = 444DAB260AACB7B1006E1768 /* CAYArcDeleteOperation.m */; };
 		44FE798F0AA3790C0040BB78 /* HessianObjC.framework in Frameworks */ = {isa = PBXBuildFile;
fileRef = 44FE798E0AA3790C0040BB78 /* HessianObjC.framework */; };
 		8DC2EF530486A6940098B216 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef
= 089C1666FE841158C02AAC07 /* InfoPlist.strings */; };
@@ -91,7 +89,7 @@
 		44463D6F0AA37577006BAA58 /* CAYClientMessage.h */ = {isa = PBXFileReference; fileEncoding
= 30; lastKnownFileType = sourcecode.c.h; path = CAYClientMessage.h; sourceTree = "<group>";
};
 		44463D700AA37577006BAA58 /* CAYClientMessage.m */ = {isa = PBXFileReference; fileEncoding
= 30; lastKnownFileType = sourcecode.c.objc; path = CAYClientMessage.m; sourceTree = "<group>";
};
 		44463D710AA37577006BAA58 /* CAYClientObjRelationship.h */ = {isa = PBXFileReference; fileEncoding
= 30; lastKnownFileType = sourcecode.c.h; path = CAYClientObjRelationship.h; sourceTree =
"<group>"; };
-		44463D720AA37577006BAA58 /* CAYClientObjRelationship.m */ = {isa = PBXFileReference; fileEncoding
= 30; lastKnownFileType = sourcecode.c.objc; path = CAYClientObjRelationship.m; sourceTree
= "<group>"; };
+		44463D720AA37577006BAA58 /* CAYClientObjRelationship.m */ = {isa = PBXFileReference; fileEncoding
= 30; languageSpecificationIdentifier = c.objc; lastKnownFileType = sourcecode.c.objc; path
= CAYClientObjRelationship.m; sourceTree = "<group>"; wrapsLines = 0; };
 		44463D730AA37577006BAA58 /* CAYCompoundDiff.h */ = {isa = PBXFileReference; fileEncoding
= 30; lastKnownFileType = sourcecode.c.h; path = CAYCompoundDiff.h; sourceTree = "<group>";
};
 		44463D740AA37577006BAA58 /* CAYCompoundDiff.m */ = {isa = PBXFileReference; fileEncoding
= 30; lastKnownFileType = sourcecode.c.objc; path = CAYCompoundDiff.m; sourceTree = "<group>";
};
 		44463D750AA37577006BAA58 /* CAYDataMap.h */ = {isa = PBXFileReference; fileEncoding = 30;
lastKnownFileType = sourcecode.c.h; path = CAYDataMap.h; sourceTree = "<group>"; };
@@ -136,8 +134,6 @@
 		4448AA420AA4C55F002C2FA7 /* CAYNodeDeleteOperation.m */ = {isa = PBXFileReference; fileEncoding
= 4; lastKnownFileType = sourcecode.c.objc; path = CAYNodeDeleteOperation.m; sourceTree =
"<group>"; };
 		444DA8030AA61E54006E1768 /* CAYCocoaCayenne.h */ = {isa = PBXFileReference; fileEncoding
= 4; lastKnownFileType = sourcecode.c.h; path = CAYCocoaCayenne.h; sourceTree = "<group>";
};
 		444DA8040AA61E54006E1768 /* CAYCocoaCayenne.m */ = {isa = PBXFileReference; fileEncoding
= 4; lastKnownFileType = sourcecode.c.objc; path = CAYCocoaCayenne.m; sourceTree = "<group>";
};
-		444DA9FB0AA640B8006E1768 /* CAYManagedArray.h */ = {isa = PBXFileReference; fileEncoding
= 4; lastKnownFileType = sourcecode.c.h; path = CAYManagedArray.h; sourceTree = "<group>";
};
-		444DA9FC0AA640B8006E1768 /* CAYManagedArray.m */ = {isa = PBXFileReference; fileEncoding
= 4; lastKnownFileType = sourcecode.c.objc; path = CAYManagedArray.m; sourceTree = "<group>";
};
 		444DAB170AACB74C006E1768 /* CAYArcCreateOperation.h */ = {isa = PBXFileReference; fileEncoding
= 4; lastKnownFileType = sourcecode.c.h; path = CAYArcCreateOperation.h; sourceTree = "<group>";
};
 		444DAB180AACB74C006E1768 /* CAYArcCreateOperation.m */ = {isa = PBXFileReference; fileEncoding
= 4; lastKnownFileType = sourcecode.c.objc; path = CAYArcCreateOperation.m; sourceTree = "<group>";
};
 		444DAB250AACB7B1006E1768 /* CAYArcDeleteOperation.h */ = {isa = PBXFileReference; fileEncoding
= 4; lastKnownFileType = sourcecode.c.h; path = CAYArcDeleteOperation.h; sourceTree = "<group>";
};
@@ -203,7 +199,6 @@
 		08FB77AEFE84172EC02AAC07 /* Classes */ = {
 			isa = PBXGroup;
 			children = (
-				444DA9FA0AA6409E006E1768 /* collection */,
 				444DA8AC0AA62727006E1768 /* connection */,
 				44463DCB0AA3757F006BAA58 /* fault */,
 				44463DCC0AA37586006BAA58 /* message */,
@@ -334,15 +329,6 @@
 			name = connection;
 			sourceTree = "<group>";
 		};
-		444DA9FA0AA6409E006E1768 /* collection */ = {
-			isa = PBXGroup;
-			children = (
-				444DA9FB0AA640B8006E1768 /* CAYManagedArray.h */,
-				444DA9FC0AA640B8006E1768 /* CAYManagedArray.m */,
-			);
-			name = collection;
-			sourceTree = "<group>";
-		};
 /* End PBXGroup section */
 
 /* Begin PBXHeadersBuildPhase section */
@@ -378,7 +364,6 @@
 				4448AA430AA4C55F002C2FA7 /* CAYNodeDeleteOperation.h in Headers */,
 				4421E61E0AA4EE2D00FBE975 /* CAYNodeIdChangeOperation.h in Headers */,
 				444DA8050AA61E54006E1768 /* CAYCocoaCayenne.h in Headers */,
-				444DA9FD0AA640B8006E1768 /* CAYManagedArray.h in Headers */,
 				444DAB190AACB74C006E1768 /* CAYArcCreateOperation.h in Headers */,
 				444DAB270AACB7B1006E1768 /* CAYArcDeleteOperation.h in Headers */,
 			);
@@ -466,7 +451,6 @@
 				4448AA440AA4C55F002C2FA7 /* CAYNodeDeleteOperation.m in Sources */,
 				4421E61F0AA4EE2D00FBE975 /* CAYNodeIdChangeOperation.m in Sources */,
 				444DA8060AA61E54006E1768 /* CAYCocoaCayenne.m in Sources */,
-				444DA9FE0AA640B8006E1768 /* CAYManagedArray.m in Sources */,
 				444DAB1A0AACB74C006E1768 /* CAYArcCreateOperation.m in Sources */,
 				444DAB280AACB7B1006E1768 /* CAYArcDeleteOperation.m in Sources */,
 			);



Mime
View raw message