Author: torehalset
Date: Wed Sep 20 13:05:59 2006
New Revision: 448320
URL: http://svn.apache.org/viewvc?view=rev&rev=448320
Log:
* added CAYArrayController that makes add/delete on a single/master
entity work. and support deleteOnRemove on toMany relationships.
* ctxt.deleteObject also delets from object store.
Added:
incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYArrayController.h
incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYArrayController.m
Modified:
incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYCocoaCayenne.m
incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectContext.m
incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CocoaCayenne.xcodeproj/project.pbxproj
Added: incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYArrayController.h
URL:
http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYArrayController.h?view=auto&rev=448320
==============================================================================
--- incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYArrayController.h
(added)
+++ incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYArrayController.h
Wed Sep 20 13:05:59 2006
@@ -0,0 +1,37 @@
+/*****************************************************************
+ * 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>
+
+#import "CAYObjectContext.h"
+
[EMAIL PROTECTED] CAYArrayController : NSArrayController {
+
+ CAYObjectContext *objectContext;
+ BOOL deleteObjectOnRemove;
+
+}
+
+-(void)setObjectContext:(CAYObjectContext *)ctxt;
+-(CAYObjectContext *)objectContext;
+
+-(void)setDeleteObjectOnRemove:(BOOL)d;
+-(BOOL)deleteObjectOnRemove;
+
[EMAIL PROTECTED]
Added: incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYArrayController.m
URL:
http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYArrayController.m?view=auto&rev=448320
==============================================================================
--- incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYArrayController.m
(added)
+++ incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYArrayController.m
Wed Sep 20 13:05:59 2006
@@ -0,0 +1,104 @@
+/*****************************************************************
+ * 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 "CAYArrayController.h"
+
[EMAIL PROTECTED] CAYArrayController
+
+- (id)newObject
+{
+ id r = [super newObject];
+
+ // NSLog(@"DEBUG: in newObject. about to register if needed: %@", r);
+ if(![self objectContext])
+ {
+ // TODO: if missing object context, perhaps autoset from content or
+ // parent or anything?
+ // TODO: this is not a problem for toMany. should probably not WARN in
+ // that situation
+ NSLog(@"WARN: array controller missing object context. %@", self);
+ }
+
+ if([self objectContext] && [r isKindOfClass:[CAYPersistentObject class]])
+ {
+ CAYPersistentObject *po = (CAYPersistentObject *)r;
+ if(![po objectContext])
+ {
+ [[self objectContext] registerNewObject:po];
+ }
+ }
+
+ return r;
+}
+
+- (void)remove:(id)sender
+{
+ // TODO: look for deleteObjectOnRemove from binding? Problem is that it
only are used
+ // in a core data environment
+
+ // remember objects to delete for later
+ NSMutableArray *objectsToDelete = [NSMutableArray array];
+ if([self objectContext] && [self deleteObjectOnRemove])
+ {
+ [objectsToDelete addObjectsFromArray:[self selectedObjects]];
+ }
+
+ // do the relationship handling
+ [super remove:sender];
+
+ // delete objects if any
+ if([self objectContext] && [self deleteObjectOnRemove])
+ {
+ NSEnumerator *enumerator = [objectsToDelete objectEnumerator];
+ CAYPersistentObject *element = nil;
+ while(element = [enumerator nextObject])
+ {
+ [[self objectContext] deleteObject:element];
+ }
+ }
+}
+
+-(void)setObjectContext:(CAYObjectContext *)ctxt
+{
+ // do not need to retain our master
+ objectContext = ctxt;
+}
+
+-(CAYObjectContext *)objectContext
+{
+ return objectContext;
+}
+
+-(void)setDeleteObjectOnRemove:(BOOL)d
+{
+ deleteObjectOnRemove = d;
+}
+
+-(BOOL)deleteObjectOnRemove
+{
+ return deleteObjectOnRemove;
+}
+
+-(void)dealloc
+{
+ [self setObjectContext:nil];
+ [super dealloc];
+}
+
[EMAIL PROTECTED]
Modified: incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYCocoaCayenne.m
URL:
http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYCocoaCayenne.m?view=diff&rev=448320&r1=448319&r2=448320
==============================================================================
--- incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYCocoaCayenne.m
(original)
+++ incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYCocoaCayenne.m Wed
Sep 20 13:05:59 2006
@@ -42,7 +42,6 @@
[classMapping setObject:@"CAYSyncMessage"
forKey:@"org.apache.cayenne.remote.SyncMessage"];
// graph
- // abstract [classMapping setObject:@"CAYNodeDiff"
forKey:@"org.apache.cayenne.graph.NodeDiff"];
[classMapping setObject:@"CAYCompoundDiff"
forKey:@"org.apache.cayenne.graph.CompoundDiff"];
[classMapping setObject:@"CAYNodeCreateOperation"
forKey:@"org.apache.cayenne.graph.NodeCreateOperation"];
[classMapping setObject:@"CAYNodePropertyChangeOperation"
forKey:@"org.apache.cayenne.graph.NodePropertyChangeOperation"];
Modified: incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectContext.m
URL:
http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectContext.m?view=diff&rev=448320&r1=448319&r2=448320
==============================================================================
--- incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectContext.m
(original)
+++ incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectContext.m Wed
Sep 20 13:05:59 2006
@@ -297,6 +297,9 @@
CAYNodeDiff *diff = [[CAYNodeDeleteOperation alloc] initWithNodeId:[o
objectId]];
[diffs addObject:diff];
[diff release];
+
+ // remove from object store
+ [objectByObjectId removeObjectForKey:[o objectId]];
// set persistent state
[o setPersistenceState:PSTATE_DELETED];
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=448320&r1=448319&r2=448320
==============================================================================
---
incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CocoaCayenne.xcodeproj/project.pbxproj
(original)
+++
incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CocoaCayenne.xcodeproj/project.pbxproj
Wed Sep 20 13:05:59 2006
@@ -69,6 +69,8 @@
444DAB1A0AACB74C006E1768 /* CAYArcCreateOperation.m in Sources
*/ = {isa = PBXBuildFile; fileRef = 444DAB180AACB74C006E1768 /*
CAYArcCreateOperation.m */; };
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 */; };
+ 448E1BA90AC0882F00D137DF /* CAYArrayController.h in Headers */
= {isa = PBXBuildFile; fileRef = 448E1BA70AC0882F00D137DF /*
CAYArrayController.h */; settings = {ATTRIBUTES = (Public, ); }; };
+ 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 */; };
44FE798F0AA3790C0040BB78 /* HessianObjC.framework in Frameworks
*/ = {isa = PBXBuildFile; fileRef = 44FE798E0AA3790C0040BB78 /*
HessianObjC.framework */; };
@@ -144,6 +146,8 @@
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>"; };
444DAB260AACB7B1006E1768 /* CAYArcDeleteOperation.m */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path
= CAYArcDeleteOperation.m; sourceTree = "<group>"; };
+ 448E1BA70AC0882F00D137DF /* CAYArrayController.h */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path =
CAYArrayController.h; sourceTree = "<group>"; };
+ 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>"; };
44FE798E0AA3790C0040BB78 /* HessianObjC.framework */ = {isa =
PBXFileReference; lastKnownFileType = wrapper.framework; name =
HessianObjC.framework; path = /Library/Frameworks/HessianObjC.framework;
sourceTree = "<absolute>"; };
@@ -225,6 +229,8 @@
44463D940AA37577006BAA58 /* CAYRemoteSession.m
*/,
444DA8030AA61E54006E1768 /* CAYCocoaCayenne.h
*/,
444DA8040AA61E54006E1768 /* CAYCocoaCayenne.m
*/,
+ 448E1BA70AC0882F00D137DF /*
CAYArrayController.h */,
+ 448E1BA80AC0882F00D137DF /*
CAYArrayController.m */,
);
name = Classes;
sourceTree = "<group>";
@@ -388,6 +394,7 @@
444DAB270AACB7B1006E1768 /*
CAYArcDeleteOperation.h in Headers */,
4407C1320ABAD50D0065409F /* CAYObjAttribute.h
in Headers */,
44BD0F9D0ABF08320005EE1E /* CAYDataMapIO.h in
Headers */,
+ 448E1BA90AC0882F00D137DF /*
CAYArrayController.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -477,6 +484,7 @@
444DAB280AACB7B1006E1768 /*
CAYArcDeleteOperation.m in Sources */,
4407C1330ABAD50D0065409F /* CAYObjAttribute.m
in Sources */,
44BD0F9E0ABF08320005EE1E /* CAYDataMapIO.m in
Sources */,
+ 448E1BAA0AC0882F00D137DF /*
CAYArrayController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};