cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From torehal...@apache.org
Subject svn commit: r440474 - in /incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne: CAYObjectContext.m CAYObjectId.m CAYPersistentObject.h CAYPersistentObject.m
Date Tue, 05 Sep 2006 20:35:17 GMT
Author: torehalset
Date: Tue Sep  5 13:35:16 2006
New Revision: 440474

URL: http://svn.apache.org/viewvc?view=rev&rev=440474
Log:
persistent objects are now unique within a single context

Modified:
    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

Modified: incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectContext.m
URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectContext.m?view=diff&rev=440474&r1=440473&r2=440474
==============================================================================
--- incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectContext.m (original)
+++ incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectContext.m Tue Sep  5 13:35:16
2006
@@ -57,9 +57,14 @@
 	id result = [[self connection] sendMessage:queryMessage];
 	[queryMessage release];
     
+    // TODO: results/rows are a mess. clean up!
     NSArray *results = [result results];
 	NSArray *rows = [results objectAtIndex:0];
     
+    // create a new result array as we may use some old objects instead of the
+    // new ones.
+    NSMutableArray *resultRows = [[NSMutableArray alloc] initWithCapacity:[rows count]];
+    
     // connect objects to the context
     int n = [rows count];
     int i;
@@ -68,19 +73,24 @@
         id row = [rows objectAtIndex:i];
         if([row isKindOfClass:[CAYPersistentObject class]])
         {
-        
-            // try to look for old with same context
+            // try to look for old with same objectId in the context
             CAYPersistentObject *old = (CAYPersistentObject *)[objectByObjectId objectForKey:[row
objectId]];
             if(old)
             {
-                NSLog(@"old exist for oid %@", [row objectId]);
-                // TODO: copy new into old
+                NSLog(@"old exist for oid. merge over values. %@ == %@", [row objectId],
[old objectId]);
+                
+                // clear out old values and set new values
+                [[old valuesRaw] setDictionary:[row valuesRaw]];
+                row = old;
             }
             else
             {
                 NSLog(@"old does not exist for oid %@", [row objectId]);
                 [objectByObjectId setObject:row forKey:[row objectId]];
             }
+
+            // update resultRows as soon as possible
+            [resultRows addObject:row];
         
             [row setObjectContext:self];
             // TODO: set initial persistant state
@@ -112,13 +122,15 @@
             {
                 NSLog(@"ERROR: Could not find ObjEntity for class %@", [row class]);
             }
-            
-            
+        }
+        else
+        {
+            NSLog(@"ERROR: not able to handle returned row of type %@", [row class]);
         }
     }
     
-	NSLog(@"query rows: %@", rows);
-	return rows;
+	NSLog(@"query rows: %@", resultRows);
+	return [resultRows autorelease];
 }
 
 -(void) propertyChanged:(CAYPersistentObject *)object forProperty:(NSString *)property fromOld:(NSObject
*)oldValue toNew:(NSObject *)newValue

Modified: incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectId.m
URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectId.m?view=diff&rev=440474&r1=440473&r2=440474
==============================================================================
--- incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectId.m (original)
+++ incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectId.m Tue Sep  5 13:35:16
2006
@@ -37,6 +37,10 @@
         NSLog(@"HACK: switching tempKey from NSNull to nil");
         [self setTempKey:nil];
     }
+    else if([self tempKey])
+    {
+        NSLog(@"HACK: tempKey has value %@", [self tempKey]);
+    }
     
 	[self setReplacementIdMap:[coder decodeObjectForKey:@"replacementIdMap"]];
 	return self;
@@ -175,14 +179,24 @@
 	{
 		return NO;
 	}
-	if(([self singleKey] != nil)&&(![[self singleKey] isEqualToString:[anObject singleKey]])&&(![[self
singleValue] isEqual:[anObject singleValue]]))
-	{
-		return NO;
-	}
-	if(([self tempKey] != nil)&&(![[self tempKey] isEqualToData:[anObject tempKey]]))
-	{
-		return NO;
-	}
+    if([self singleKey])
+    {
+        if(![[self singleKey] isEqualToString:[anObject singleKey]])
+        {
+            return NO;
+        }
+        if(![[self singleValue] isEqual:[anObject singleValue]])
+        {
+            return NO;
+        }
+    }
+    if([self tempKey])
+    {
+        if(![[self tempKey] isEqualToData:[anObject tempKey]])
+        {
+            return NO;
+        }
+    }
 	// TODO: check all values
 	return YES;
 }

Modified: incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYPersistentObject.h
URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYPersistentObject.h?view=diff&rev=440474&r1=440473&r2=440474
==============================================================================
--- incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYPersistentObject.h (original)
+++ incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYPersistentObject.h Tue Sep  5 13:35:16
2006
@@ -26,7 +26,7 @@
 @interface CAYPersistentObject : NSObject <NSCoding> {
 	CAYObjectId *objectId;
 	unsigned int persistenceState;
-	id objectContext;
+	CAYObjectContext *objectContext;
     NSMutableDictionary *values;
 }
 
@@ -39,7 +39,7 @@
 
 -(NSMutableDictionary *)valuesRaw;
 
-- (void)setValue:(id)value forKey:(NSString *)key;
-- (id)valueForKey:(NSString *)key;
+-(void)setValue:(id)value forKey:(NSString *)key;
+-(id)valueForKey:(NSString *)key;
 
 @end

Modified: incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYPersistentObject.m
URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYPersistentObject.m?view=diff&rev=440474&r1=440473&r2=440474
==============================================================================
--- incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYPersistentObject.m (original)
+++ incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYPersistentObject.m Tue Sep  5 13:35:16
2006
@@ -73,8 +73,8 @@
 -(void)setObjectContext:(CAYObjectContext *)ctxt
 {
     // do not need to retain/release as ctxt is our master
-	//[ctxt retain];
-	//[objectContext release];
+	// [ctxt retain];
+	// [objectContext release];
 	objectContext = ctxt;
 }
 
@@ -96,7 +96,7 @@
     return values;
 }
 
-- (void)setValue:(id)value forKey:(NSString *)key
+-(void)setValue:(id)value forKey:(NSString *)key
 {
     NSLog(@"set value %@ for key %@ of type %@", value, key, [value class]);
     
@@ -104,7 +104,6 @@
     CAYObjEntity *objEntity = [[[self objectContext] entityResolver] lookupObjEntity:self];
     CAYClientObjRelationship *relationship = [[objEntity relationships] valueForKey:key];
     
-    //if([value isKindOfClass:[NSArray class]])
     if (relationship)
     {
         
@@ -167,7 +166,7 @@
     [values setValue:value forKey:key];
 }
 
-- (id)valueForKey:(NSString *)key
+-(id)valueForKey:(NSString *)key
 {
     id val = [values objectForKey:key];
     if([val isKindOfClass:[CAYFault class]])



Mime
View raw message