You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by to...@apache.org on 2006/11/08 23:22:20 UTC
svn commit: r472663 - in
/incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne: ./
CocoaCayenne.xcodeproj/
Author: torehalset
Date: Wed Nov 8 14:22:19 2006
New Revision: 472663
URL: http://svn.apache.org/viewvc?view=rev&rev=472663
Log:
undo stuff
* clear undo stack after successfull commitChanges
* remove prev NodeDiff if undo
Added:
incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYUtil.h
incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYUtil.m
Modified:
incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYArcCreateOperation.m
incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYArcDeleteOperation.m
incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYNodeDiff.h
incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYNodeDiff.m
incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYNodePropertyChangeOperation.m
incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectContext.m
incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectStore.h
incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectStore.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=472663&r1=472662&r2=472663
==============================================================================
--- incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYArcCreateOperation.m (original)
+++ incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYArcCreateOperation.m Wed Nov 8 14:22:19 2006
@@ -18,7 +18,8 @@
****************************************************************/
#import "CAYArcCreateOperation.h"
-
+#import "CAYArcDeleteOperation.h"
+#import "CAYUtil.h"
@implementation CAYArcCreateOperation
@@ -70,6 +71,24 @@
-(NSObject *)arcId
{
return arcId;
+}
+
+-(BOOL)isOpposite:(CAYNodeDiff *)diff
+{
+ if(![diff isKindOfClass:[CAYArcDeleteOperation class]])
+ {
+ return NO;
+ }
+
+ if(![[diff nodeId] isEqualTo:[self nodeId]])
+ {
+ return NO;
+ }
+
+ CAYArcDeleteOperation *other = (CAYArcDeleteOperation *)diff;
+
+ return ([[other arcId] isEqualTo:[self arcId]] &&
+ [CAYUtil nilSafe:[other targetNodeId] isEqualTo:[self targetNodeId]]);
}
-(NSString *)description
Modified: incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYArcDeleteOperation.m
URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYArcDeleteOperation.m?view=diff&rev=472663&r1=472662&r2=472663
==============================================================================
--- incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYArcDeleteOperation.m (original)
+++ incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYArcDeleteOperation.m Wed Nov 8 14:22:19 2006
@@ -18,7 +18,8 @@
****************************************************************/
#import "CAYArcDeleteOperation.h"
-
+#import "CAYArcCreateOperation.h"
+#import "CAYUtil.h"
@implementation CAYArcDeleteOperation
@@ -70,6 +71,24 @@
-(NSObject *)arcId
{
return arcId;
+}
+
+-(BOOL)isOpposite:(CAYNodeDiff *)diff
+{
+ if(![diff isKindOfClass:[CAYArcCreateOperation class]])
+ {
+ return NO;
+ }
+
+ if(![[diff nodeId] isEqualTo:[self nodeId]])
+ {
+ return NO;
+ }
+
+ CAYArcCreateOperation *other = (CAYArcCreateOperation *)diff;
+
+ return ([[other arcId] isEqualTo:[self arcId]] &&
+ [CAYUtil nilSafe:[other targetNodeId] isEqualTo:[self targetNodeId]]);
}
-(NSString *)description
Modified: incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYNodeDiff.h
URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYNodeDiff.h?view=diff&rev=472663&r1=472662&r2=472663
==============================================================================
--- incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYNodeDiff.h (original)
+++ incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYNodeDiff.h Wed Nov 8 14:22:19 2006
@@ -35,5 +35,6 @@
-(void)apply:(CAYObjectStore *)objectStore;
-(void)undo:(CAYObjectStore *)objectStore;
+-(BOOL)isOpposite:(CAYNodeDiff *)diff;
@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=472663&r1=472662&r2=472663
==============================================================================
--- incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYNodeDiff.m (original)
+++ incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYNodeDiff.m Wed Nov 8 14:22:19 2006
@@ -64,12 +64,18 @@
-(void)apply:(CAYObjectStore *)objectStore
{
- NSLog(@"%@ does not implement apply:", [self class]);
+ NSLog(@"DEBUG: %@ does not implement apply:", [self class]);
}
-(void)undo:(CAYObjectStore *)objectStore
{
- NSLog(@"%@ does not implement undo:", [self class]);
+ NSLog(@"DEBUG: %@ does not implement undo:", [self class]);
+}
+
+-(BOOL)isOpposite:(CAYNodeDiff *)diff
+{
+ NSLog(@"DEBUG: %@ does not implement isOpposite:", [self class]);
+ return NO;
}
-(void)dealloc
Modified: incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYNodePropertyChangeOperation.m
URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYNodePropertyChangeOperation.m?view=diff&rev=472663&r1=472662&r2=472663
==============================================================================
--- incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYNodePropertyChangeOperation.m (original)
+++ incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYNodePropertyChangeOperation.m Wed Nov 8 14:22:19 2006
@@ -19,6 +19,7 @@
#import "CAYNodePropertyChangeOperation.h"
#import "CAYNodeDiff.h"
+#import "CAYUtil.h"
@implementation CAYNodePropertyChangeOperation
@@ -89,6 +90,24 @@
-(NSObject *)newValue
{
return newValue;
+}
+
+-(BOOL)isOpposite:(CAYNodeDiff *)diff
+{
+ if(![diff isKindOfClass:[self class]])
+ {
+ return NO;
+ }
+
+ if(![[diff nodeId] isEqualTo:[self nodeId]])
+ {
+ return NO;
+ }
+
+ CAYNodePropertyChangeOperation *other = (CAYNodePropertyChangeOperation *)diff;
+
+ return ([CAYUtil nilSafe:[other newValue] isEqualTo:[self oldValue]] &&
+ [CAYUtil nilSafe:[other oldValue] isEqualTo:[self newValue]]);
}
-(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=472663&r1=472662&r2=472663
==============================================================================
--- incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectContext.m (original)
+++ incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectContext.m Wed Nov 8 14:22:19 2006
@@ -249,6 +249,7 @@
// even if no diffs a CAYNodeDiff are returned. so this is the
// place to clear out the diffs
[[self objectStore] removeAllDiffs];
+ [[self undoManager] removeAllActions];
}
else if ([result isKindOfClass:[NSError class]])
{
Modified: incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectStore.h
URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectStore.h?view=diff&rev=472663&r1=472662&r2=472663
==============================================================================
--- incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectStore.h (original)
+++ incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectStore.h Wed Nov 8 14:22:19 2006
@@ -27,6 +27,7 @@
@interface CAYObjectStore : NSObject {
NSMutableArray *diffs;
+ NSMutableDictionary *diffsByObjectId;
NSMutableDictionary *objectByObjectId;
}
Modified: incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectStore.m
URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectStore.m?view=diff&rev=472663&r1=472662&r2=472663
==============================================================================
--- incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectStore.m (original)
+++ incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectStore.m Wed Nov 8 14:22:19 2006
@@ -28,6 +28,7 @@
if(self != nil)
{
diffs = [[NSMutableArray alloc] init];
+ diffsByObjectId = [[NSMutableDictionary alloc] init];
objectByObjectId = [[NSMutableDictionary alloc] init];
}
return self;
@@ -35,7 +36,33 @@
-(void)registerDiff:(CAYNodeDiff *)diff
{
+ // find diffs for this ObjectId
+ CAYObjectId *oid = (CAYObjectId *)[diff nodeId];
+ NSMutableArray *diffsForSingleObjectId = (NSMutableArray *)[diffsByObjectId objectForKey:oid];
+ if(!diffsForSingleObjectId)
+ {
+ diffsForSingleObjectId = [NSMutableArray array];
+ [diffsByObjectId setObject:diffsForSingleObjectId forKey:oid];
+ }
+
+ // check if this diff is the opposite of the prev - if so just remove the prev
+ // instead of adding the new
+ if([diffsForSingleObjectId count] > 0)
+ {
+ CAYNodeDiff *prevDiff = [diffsForSingleObjectId lastObject];
+ if([diff isOpposite:prevDiff])
+ {
+ NSLog(@"DEBUG: diff is opposite of prev. remove instead of add. %@", diff);
+ [diffs removeObject:prevDiff];
+ [diffsForSingleObjectId removeObject:prevDiff];
+ return;
+ }
+ }
+
+ // accept this diff
+ NSLog(@"DEBUG: diff is not opposite of prev. add. %@", diff);
[diffs addObject:diff];
+ [diffsForSingleObjectId addObject:diff];
}
-(unsigned int)diffCount
@@ -52,6 +79,7 @@
-(void)removeAllDiffs
{
[diffs removeAllObjects];
+ [diffsByObjectId removeAllObjects];
}
-(CAYPersistentObject *)objectForId:(CAYObjectId *)oid
@@ -67,12 +95,15 @@
-(void)removeObjectForId:(CAYObjectId *)oid
{
[objectByObjectId removeObjectForKey:oid];
+ // TODO: remove from diffs?
}
-(void)dealloc
{
[diffs release];
diffs = nil;
+ [diffsByObjectId release];
+ diffsByObjectId = nil;
[objectByObjectId release];
objectByObjectId = nil;
[super dealloc];
Added: incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYUtil.h
URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYUtil.h?view=auto&rev=472663
==============================================================================
--- incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYUtil.h (added)
+++ incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYUtil.h Wed Nov 8 14:22:19 2006
@@ -0,0 +1,29 @@
+/*****************************************************************
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+****************************************************************/
+
+#import <Cocoa/Cocoa.h>
+
+
+@interface CAYUtil : NSObject {
+
+}
+
++(BOOL)nilSafe:(id)a isEqualTo:(id)b;
+
+@end
Added: incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYUtil.m
URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYUtil.m?view=auto&rev=472663
==============================================================================
--- incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYUtil.m (added)
+++ incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYUtil.m Wed Nov 8 14:22:19 2006
@@ -0,0 +1,40 @@
+/*****************************************************************
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+****************************************************************/
+
+#import "CAYUtil.h"
+
+
+@implementation CAYUtil
+
++(BOOL)nilSafe:(id)a isEqualTo:(id)b
+{
+ if(!a)
+ {
+ return !b;
+ }
+
+ if(!b)
+ {
+ return !a;
+ }
+
+ return [a isEqualTo:b];
+}
+
+@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=472663&r1=472662&r2=472663
==============================================================================
--- incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CocoaCayenne.xcodeproj/project.pbxproj (original)
+++ incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CocoaCayenne.xcodeproj/project.pbxproj Wed Nov 8 14:22:19 2006
@@ -13,7 +13,7 @@
4421E61F0AA4EE2D00FBE975 /* CAYNodeIdChangeOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = 4421E61D0AA4EE2D00FBE975 /* CAYNodeIdChangeOperation.m */; };
442607380AA4B8DE00F0A01F /* CAYNodeCreateOperation.h in Headers */ = {isa = PBXBuildFile; fileRef = 442607360AA4B8DE00F0A01F /* CAYNodeCreateOperation.h */; settings = {ATTRIBUTES = (Public, ); }; };
442607390AA4B8DE00F0A01F /* CAYNodeCreateOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = 442607370AA4B8DE00F0A01F /* CAYNodeCreateOperation.m */; };
- 443C14FA0B01348F004B032F /* CAYObjectStore.h in Headers */ = {isa = PBXBuildFile; fileRef = 443C14F80B01348F004B032F /* CAYObjectStore.h */; };
+ 443C14FA0B01348F004B032F /* CAYObjectStore.h in Headers */ = {isa = PBXBuildFile; fileRef = 443C14F80B01348F004B032F /* CAYObjectStore.h */; settings = {ATTRIBUTES = (Public, ); }; };
443C14FB0B01348F004B032F /* CAYObjectStore.m in Sources */ = {isa = PBXBuildFile; fileRef = 443C14F90B01348F004B032F /* CAYObjectStore.m */; };
44463D9B0AA37577006BAA58 /* CAYBootstrapMessage.h in Headers */ = {isa = PBXBuildFile; fileRef = 44463D6B0AA37577006BAA58 /* CAYBootstrapMessage.h */; settings = {ATTRIBUTES = (Public, ); }; };
44463D9C0AA37577006BAA58 /* CAYBootstrapMessage.m in Sources */ = {isa = PBXBuildFile; fileRef = 44463D6C0AA37577006BAA58 /* CAYBootstrapMessage.m */; };
@@ -89,6 +89,8 @@
448E1BAA0AC0882F00D137DF /* CAYArrayController.m in Sources */ = {isa = PBXBuildFile; fileRef = 448E1BA80AC0882F00D137DF /* CAYArrayController.m */; };
44BD0F9D0ABF08320005EE1E /* CAYDataMapIO.h in Headers */ = {isa = PBXBuildFile; fileRef = 44BD0F9B0ABF08320005EE1E /* CAYDataMapIO.h */; settings = {ATTRIBUTES = (Public, ); }; };
44BD0F9E0ABF08320005EE1E /* CAYDataMapIO.m in Sources */ = {isa = PBXBuildFile; fileRef = 44BD0F9C0ABF08320005EE1E /* CAYDataMapIO.m */; };
+ 44FCBB6E0B02883200A0F3D3 /* CAYUtil.h in Headers */ = {isa = PBXBuildFile; fileRef = 44FCBB6C0B02883200A0F3D3 /* CAYUtil.h */; };
+ 44FCBB6F0B02883200A0F3D3 /* CAYUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = 44FCBB6D0B02883200A0F3D3 /* CAYUtil.m */; };
44FE798F0AA3790C0040BB78 /* HessianObjC.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 44FE798E0AA3790C0040BB78 /* HessianObjC.framework */; };
8DC2EF530486A6940098B216 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C1666FE841158C02AAC07 /* InfoPlist.strings */; };
8DC2EF570486A6940098B216 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7B1FEA5585E11CA2CBB /* Cocoa.framework */; };
@@ -182,6 +184,8 @@
448E1BA80AC0882F00D137DF /* CAYArrayController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CAYArrayController.m; sourceTree = "<group>"; };
44BD0F9B0ABF08320005EE1E /* CAYDataMapIO.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CAYDataMapIO.h; sourceTree = "<group>"; };
44BD0F9C0ABF08320005EE1E /* CAYDataMapIO.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CAYDataMapIO.m; sourceTree = "<group>"; };
+ 44FCBB6C0B02883200A0F3D3 /* CAYUtil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CAYUtil.h; sourceTree = "<group>"; };
+ 44FCBB6D0B02883200A0F3D3 /* CAYUtil.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CAYUtil.m; sourceTree = "<group>"; };
44FE798E0AA3790C0040BB78 /* HessianObjC.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = HessianObjC.framework; path = /Library/Frameworks/HessianObjC.framework; sourceTree = "<absolute>"; };
8DC2EF5A0486A6940098B216 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
8DC2EF5B0486A6940098B216 /* CocoaCayenne.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = CocoaCayenne.framework; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -267,6 +271,8 @@
444F27A70AC9EDFF0097052B /* CAYCayenneRuntimeException.m */,
443C14F80B01348F004B032F /* CAYObjectStore.h */,
443C14F90B01348F004B032F /* CAYObjectStore.m */,
+ 44FCBB6C0B02883200A0F3D3 /* CAYUtil.h */,
+ 44FCBB6D0B02883200A0F3D3 /* CAYUtil.m */,
);
name = Classes;
sourceTree = "<group>";
@@ -467,6 +473,7 @@
4485B3B70AF69DE500920481 /* CAYObjectIdQuery.h in Headers */,
445C275A0AFC024300D7D2AA /* CAYTreeController.h in Headers */,
443C14FA0B01348F004B032F /* CAYObjectStore.h in Headers */,
+ 44FCBB6E0B02883200A0F3D3 /* CAYUtil.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -565,6 +572,7 @@
4485B3B80AF69DE500920481 /* CAYObjectIdQuery.m in Sources */,
445C275B0AFC024300D7D2AA /* CAYTreeController.m in Sources */,
443C14FB0B01348F004B032F /* CAYObjectStore.m in Sources */,
+ 44FCBB6F0B02883200A0F3D3 /* CAYUtil.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};