Author: torehalset
Date: Mon Sep 11 23:35:50 2006
New Revision: 442482
URL: http://svn.apache.org/viewvc?view=rev&rev=442482
Log:
started to manage persistence state
Modified:
incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYCocoaCayenne.h
incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectContext.m
incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYPersistentObject.m
incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYToOneFault.m
Modified: incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYCocoaCayenne.h
URL:
http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYCocoaCayenne.h?view=diff&rev=442482&r1=442481&r2=442482
==============================================================================
--- incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYCocoaCayenne.h
(original)
+++ incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYCocoaCayenne.h Mon
Sep 11 23:35:50 2006
@@ -19,11 +19,18 @@
#import <Cocoa/Cocoa.h>
-
@interface CAYCocoaCayenne : NSObject {
}
+(NSMutableDictionary *)classMapping;
+
+// define PersistenceState-states. see PersistenceState for documentation
+#define PSTATE_TRANSIENT 1
+#define PSTATE_NEW 2
+#define PSTATE_COMMITTED 3
+#define PSTATE_MODIFIED 4
+#define PSTATE_HOLLOW 5
+#define PSTATE_DELETED 6
@end
Modified: incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectContext.m
URL:
http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectContext.m?view=diff&rev=442482&r1=442481&r2=442482
==============================================================================
--- incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectContext.m
(original)
+++ incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectContext.m Mon
Sep 11 23:35:50 2006
@@ -78,6 +78,8 @@
if(old)
{
NSLog(@"old exist for oid. merge over values. %@ == %@", [row
objectId], [old objectId]);
+
+ // TODO: handle the state of the old object
// clear out old values and set new values
[[old valuesRaw] setDictionary:[row valuesRaw]];
@@ -122,6 +124,10 @@
{
NSLog(@"ERROR: Could not find ObjEntity for class %@", [row
class]);
}
+
+ // set persistence state to comitted as this rows
values are fresh from
+ // the database
+ [row setPersistenceState:PSTATE_COMMITTED];
}
else
{
@@ -140,6 +146,7 @@
CAYNodeDiff *diff = [[CAYNodePropertyChangeOperation alloc]
initWithNodeId:[object objectId] property:property oldValue:oldValue
newValue:newValue];
[diffs addObject:diff];
[diff release];
+ [object setPersistenceState:PSTATE_MODIFIED];
NSLog(@"%i unsaved changes", [diffs count]);
}
@@ -251,8 +258,10 @@
// TODO: check existing data context?
[o retain];
[o setObjectContext:self];
- // TODO: set persistant state
-
+
+ // set persistant state
+ [o setPersistenceState:PSTATE_NEW];
+
// create random data for key
int randombytes[8];
int i;
@@ -301,7 +310,8 @@
[diffs addObject:diff];
[diff release];
- // TODO set persistent state?
+ // set persistent state
+ [o setPersistenceState:PSTATE_DELETED];
// cleanup and remove
[o setObjectContext:nil];
Modified:
incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYPersistentObject.m
URL:
http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYPersistentObject.m?view=diff&rev=442482&r1=442481&r2=442482
==============================================================================
--- incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYPersistentObject.m
(original)
+++ incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYPersistentObject.m
Mon Sep 11 23:35:50 2006
@@ -23,6 +23,7 @@
#import "CAYFault.h"
#import "CAYObjEntity.h"
#import "CAYClientObjRelationship.h"
+#import "CAYCocoaCayenne.h"
@implementation CAYPersistentObject
@@ -32,6 +33,7 @@
if(self)
{
values = [[NSMutableDictionary dictionary] retain];
+ [self setPersistenceState:PSTATE_TRANSIENT];
}
return self;
}
@@ -190,6 +192,8 @@
{
NSLog(@"DEBUG: setToOneTarget value class: %@, key: %@, setrev: %@",
[value class], key, setrev ? @"YES" : @"NO");
id oldTarget = [self valueForKey:key];
+
+ // check for special case of no change
if(oldTarget == value)
{
return;
@@ -201,7 +205,6 @@
{
if([oldTarget isKindOfClass:[CAYPersistentObject class]])
{
- // TODO: unset reverse
[self unsetReverseRelationship:oldTarget forKey:key];
}
@@ -217,6 +220,7 @@
-(void)addToManyTarget:(CAYPersistentObject *)value forKey:(NSString *)key
setReverse:(BOOL)setrev
{
NSLog(@"DEBUG: addToManyTarget value class: %@, key: %@, setrev: %@",
[value class], key, setrev ? @"YES" : @"NO");
+
if(!value)
{
// TODO: throw
@@ -238,21 +242,20 @@
-(void)removeToManyTarget:(CAYPersistentObject *)value forKey:(NSString *)key
setReverse:(BOOL)setrev
{
NSLog(@"DEBUG: removeToManyTarget value class: %@, key: %@, setrev:
%@", [value class], key, setrev ? @"YES" : @"NO");
+
if(!value)
{
- // TODO: throw
- NSLog(@"ERROR. can not remove nil to [EMAIL PROTECTED]@", [self
class], key);
+ NSLog(@"ERROR. can not remove nil from [EMAIL PROTECTED]@.
ignoring.", [self class], key);
return;
}
NSMutableArray *list = [self valueForKey:key];
[[self objectContext] arcPropertyChanged:self forProperty:key
fromOld:value toNew:nil];
- // TODO:
- /*
- if (persistenceState == PersistenceState.COMMITTED) {
- persistenceState = PersistenceState.MODIFIED;
- }
- */
+
+ if([self persistenceState] == PSTATE_COMMITTED)
+ {
+ [self setPersistenceState:PSTATE_MODIFIED];
+ }
NSLog(@"DEBUG: value for [EMAIL PROTECTED]@ is of type %@", [self
class], key, [list class]);
Modified: incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYToOneFault.m
URL:
http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYToOneFault.m?view=diff&rev=442482&r1=442481&r2=442482
==============================================================================
--- incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYToOneFault.m
(original)
+++ incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYToOneFault.m Mon Sep
11 23:35:50 2006
@@ -39,7 +39,7 @@
{
row = (CAYPersistentObject *)[rows objectAtIndex:0];
}
- else
+ else if([rows count] > 1)
{
NSLog(@"ERROR: toOne fault resolve returned %i rows", [rows count]);
}