mirror of
https://github.com/gnustep/libs-gdl2.git
synced 2025-02-22 19:01:04 +00:00
* EOAccess/EOEntity.m ([EOEntityClassDescription
awakeObject:fromInsertionInEditingContext:]): Only process class properties. Remove inactive code. Document. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gdl2/trunk@20166 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
ffb14dffe8
commit
432a2d5ce4
2 changed files with 71 additions and 137 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
2004-09-28 David Ayers <d.ayers@inode.at>
|
||||||
|
|
||||||
|
* EOAccess/EOEntity.m ([EOEntityClassDescription
|
||||||
|
awakeObject:fromInsertionInEditingContext:]): Only process class
|
||||||
|
properties. Remove inactive code. Document.
|
||||||
|
|
||||||
2004-09-26 David Ayers <d.ayers@inode.at>
|
2004-09-26 David Ayers <d.ayers@inode.at>
|
||||||
|
|
||||||
* EOControl/EOObserver.m: Update includes. Document classes and
|
* EOControl/EOObserver.m: Update includes. Document classes and
|
||||||
|
|
|
@ -4313,155 +4313,83 @@ fromFetchInEditingContext: (EOEditingContext *)context
|
||||||
EOFLOGObjectFnStop();
|
EOFLOGObjectFnStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Overrides [EOClassDescription-awakeObject:fromInsertionInEditingContext:]
|
||||||
|
* to initialize the class property relationships. The toMany relationships
|
||||||
|
* properties are initialized with a mutable array, while toOne relationships
|
||||||
|
* which propagate the primary key of the object get instantiated with a
|
||||||
|
* freshly initialzed instance. Whether a relationship is manditory or not
|
||||||
|
* is irrelevant at this point.
|
||||||
|
*/
|
||||||
- (void)awakeObject: (id)object
|
- (void)awakeObject: (id)object
|
||||||
fromInsertionInEditingContext: (EOEditingContext *)anEditingContext
|
fromInsertionInEditingContext: (EOEditingContext *)context
|
||||||
{
|
{
|
||||||
//near OK
|
NSArray *relationships;
|
||||||
|
NSArray *classProperties;
|
||||||
|
EORelationship *relationship;
|
||||||
|
int i, count;
|
||||||
|
|
||||||
EOFLOGObjectFnStart();
|
EOFLOGObjectFnStart();
|
||||||
|
|
||||||
[super awakeObject: object
|
[super awakeObject: object
|
||||||
fromInsertionInEditingContext: anEditingContext];
|
fromInsertionInEditingContext: context];
|
||||||
{
|
|
||||||
NSArray *relationships = [_entity relationships];
|
|
||||||
NSArray *classProperties = [_entity classProperties];//TODO use it !
|
|
||||||
int i, count = [relationships count];
|
|
||||||
|
|
||||||
for (i = 0; i < count; i++)
|
relationships = [_entity relationships];
|
||||||
{
|
classProperties = [_entity classProperties];
|
||||||
EORelationship *relationship = [relationships objectAtIndex: i];
|
count = [relationships count];
|
||||||
BOOL isToMany = [relationship isToMany];
|
|
||||||
|
|
||||||
if (isToMany)
|
for (i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
// We put a value only if there's not already one
|
relationship = [relationships objectAtIndex: i];
|
||||||
NSString* relationshipName=[relationship name];
|
|
||||||
id relationshipValue = [object storedValueForKey:relationshipName];
|
|
||||||
if (relationshipValue == nil)
|
|
||||||
{
|
|
||||||
//Put an empty mutable array [Ref: Assigns empty arrays to to-many
|
|
||||||
// relationship properties of newly inserted enterprise objects]
|
|
||||||
[object takeStoredValue: [EOCheapCopyMutableArray array]
|
|
||||||
forKey: [relationship name]];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else //??
|
|
||||||
{
|
|
||||||
/* Manuel
|
|
||||||
My (old) tests show that we create 1: object not on mandatory property but on propagatesPrimaryKey one *only*
|
|
||||||
if someone has an example of EOF creating an object here without propagatesPrimaryKey, please send it to me.
|
|
||||||
*/
|
|
||||||
#if 1
|
|
||||||
BOOL propagatesPrimaryKey = [relationship propagatesPrimaryKey];
|
|
||||||
|
|
||||||
if (propagatesPrimaryKey)
|
if ([classProperties containsObject: relationship])
|
||||||
{
|
{
|
||||||
int classPropIndex = [classProperties
|
if ([relationship isToMany])
|
||||||
indexOfObjectIdenticalTo: relationship];
|
{
|
||||||
|
NSString *name = [relationship name];
|
||||||
|
id relationshipValue
|
||||||
|
= [object storedValueForKey: name];
|
||||||
|
|
||||||
if (classPropIndex == NSNotFound)
|
/* We put a value only if there's not already one */
|
||||||
{
|
if (relationshipValue == nil)
|
||||||
NSEmitTODO(); //TODO
|
{
|
||||||
[self notImplemented: _cmd]; //TODO gid
|
/* [Ref: Assigns empty arrays to to-many
|
||||||
}
|
relationship properties of newly inserted
|
||||||
else
|
enterprise objects] */
|
||||||
{
|
[object takeStoredValue: [EOCheapCopyMutableArray array]
|
||||||
NSString *relationshipName = [relationship name];
|
forKey: name];
|
||||||
id relationshipValue = [object valueForKey:
|
}
|
||||||
relationshipName];//nil
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ([relationship propagatesPrimaryKey])
|
||||||
|
{
|
||||||
|
NSString *name = [relationship name];
|
||||||
|
id relationshipValue
|
||||||
|
= [object valueForKey: name];
|
||||||
|
|
||||||
if (relationshipValue)
|
if (relationshipValue == nil)
|
||||||
{
|
{
|
||||||
//Do nothing ??
|
EOEntity *destinationEntity
|
||||||
NSEmitTODO(); //TODO
|
= [relationship destinationEntity];
|
||||||
[self notImplemented: _cmd];//TODO??
|
EOClassDescription *classDescription
|
||||||
}
|
= [destinationEntity classDescriptionForInstances];
|
||||||
else
|
|
||||||
{
|
|
||||||
EOEntity *relationshipDestinationEntity =
|
|
||||||
[relationship destinationEntity];
|
|
||||||
EOClassDescription *classDescription =
|
|
||||||
[relationshipDestinationEntity
|
|
||||||
classDescriptionForInstances];
|
|
||||||
|
|
||||||
relationshipValue = [classDescription
|
relationshipValue
|
||||||
createInstanceWithEditingContext:
|
= [classDescription createInstanceWithEditingContext:
|
||||||
anEditingContext
|
context
|
||||||
globalID: nil
|
globalID: nil
|
||||||
zone: NULL];
|
zone: NULL];
|
||||||
|
|
||||||
[object addObject: relationshipValue
|
[object addObject: relationshipValue
|
||||||
toBothSidesOfRelationshipWithKey:
|
toBothSidesOfRelationshipWithKey: name];
|
||||||
relationshipName];
|
|
||||||
|
|
||||||
[anEditingContext insertObject: relationshipValue];
|
[context insertObject: relationshipValue];
|
||||||
/*
|
}
|
||||||
//Mirko code
|
}
|
||||||
EOEntity *entityTo;
|
}
|
||||||
|
}
|
||||||
objectTo = [object storedValueForKey:[relationship name]];
|
}
|
||||||
entityTo = [relationship destinationEntity];
|
|
||||||
|
|
||||||
if ([relationship isMandatory] == YES && objectTo == nil)
|
|
||||||
{
|
|
||||||
EODatabaseOperation *opTo;
|
|
||||||
EOGlobalID *gidTo;
|
|
||||||
|
|
||||||
objectTo = [[entityTo classDescriptionForInstances]
|
|
||||||
createInstanceWithEditingContext:context
|
|
||||||
globalID:nil
|
|
||||||
zone:NULL];
|
|
||||||
|
|
||||||
gidTo = [entityTo globalIDForRow:newPK];
|
|
||||||
|
|
||||||
opTo = [self _dbOperationWithGlobalID:gidTo
|
|
||||||
object:objectTo
|
|
||||||
entity:entityTo
|
|
||||||
operator:EODatabaseInsertOperator];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (objectTo && [entityTo
|
|
||||||
isPrimaryKeyValidInObject:objectTo] == NO)
|
|
||||||
{
|
|
||||||
pk = AUTORELEASE([[[entityTo primaryKeyAttributeNames] mutableCopy]);
|
|
||||||
[pk removeObjectsInArray:[entityTo classPropertyNames]];
|
|
||||||
|
|
||||||
pkObj = AUTORELEASE([newPK mutableCopy]);
|
|
||||||
[pkObj removeObjectsForKeys:pk];
|
|
||||||
|
|
||||||
[objectTo takeStoredValuesFromDictionary:pkObj];
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
// We'll put only mandatory values
|
|
||||||
if ([relationship isMandatory])
|
|
||||||
{
|
|
||||||
NSString* relationshipName=[relationship name];
|
|
||||||
id objectTo = [object storedValueForKey:relationshipName];
|
|
||||||
|
|
||||||
// We put a value only if there's not already one
|
|
||||||
if (objectTo == nil)
|
|
||||||
{
|
|
||||||
EOEntity *entityTo=nil;
|
|
||||||
|
|
||||||
entityTo = [relationship destinationEntity];
|
|
||||||
objectTo = [[entityTo classDescriptionForInstances]
|
|
||||||
createInstanceWithEditingContext:
|
|
||||||
anEditingContext
|
|
||||||
globalID: nil
|
|
||||||
zone: NULL];
|
|
||||||
|
|
||||||
[anEditingContext insertObject: objectTo];
|
|
||||||
|
|
||||||
[object addObject: objectTo
|
|
||||||
toBothSidesOfRelationshipWithKey:relationshipName];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
EOFLOGObjectFnStop();
|
EOFLOGObjectFnStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue