* 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.



git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gdl2/trunk@30886 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Dave Wetzel 2010-06-29 03:10:35 +00:00
parent f14aafa3fc
commit 7c14405e1d
5 changed files with 204 additions and 229 deletions

View file

@ -1,3 +1,22 @@
2010-06-28 David Wetzel <dave@turbocat.de>
* 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 <dave@turbocat.de>
* EOAccess/EOEntity.m
- createInstanceWithEditingContext:globalID:zone:

View file

@ -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];
}
}
}

View file

@ -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<count; h++)
{
join = [joins objectAtIndex:h];
value = [snapshot objectForKey:[[join sourceAttribute]
name]];
if (value == null)
realValue = nil;
else
realValue = value;
[[prop validateValue:&realValue] raise];
[row setObject:value
forKey:[[join destinationAttribute]
name]];
}
if (realValue || [prop isMandatory] == YES)
{
faultGID = [[(EORelationship *)prop destinationEntity]
globalIDForRow:row];
fault = [context objectForGlobalID:faultGID];
if (fault == nil)
fault = [context faultForGlobalID:faultGID
editingContext:context];
}
else
fault = nil;
*/
}
}
GDL2_TakeStoredValueForKeyWithImp(object,objectTakeStoredValueForKeyIMP,
relObject,relName);
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<count; h++)
{
join = [joins objectAtIndex:h];
value = [snapshot objectForKey:[[join sourceAttribute]
name]];
if (value == null)
realValue = nil;
else
realValue = value;
[[prop validateValue:&realValue] raise];
[row setObject:value
forKey:[[join destinationAttribute]
name]];
}
if (realValue || [prop isMandatory] == YES)
{
faultGID = [[(EORelationship *)prop destinationEntity]
globalIDForRow:row];
fault = [context objectForGlobalID:faultGID];
if (fault == nil)
fault = [context faultForGlobalID:faultGID
editingContext:context];
}
else
fault = nil;
*/
}
}
[object takeStoredValue:relObject
forKey:relName];
}
};
}
- (void)forgetAllLocks

View file

@ -65,7 +65,7 @@
+ (id)retain;
+ (void)release;
+ (id)autorelease;
+ (unsigned)retainCount;
+ (NSUInteger)retainCount;
+ (BOOL)isKindOfClass: (Class)aClass;
+ (void)doesNotRecognizeSelector: (SEL)selector;

View file

@ -114,7 +114,7 @@ static Class EOFaultClass = NULL;
return self;
}
+ (unsigned)retainCount
+ (NSUInteger)retainCount
{
return UINT_MAX;
}
@ -198,49 +198,37 @@ static Class EOFaultClass = NULL;
+ (void)clearFault: (id)fault
{
EOFaultHandler *handler;
EOFault *aFault = (EOFault *)fault;
int refs = 0;
NSDebugFLLog(@"gsdb", @"START fault=%p", fault);
EOFaultHandler * handler;
EOFault * aFault = (EOFault *)fault;
NSUInteger refs = 0;
if ([EOFaultClass isFault:fault] == NO)
{
//REVOIR!!!
/*
[NSException raise:NSInvalidArgumentException
format:@"%@ -- %@ 0x%x: object %@ of class %@ is not a fault object",
NSStringFromSelector(_cmd),
NSStringFromClass([self class]),
self,
fault,
[fault class]];
*/
{
[NSException raise:NSInvalidArgumentException
format:@"%s -- object %@ of class %@ is not a fault object",
__PRETTY_FUNCTION__,
fault,
[fault class]];
} else {
handler = aFault->_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