Author: torehalset
Date: Mon Oct 30 14:26:19 2006
New Revision: 469299
URL: http://svn.apache.org/viewvc?view=rev&rev=469299
Log:
ObjectIdQuery and basic HOLLOW handling
Added:
incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectIdQuery.h
incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectIdQuery.m
Modified:
incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYCocoaCayenne.m
incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectContext.h
incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectContext.m
incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYPersistentObject.m
incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CocoaCayenne.xcodeproj/project.pbxproj
Modified: incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYCocoaCayenne.m
URL:
http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYCocoaCayenne.m?view=diff&rev=469299&r1=469298&r2=469299
==============================================================================
--- incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYCocoaCayenne.m
(original)
+++ incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYCocoaCayenne.m Mon
Oct 30 14:26:19 2006
@@ -28,8 +28,6 @@
// core
[classMapping setObject:@"CAYRemoteSession"
forKey:@"org.apache.cayenne.remote.RemoteSession"];
- [classMapping setObject:@"CAYNamedQuery"
forKey:@"org.apache.cayenne.query.NamedQuery"];
- [classMapping setObject:@"CAYRelationshipQuery"
forKey:@"org.apache.cayenne.query.RelationshipQuery"];
[classMapping setObject:@"CAYGenericResponse"
forKey:@"org.apache.cayenne.util.GenericResponse"];
[classMapping setObject:@"CAYObjectId"
forKey:@"org.apache.cayenne.ObjectId"];
[classMapping setObject:@"CAYObjEntity"
forKey:@"org.apache.cayenne.map.ObjEntity"];
@@ -39,6 +37,11 @@
[classMapping setObject:@"CAYDataMap"
forKey:@"org.apache.cayenne.map.DataMap"];
[classMapping setObject:@"CAYCayenneRuntimeException"
forKey:@"org.apache.cayenne.CayenneRuntimeException"];
[classMapping setObject:@"CAYMissingSessionException"
forKey:@"org.apache.cayenne.remote.service.MissingSessionException"];
+
+ // query
+ [classMapping setObject:@"CAYNamedQuery"
forKey:@"org.apache.cayenne.query.NamedQuery"];
+ [classMapping setObject:@"CAYRelationshipQuery"
forKey:@"org.apache.cayenne.query.RelationshipQuery"];
+ [classMapping setObject:@"CAYObjectIdQuery"
forKey:@"org.apache.cayenne.query.ObjectIdQuery"];
// message
[classMapping setObject:@"CAYBootstrapMessage"
forKey:@"org.apache.cayenne.remote.BootstrapMessage"];
Modified: incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectContext.h
URL:
http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectContext.h?view=diff&rev=469299&r1=469298&r2=469299
==============================================================================
--- incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectContext.h
(original)
+++ incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectContext.h Mon
Oct 30 14:26:19 2006
@@ -48,6 +48,8 @@
-(void)deleteObject:(CAYPersistentObject *)o;
-(void)registerNewObject:(CAYPersistentObject *)o;
+-(void)prepareForAccess:(CAYPersistentObject *)object forProperty:(NSString
*)property withLazyFetching:(BOOL)lazyFaulting;
+
-(void)updateClassMapping;
@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=469299&r1=469298&r2=469299
==============================================================================
--- incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectContext.m
(original)
+++ incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectContext.m Mon
Oct 30 14:26:19 2006
@@ -35,6 +35,7 @@
#import "CAYArcDeleteOperation.h"
#import "CAYRelationshipQuery.h"
#import "CAYGenericResponse.h"
+#import "CAYObjectIdQuery.h"
@implementation CAYObjectContext
@@ -120,7 +121,7 @@
CAYPersistentObject *old = (CAYPersistentObject
*)[objectByObjectId objectForKey:[row objectId]];
if(old)
{
- NSLog(@"old exist for oid. merge over values. %@ == %@", [row
objectId], [old objectId]);
+ NSLog(@"DEBUG: old exist for oid. merge over values. %@ ==
%@", [row objectId], [old objectId]);
// TODO: handle the state of the old object.
merge over changes? or delete diffs
// for objects refreshed from server?
@@ -129,13 +130,13 @@
if(refreshing)
{
[[old valuesRaw] setDictionary:[row valuesRaw]];
- [row setPersistenceState:PSTATE_COMMITTED];
+ [old setPersistenceState:PSTATE_COMMITTED];
}
row = old;
}
else
{
- NSLog(@"old does not exist for oid %@", [row objectId]);
+ NSLog(@"DEBUG: old does not exist for oid %@", [row objectId]);
[objectByObjectId setObject:row forKey:[row objectId]];
[row setPersistenceState:PSTATE_COMMITTED];
}
@@ -157,19 +158,19 @@
}
}
- NSLog(@"query rows: %@", resultRows);
+ NSLog(@"DEBUG: query rows: %@", resultRows);
return [resultRows autorelease];
}
-(void) propertyChanged:(CAYPersistentObject *)object forProperty:(NSString
*)property fromOld:(NSObject *)oldValue toNew:(NSObject *)newValue
{
- NSLog(@"prop %@ changed from %@ to %@", property, oldValue, newValue);
+ NSLog(@"DEBUG: prop %@ changed from %@ to %@", property, oldValue,
newValue);
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]);
+ NSLog(@"DEBUG: %i unsaved changes", [diffs count]);
}
-(void) arcPropertyChanged:(CAYPersistentObject *)object forProperty:(NSString
*)property fromOld:(NSObject *)oldValue toNew:(NSObject *)newValue
@@ -178,7 +179,7 @@
if([oldValue isKindOfClass:[CAYPersistentObject class]])
{
- NSLog(@"add a arcDelete [EMAIL PROTECTED]@", [object class], property);
+ NSLog(@"DEBUG: add a arcDelete [EMAIL PROTECTED]@", [object class],
property);
CAYPersistentObject *ov = (CAYPersistentObject *)oldValue;
CAYArcDeleteOperation *diff = [[CAYArcDeleteOperation alloc]
initWithNodeId:[object objectId] targetNodeId:[ov objectId] arcId:property];
[diffs addObject:diff];
@@ -187,7 +188,7 @@
if([newValue isKindOfClass:[CAYPersistentObject class]])
{
- NSLog(@"add a arcCreate [EMAIL PROTECTED]@", [object class], property);
+ NSLog(@"DEBUG: add a arcCreate [EMAIL PROTECTED]@", [object class],
property);
CAYPersistentObject *nv = (CAYPersistentObject *)newValue;
CAYArcCreateOperation *diff = [[CAYArcCreateOperation alloc]
initWithNodeId:[object objectId] targetNodeId:[nv objectId] arcId:property];
[diffs addObject:diff];
@@ -386,19 +387,56 @@
[o setObjectId:nil];
}
+-(void)prepareForAccess:(CAYPersistentObject *)object forProperty:(NSString
*)property withLazyFetching:(BOOL)lazyFaulting
+{
+ if([object persistenceState] == PSTATE_HOLLOW)
+ {
+ NSLog(@"DEBUG: Object id hollow - issuing a ObjectIdQuery. %@",
[object objectId]);
+ CAYObjectId *oid = [object objectId];
+ CAYObjectIdQuery *query = [[CAYObjectIdQuery alloc] init];
+ [query setObjectId:oid];
+ NSError *error = nil;
+ NSArray *rows = [self performQuery:query error:&error];
+ [query release];
+
+ if(!rows)
+ {
+ // TODO: do something with this error??
+ NSLog(@"ERROR: %@", [error localizedDescription]);
+ }
+
+ if([rows count] == 0)
+ {
+ NSLog(@"ERROR: Error resolving fault, no matching row exists in
the database for ObjectId: %@", oid);
+ }
+
+ if([rows count] > 1)
+ {
+ NSLog(@"ERROR: Error resolving fault, more than one row exists in
the database for ObjectId: %@", oid);
+ }
+
+ if([object persistenceState] != PSTATE_COMMITTED)
+ {
+ NSLog(@"ERROR: Error resolving fault for ObjectId: [EMAIL
PROTECTED] Persistence state not comitted after ObjectIdQuery. %d", oid,
[object persistenceState]);
+ }
+ }
+
+ // TODO: resolve faults?
+}
+
-(void)updateClassMapping
{
if([self entityResolver])
{
// full class mapping for cayenne classes and all entities
- NSLog(@"update class mapping from entity resolver");
+ NSLog(@"DEBUG: update class mapping from entity resolver");
[[self entityResolver] updateClassMapping];
[[self connection] updateClassMapping:[[self entityResolver]
classMapping]];
}
else
{
// basic class mapping for the cayenne classes
- NSLog(@"update cayenne class");
+ NSLog(@"DEBUG: update cayenne class");
[[self connection] updateClassMapping:[CAYCocoaCayenne classMapping]];
}
}
Added: incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectIdQuery.h
URL:
http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectIdQuery.h?view=auto&rev=469299
==============================================================================
--- incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectIdQuery.h
(added)
+++ incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectIdQuery.h Mon
Oct 30 14:26:19 2006
@@ -0,0 +1,44 @@
+/*****************************************************************
+ * 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 "CAYQuery.h"
+#import "CAYObjectId.h"
+
+
[EMAIL PROTECTED] CAYObjectIdQuery : CAYQuery <NSCoding> {
+
+ CAYObjectId *objectId;
+ unsigned int cachePolicy;
+ BOOL fetchingDataRows;
+
+}
+
+-(void)setObjectId:(CAYObjectId *)oid;
+-(CAYObjectId *)objectId;
+-(void)setCachePolicy:(unsigned int)cp;
+-(unsigned int)cachePolicy;
+-(void)setFetchingDataRows:(BOOL)fdr;
+-(BOOL)isFetchingDataRows;
+
+#define CACHE 1
+#define CACHE_REFRESH 2
+#define CACHE_NOREFRESH 3
+
[EMAIL PROTECTED]
Added: incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectIdQuery.m
URL:
http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectIdQuery.m?view=auto&rev=469299
==============================================================================
--- incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectIdQuery.m
(added)
+++ incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjectIdQuery.m Mon
Oct 30 14:26:19 2006
@@ -0,0 +1,91 @@
+/*****************************************************************
+ * 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 "CAYObjectIdQuery.h"
+
+
[EMAIL PROTECTED] CAYObjectIdQuery
+
+-(id)init
+{
+ self = [super init];
+ if(self)
+ {
+ // set default values
+ [self setFetchingDataRows:FALSE];
+ [self setCachePolicy:CACHE_REFRESH];
+ }
+ return self;
+}
+
+-(id)initWithCoder:(NSCoder*)coder
+{
+ [super init];
+ [self setObjectId:[coder decodeObjectForKey:@"objectId"]];
+ [self setFetchingDataRows:[coder decodeBoolForKey:@"fetchingDataRows"]];
+ [self setCachePolicy:[coder decodeIntForKey:@"cachePolicy"]];
+ return self;
+}
+
+-(void)encodeWithCoder:(NSCoder*)coder
+{
+ [coder encodeObject:[self objectId] forKey:@"objectId"];
+ [coder encodeBool:[self isFetchingDataRows] forKey:@"fetchingDataRows"];
+ [coder encodeInt:[self cachePolicy] forKey:@"cachePolicy"];
+}
+
+-(void)setObjectId:(CAYObjectId *)oid
+{
+ [oid retain];
+ [objectId release];
+ objectId = oid;
+}
+
+-(CAYObjectId *)objectId
+{
+ return objectId;
+}
+
+-(void)setCachePolicy:(unsigned int)cp
+{
+ cachePolicy = cp;
+}
+
+-(unsigned int)cachePolicy
+{
+ return cachePolicy;
+}
+
+-(void)setFetchingDataRows:(BOOL)fdr
+{
+ fetchingDataRows = fdr;
+}
+
+-(BOOL)isFetchingDataRows
+{
+ return fetchingDataRows;
+}
+
+-(void)dealloc
+{
+ [self setObjectId:nil];
+ [super dealloc];
+}
+
[EMAIL PROTECTED]
Modified:
incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYPersistentObject.m
URL:
http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYPersistentObject.m?view=diff&rev=469299&r1=469298&r2=469299
==============================================================================
--- incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYPersistentObject.m
(original)
+++ incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYPersistentObject.m
Mon Oct 30 14:26:19 2006
@@ -75,6 +75,12 @@
-(void)setPersistenceState:(unsigned int)state
{
persistenceState = state;
+
+ if(persistenceState == PSTATE_HOLLOW)
+ {
+ NSLog(@"DEBUG: setting persistent state hollow - clearing values. %@",
[self objectId]);
+ [[self valuesRaw] removeAllObjects];
+ }
}
-(unsigned int)persistenceState
@@ -232,6 +238,7 @@
// see
http://developer.apple.com/documentation/Cocoa/Conceptual/KeyValueCoding/Concepts/SearchImplementation.html
-(void)setValue:(id)value forUndefinedKey:(NSString *)key
{
+ [[self objectContext] prepareForAccess:self forProperty:key
withLazyFetching:NO];
[self setPrimitiveValue:value forKey:key];
}
@@ -241,7 +248,7 @@
if([val isKindOfClass:[CAYFault class]])
{
CAYFault *fault = (CAYFault *)val;
- NSLog(@"resolve fault %@", fault);
+ NSLog(@"DEBUG: resolve fault %@", fault);
val = [fault resolveFault];
[values setValue:val forKey:key];
}
@@ -257,6 +264,7 @@
// see
http://developer.apple.com/documentation/Cocoa/Conceptual/KeyValueCoding/Concepts/SearchImplementation.html
-(id)valueForUndefinedKey:(NSString *)key
{
+ [[self objectContext] prepareForAccess:self forProperty:key
withLazyFetching:NO];
return [self primitiveValueForKey:key];
}
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=469299&r1=469298&r2=469299
==============================================================================
---
incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CocoaCayenne.xcodeproj/project.pbxproj
(original)
+++
incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CocoaCayenne.xcodeproj/project.pbxproj
Mon Oct 30 14:26:19 2006
@@ -79,6 +79,8 @@
444F27A90AC9EDFF0097052B /* CAYCayenneRuntimeException.m in
Sources */ = {isa = PBXBuildFile; fileRef = 444F27A70AC9EDFF0097052B /*
CAYCayenneRuntimeException.m */; };
444F27F50AC9F4B80097052B /* CAYMissingSessionException.h in
Headers */ = {isa = PBXBuildFile; fileRef = 444F27F30AC9F4B80097052B /*
CAYMissingSessionException.h */; settings = {ATTRIBUTES = (Public, ); }; };
444F27F60AC9F4B80097052B /* CAYMissingSessionException.m in
Sources */ = {isa = PBXBuildFile; fileRef = 444F27F40AC9F4B80097052B /*
CAYMissingSessionException.m */; };
+ 4485B3B70AF69DE500920481 /* CAYObjectIdQuery.h in Headers */ =
{isa = PBXBuildFile; fileRef = 4485B3B50AF69DE500920481 /* CAYObjectIdQuery.h
*/; };
+ 4485B3B80AF69DE500920481 /* CAYObjectIdQuery.m in Sources */ =
{isa = PBXBuildFile; fileRef = 4485B3B60AF69DE500920481 /* CAYObjectIdQuery.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, ); }; };
@@ -166,6 +168,8 @@
444F27A70AC9EDFF0097052B /* CAYCayenneRuntimeException.m */ =
{isa = PBXFileReference; fileEncoding = 4; lastKnownFileType =
sourcecode.c.objc; path = CAYCayenneRuntimeException.m; sourceTree = "<group>";
};
444F27F30AC9F4B80097052B /* CAYMissingSessionException.h */ =
{isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h;
path = CAYMissingSessionException.h; sourceTree = "<group>"; };
444F27F40AC9F4B80097052B /* CAYMissingSessionException.m */ =
{isa = PBXFileReference; fileEncoding = 4; lastKnownFileType =
sourcecode.c.objc; path = CAYMissingSessionException.m; sourceTree = "<group>";
};
+ 4485B3B50AF69DE500920481 /* CAYObjectIdQuery.h */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path =
CAYObjectIdQuery.h; sourceTree = "<group>"; };
+ 4485B3B60AF69DE500920481 /* CAYObjectIdQuery.m */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path
= CAYObjectIdQuery.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>"; };
@@ -363,6 +367,8 @@
44463D8E0AA37577006BAA58 /* CAYQuery.m */,
44463D910AA37577006BAA58 /*
CAYRelationshipQuery.h */,
44463D920AA37577006BAA58 /*
CAYRelationshipQuery.m */,
+ 4485B3B50AF69DE500920481 /* CAYObjectIdQuery.h
*/,
+ 4485B3B60AF69DE500920481 /* CAYObjectIdQuery.m
*/,
);
name = query;
sourceTree = "<group>";
@@ -438,6 +444,7 @@
444F263F0AC975E50097052B /*
CAYValidationResult.h in Headers */,
444F27A80AC9EDFF0097052B /*
CAYCayenneRuntimeException.h in Headers */,
444F27F50AC9F4B80097052B /*
CAYMissingSessionException.h in Headers */,
+ 4485B3B70AF69DE500920481 /* CAYObjectIdQuery.h
in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -533,6 +540,7 @@
444F26400AC975E50097052B /*
CAYValidationResult.m in Sources */,
444F27A90AC9EDFF0097052B /*
CAYCayenneRuntimeException.m in Sources */,
444F27F60AC9F4B80097052B /*
CAYMissingSessionException.m in Sources */,
+ 4485B3B80AF69DE500920481 /* CAYObjectIdQuery.m
in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};