cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From torehal...@apache.org
Subject svn commit: r440898 - in /incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne: CAYCompoundDiff.h CAYCompoundDiff.m CAYNodeDiff.h CAYNodeDiff.m CAYNodeIdChangeOperation.m CAYObjectContext.m CAYObjectId.m
Date Wed, 06 Sep 2006 23:21:15 GMT
Author: torehalset
Date: Wed Sep  6 16:21:15 2006
New Revision: 440898

URL: http://svn.apache.org/viewvc?view=rev&rev=440898
Log:
able to apply CAYNodeIdChangeOperation localy

Modified:
    incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYCompoundDiff.h
    incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYCompoundDiff.m
    incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYNodeDiff.h
    incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYNodeDiff.m
    incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYNodeIdChangeOperation.m
    incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectContext.m
    incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectId.m

Modified: incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYCompoundDiff.h
URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYCompoundDiff.h?view=diff&rev=440898&r1=440897&r2=440898
==============================================================================
--- incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYCompoundDiff.h (original)
+++ incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYCompoundDiff.h Wed Sep  6 16:21:15
2006
@@ -18,9 +18,9 @@
  ****************************************************************/
 
 #import <Cocoa/Cocoa.h>
+#import "CAYNodeDiff.h"
 
-
-@interface CAYCompoundDiff : NSObject <NSCoding>  {
+@interface CAYCompoundDiff : CAYNodeDiff <NSCoding>  {
     NSMutableArray *diffs;
 }
 

Modified: incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYCompoundDiff.m
URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYCompoundDiff.m?view=diff&rev=440898&r1=440897&r2=440898
==============================================================================
--- incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYCompoundDiff.m (original)
+++ incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYCompoundDiff.m Wed Sep  6 16:21:15
2006
@@ -19,7 +19,6 @@
 
 #import "CAYCompoundDiff.h"
 
-
 @implementation CAYCompoundDiff
 
 -(id)initWithDiffs:(NSMutableArray *)ds
@@ -59,6 +58,19 @@
     result = [[NSString alloc] initWithFormat:@"CAYCompoundDiff {diffs = %@}", [self diffs]];
     [result autorelease];
     return result;
+}
+
+-(void)apply:(NSMutableDictionary *)objectStore
+{
+    if(![diffs isKindOfClass:[NSNull class]])
+    {
+        NSEnumerator *enumerator = [[self diffs] objectEnumerator];
+        CAYNodeDiff *diff = nil;
+        while(diff = [enumerator nextObject])
+        {
+            [diff apply:objectStore];
+        }
+    }
 }
 
 -(void)dealloc

Modified: incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYNodeDiff.h
URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYNodeDiff.h?view=diff&rev=440898&r1=440897&r2=440898
==============================================================================
--- incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYNodeDiff.h (original)
+++ incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYNodeDiff.h Wed Sep  6 16:21:15
2006
@@ -31,4 +31,7 @@
 -(void)setNodeId:(NSObject *)nid;
 -(NSObject *)nodeId;
 
+-(void)apply:(NSMutableDictionary *)objectStore;
+-(void)undo:(NSMutableDictionary *)objectStore;
+
 @end

Modified: incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYNodeDiff.m
URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYNodeDiff.m?view=diff&rev=440898&r1=440897&r2=440898
==============================================================================
--- incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYNodeDiff.m (original)
+++ incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYNodeDiff.m Wed Sep  6 16:21:15
2006
@@ -62,9 +62,19 @@
     return nodeId;
 }
 
+-(void)apply:(NSMutableDictionary *)objectStore
+{
+    NSLog(@"%@ does not implement apply:", [self class]);
+}
+
+-(void)undo:(NSMutableDictionary *)objectStore
+{
+    NSLog(@"%@ does not implement undo:", [self class]);
+}
+
 -(void)dealloc
 {
-	[nodeId release];
+	[self setNodeId:nil];
 	[super dealloc];
 }
 

Modified: incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYNodeIdChangeOperation.m
URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYNodeIdChangeOperation.m?view=diff&rev=440898&r1=440897&r2=440898
==============================================================================
--- incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYNodeIdChangeOperation.m (original)
+++ incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYNodeIdChangeOperation.m Wed Sep
 6 16:21:15 2006
@@ -18,7 +18,8 @@
  ****************************************************************/
 
 #import "CAYNodeIdChangeOperation.h"
-
+#import "CAYPersistentObject.h"
+#import "CAYObjectId.h"
 
 @implementation CAYNodeIdChangeOperation
 
@@ -46,6 +47,24 @@
 {
     return newNodeId;
 }
+
+-(void)apply:(NSMutableDictionary *)objectStore
+{
+    CAYPersistentObject *o = [objectStore objectForKey:[self nodeId]];
+    if(o)
+    {
+        [o setObjectId:(CAYObjectId *)[self newNodeId]];
+        // TODO: should probably remove old object, but it lead to a crash..
+        //[objectStore removeObjectForKey:[self nodeId]];
+        [objectStore setObject:o forKey:[self newNodeId]];
+        NSLog(@"object after %@: %@", self, o);
+    }
+    else
+    {
+        NSLog(@"ERROR: not able to find object with id %@. keys in object store: %@", [self
nodeId], [objectStore allKeys]);
+    }
+}
+
 
 -(NSString *)description
 {

Modified: incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectContext.m
URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectContext.m?view=diff&rev=440898&r1=440897&r2=440898
==============================================================================
--- incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectContext.m (original)
+++ incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectContext.m Wed Sep  6 16:21:15
2006
@@ -209,6 +209,18 @@
     NSLog(@"commit result: %@", result);
     [diffs removeAllObjects];
     
+    // apply any resulting diffs. typicaly server generated primary key values
+    // for new values
+    if([result isKindOfClass:[CAYNodeDiff class]])
+    {
+        CAYNodeDiff *resultDiff = (CAYNodeDiff *)result;
+        [resultDiff apply:objectByObjectId];
+    }
+    else
+    {
+        NSLog(@"ERROR: not able to handle commit result of type %@", [result class]);
+    }
+    
     [msg release];
     [diffWithDiffs release];
     NSLog(@"%i unsaved changes after commit", [diffs count]);

Modified: incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectId.m
URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectId.m?view=diff&rev=440898&r1=440897&r2=440898
==============================================================================
--- incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectId.m (original)
+++ incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectId.m Wed Sep  6 16:21:15
2006
@@ -153,28 +153,23 @@
 {
 	/*
 	 file:///Developer/ADC%20Reference%20Library/documentation/Cocoa/Reference/Foundation/Protocols/NSObject_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/NSObject/hash
-	 
 	 http://www.mulle-kybernetik.com/artikel/Optimization/opti-7.html
+     http://www.cocoabuilder.com/archive/message/cocoa/2003/12/18/546
 	 */
-	// TODO: implement!
-	// TODO: be smart about how to build hash value
-	unsigned hash = 17;
-	hash = hash + [entityName hash];
-	if([self singleKey] != nil)
+    if([self tempKey])
+    {
+        return ([entityName hash] ^ [[self tempKey] hash]);
+    }
+	if([self singleValue])
 	{
-		hash = hash + [singleKey hash];
-		hash = hash + [singleValue hash];
+		return ([entityName hash] ^ [[self singleValue] hash]);
 	}
-	else if ([self objectIdKeys] != nil)
-	{
-		// TODO: remember that values can come in random order
-	}
-	return hash;
+    // TODO: include other parameters in hash code
+	return [entityName hash];
 }
 
 - (BOOL)isEqual:(id)anObject
 {
-	// TODO: implement
 	if(![[self entityName] isEqualToString:[anObject entityName]])
 	{
 		return NO;



Mime
View raw message