diff --git a/ChangeLog b/ChangeLog index 12cfbce..e1fb11c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2010-06-28 David Wetzel + * EOAccess/EODatabaseContext.m + -initializeObject:withGlobalID:editingContext: + remove exessive checking + -initializeObject:row:entity:editingContext: + reformat, less IMPs, less logs + * EOControl/EOFault.h + + retainCount + unsigned -> NSUInteger + * EOControl/EOFault.m + + retainCount + unsigned -> NSUInteger + + clearFault: + raise if argument is no fault + rewrote retain behaviour + it makes no sense to free objects here and use the pointers + this would mess up the whole memory and crash. + + 2010-06-28 David Wetzel * EOAccess/EOEntity.m - createInstanceWithEditingContext:globalID:zone: diff --git a/EOAccess/EODatabaseChannel.m b/EOAccess/EODatabaseChannel.m index 7a3be3b..e06e9ce 100644 --- a/EOAccess/EODatabaseChannel.m +++ b/EOAccess/EODatabaseChannel.m @@ -439,8 +439,7 @@ RCS_ID("$Id$") [EOObserverCenter suppressObserverNotification]; NS_DURING - { - + { [_currentEditingContext initializeObject: object withGlobalID: gid editingContext: _currentEditingContext]; @@ -460,6 +459,7 @@ RCS_ID("$Id$") } [object awakeFromFetchInEditingContext: _currentEditingContext]; + } } } diff --git a/EOAccess/EODatabaseContext.m b/EOAccess/EODatabaseContext.m index 2b0d47c..f00406e 100644 --- a/EOAccess/EODatabaseContext.m +++ b/EOAccess/EODatabaseContext.m @@ -860,21 +860,12 @@ classPropertyNames = [entity classPropertyNames]; [NSException raise: NSInternalInconsistencyException format: @"%s No snapshot for gid %@", __PRETTY_FUNCTION__, globalID]; } else { - if ((!object) || ([object isKindOfClass:[EOCustomObject class]] == NO)) { - [NSException raise: NSInternalInconsistencyException - format: @"%s:%d cannot initialize nil/non EOCustomObject object!", __FILE__, __LINE__]; - } [self initializeObject: object row: snapDict entity: entity editingContext: context]; - - if ((!object) || ([object isKindOfClass:[EOCustomObject class]] == NO)) { - [NSException raise: NSInternalInconsistencyException - format: @"%s:%d Something went wrong!", __FILE__, __LINE__]; - } - + [_database incrementSnapshotCountForGlobalID:globalID]; } @@ -6140,183 +6131,169 @@ Raises an exception is the adaptor is unable to perform the operations. NSArray *relationships = nil; NSArray *classPropertyAttributeNames = nil; NSUInteger count = 0; - IMP objectTakeStoredValueForKeyIMP=NULL; IMP rowObjectForKeyIMP=NULL; - + classPropertyAttributeNames = [entity classPropertyAttributeNames]; count = [classPropertyAttributeNames count]; - + //row is usuallly a EOMutableKnownKeyDictionary so will use EOMKKD_objectForKeyWithImpPtr - + if (count>0) + { + NSUInteger i=0; + IMP oaiIMP=[classPropertyAttributeNames methodForSelector:@selector(objectAtIndex:)]; + + NSAssert(!_isFault(object), + @"Object is a fault. call -methodForSelector: on it is a bad idea"); + + for (i = 0; i < count; i++) { - NSUInteger i=0; - IMP oaiIMP=[classPropertyAttributeNames methodForSelector:@selector(objectAtIndex:)]; - - NSAssert(!_isFault(object), - @"Object is a fault. call -methodForSelector: on it is a bad idea"); - - objectTakeStoredValueForKeyIMP=[object methodForSelector:@selector(takeStoredValue:forKey:)]; - - for (i = 0; i < count; i++) - { - id key = GDL2_ObjectAtIndexWithImp(classPropertyAttributeNames,oaiIMP,i); - id value = nil; - - - value = EOMKKD_objectForKeyWithImpPtr(row,&rowObjectForKeyIMP,key); - - if (value == GDL2_EONull) - value = nil; - - NSDebugMLLog(@"EODatabaseContext", @"value (%p)", - value); - NSDebugMLLog(@"EODatabaseContext", @"value (%p)=%@ (class: %@)", - value, value, [value class]); - - GDL2_TakeStoredValueForKeyWithImp(object,objectTakeStoredValueForKeyIMP, - value,key); - } - }; - + id key = GDL2_ObjectAtIndexWithImp(classPropertyAttributeNames,oaiIMP,i); + id value = nil; + + + value = EOMKKD_objectForKeyWithImpPtr(row,&rowObjectForKeyIMP,key); + + if (value == GDL2_EONull) + value = nil; + + [object takeStoredValue:value + forKey:key]; + } + }; + relationships = [entity _relationshipsToFaultForRow: row]; - - - + + + count = [relationships count]; - + if (count>0) + { + NSUInteger i=0; + IMP oaiIMP=[relationships methodForSelector:@selector(objectAtIndex:)]; + + NSAssert(!_isFault(object), + @"Object is a fault. call -methodForSelector: on it is a bad idea"); + + + for (i = 0; i < count; i++) { - NSUInteger i=0; - IMP oaiIMP=[relationships methodForSelector:@selector(objectAtIndex:)]; - - if (!objectTakeStoredValueForKeyIMP) + id relObject = nil; + EORelationship *relationship = GDL2_ObjectAtIndexWithImp(relationships,oaiIMP,i); + NSString *relName = [relationship name]; + + + if ([relationship isToMany]) + { + EOGlobalID *gid = [entity globalIDForRow: row]; + + relObject = [self arrayFaultWithSourceGlobalID: gid + relationshipName: relName + editingContext: context]; + } + else if ([relationship isFlattened]) + { + // to one flattened relationship like aRelationship.anotherRelationship... + + // I don't know how to handle this case.... May be we shouldn't treat this as real property ?? + NSEmitTODO(); + relObject = nil; + } + else + { + EOMutableKnownKeyDictionary *foreignKeyForSourceRow = nil; + + NSDebugMLLog(@"EODatabaseContext", + @"relationship=%@ foreignKeyInDestination:%d", + relName, + [relationship foreignKeyInDestination]); + + foreignKeyForSourceRow = [relationship _foreignKeyForSourceRow: row]; + + NSDebugMLLog(@"EODatabaseContext", + @"row=%@\nforeignKeyForSourceRow:%@", + row, foreignKeyForSourceRow); + + if (![foreignKeyForSourceRow + containsObjectsNotIdenticalTo: GDL2_EONull]) { - NSAssert(!_isFault(object), - @"Object is a fault. call -methodForSelector: on it is a bad idea"); - - objectTakeStoredValueForKeyIMP=[object methodForSelector:@selector(takeStoredValue:forKey:)]; - }; - - for (i = 0; i < count; i++) - { - id relObject = nil; - EORelationship *relationship = GDL2_ObjectAtIndexWithImp(relationships,oaiIMP,i); - NSString *relName = [relationship name]; - - - if ([relationship isToMany]) - { - EOGlobalID *gid = [entity globalIDForRow: row]; - - relObject = [self arrayFaultWithSourceGlobalID: gid - relationshipName: relName - editingContext: context]; - } - else if ([relationship isFlattened]) - { - // to one flattened relationship like aRelationship.anotherRelationship... - - // I don't know how to handle this case.... May be we shouldn't treat this as real property ?? - NSEmitTODO(); - relObject = nil; - } - else - { - EOMutableKnownKeyDictionary *foreignKeyForSourceRow = nil; - - NSDebugMLLog(@"EODatabaseContext", - @"relationship=%@ foreignKeyInDestination:%d", - relName, - [relationship foreignKeyInDestination]); - - foreignKeyForSourceRow = [relationship _foreignKeyForSourceRow: row]; - - NSDebugMLLog(@"EODatabaseContext", - @"row=%@\nforeignKeyForSourceRow:%@", - row, foreignKeyForSourceRow); - - if (![foreignKeyForSourceRow - containsObjectsNotIdenticalTo: GDL2_EONull]) - { - NSLog(@"foreignKeyForSourceRow=%@",[foreignKeyForSourceRow debugDescription]); - NSEmitTODO();//TODO: what to do if rel is mandatory ? - relObject = nil; - } - else - { - EOEntity *destinationEntity = [relationship destinationEntity]; - EOGlobalID *relRowGid = [destinationEntity - globalIDForRow: foreignKeyForSourceRow]; - - - - if ([(EOKeyGlobalID*)relRowGid areKeysAllNulls]) - NSWarnLog(@"All key of relRowGid %p (%@) are nulls", - relRowGid, - relRowGid); - - relObject = [context faultForGlobalID: relRowGid - editingContext: context]; - - NSDebugMLLog(@"EODatabaseContext", @"relObject=%p (%@)", - relObject, [relObject class]); -//end -/* - NSArray *joins = [(EORelationship *)prop joins]; - EOJoin *join; - NSMutableDictionary *row; - EOGlobalID *faultGID; - int h, count; - id value, realValue = nil; - - row = [NSMutableDictionary dictionaryWithCapacity:4]; - - count = [joins count]; - for (h=0; h_handler; + + [handler faultWillFire: fault]; + + // this will transfer our fault instance into an EO + aFault->isa = [handler targetClass]; + aFault->_handler = [handler extraData]; + + // get the extra references to add them later to the EO + refs = [handler extraRefCount]; + + [handler autorelease]; + + // add up extra references to the EO + while (refs-- > 0) { + [aFault retain]; } - else - { - handler = aFault->_handler; - - [handler faultWillFire: fault]; - - refs = [handler extraRefCount]; - - aFault->isa = [handler targetClass]; - aFault->_handler = [handler extraData]; - - [handler autorelease]; - - refs -= [fault retainCount]; - - if (refs > 0) - while (refs-- > 0) - [aFault retain]; - else - while (refs++ < 0) - [aFault release]; - } - - NSDebugFLLog(@"gsdb", @"STOP fault=%p", fault); + } + } + (EOFaultHandler *)handlerForFault:(id)fault @@ -403,18 +391,9 @@ static Class EOFaultClass = NULL; - (void)dealloc { -#ifdef DEBUG - NSDebugFLog(@"Dealloc EOFault %p. %@", - (void*)self,GSCurrentThread()); -#endif [EOFaultClass clearFault: self]; - NSDebugMLog(@"EOFault dealloc self=%p",self); if (![EOFaultClass isFault:self]) // otherwise, this loop. [self dealloc]; -#ifdef DEBUG - NSDebugFLog(@"Stop Dealloc EOFault %p. %@", - (void*)self,GSCurrentThread()); -#endif } - (NSZone *)zone