mirror of
https://github.com/gnustep/libs-gdl2.git
synced 2025-02-21 02:20:55 +00:00
* EOAccess/EORelationship.m ([EORelationship
-foreignKeyInDestination]): use destinationEntity to search for pk. * EOAccess/EODatabaseContext.m ([EODatabaseContext -_buildPrimaryKeyGeneratorListForEditingContext:]): check if the relationship propagates the pk to an entity pk. ([EODatabaseContext -relayAttributesInRelationship:sourceObject: destinationObject:]): record updates for relationship with fk and the ones that propatates pk. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gdl2/trunk@15295 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
4ff95c2a36
commit
0d78e7210c
3 changed files with 86 additions and 57 deletions
12
ChangeLog
12
ChangeLog
|
@ -1,3 +1,15 @@
|
|||
2002-12-14 Mirko Viviani <mirko.viviani@rccr.cremona.it>
|
||||
|
||||
* EOAccess/EORelationship.m ([EORelationship
|
||||
-foreignKeyInDestination]): use destinationEntity to search for pk.
|
||||
|
||||
* EOAccess/EODatabaseContext.m ([EODatabaseContext
|
||||
-_buildPrimaryKeyGeneratorListForEditingContext:]): check if the
|
||||
relationship propagates the pk to an entity pk.
|
||||
([EODatabaseContext -relayAttributesInRelationship:sourceObject:
|
||||
destinationObject:]): record updates for relationship with fk and the
|
||||
ones that propatates pk.
|
||||
|
||||
2002-12-08 Mirko Viviani <mirko.viviani@rccr.cremona.it>
|
||||
|
||||
* EOAccess/EOEntity.m ([EOEntity -classDescriptionForInstances]):
|
||||
|
|
|
@ -3451,9 +3451,9 @@ Raises an exception is the adaptor is unable to perform the operations.
|
|||
EOFLOGObjectFnStop();
|
||||
}
|
||||
|
||||
-(void)relayAttributesInRelationship: (EORelationship*)relationship
|
||||
sourceObject: (id)sourceObject
|
||||
destinationObjects: (NSArray*)destinationObjects
|
||||
- (void)relayAttributesInRelationship: (EORelationship*)relationship
|
||||
sourceObject: (id)sourceObject
|
||||
destinationObjects: (NSArray*)destinationObjects
|
||||
{
|
||||
int destinationObjectsCount = 0;
|
||||
|
||||
|
@ -3526,7 +3526,7 @@ Raises an exception is the adaptor is unable to perform the operations.
|
|||
objectForKey: @"destinationKeys"];//(customerCode)
|
||||
NSArray *sourceKeys = [sourceToDestinationKeyMap
|
||||
objectForKey: @"sourceKeys"];//(code)
|
||||
NSMutableDictionary* sourceNewRow = [sourceDBOpe newRow];//OK in foreignKeyInDestination
|
||||
NSMutableDictionary *sourceNewRow = [sourceDBOpe newRow];//OK in foreignKeyInDestination
|
||||
BOOL foreignKeyInDestination = [relationship foreignKeyInDestination];
|
||||
int i, count;
|
||||
|
||||
|
@ -3548,7 +3548,7 @@ Raises an exception is the adaptor is unable to perform the operations.
|
|||
NSAssert([destinationKeys count] == [sourceKeys count],
|
||||
@"destination keys count!=source keys count");
|
||||
|
||||
if (foreignKeyInDestination)
|
||||
if (foreignKeyInDestination || [relationship propagatesPrimaryKey])
|
||||
{
|
||||
relayedValues = [[[sourceNewRow valuesForKeys: sourceKeys]
|
||||
mutableCopy] autorelease];// {code = 0; }
|
||||
|
@ -3559,20 +3559,20 @@ Raises an exception is the adaptor is unable to perform the operations.
|
|||
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
id sourceKey = [sourceKeys objectAtIndex: i];
|
||||
id destKey = [destinationKeys objectAtIndex: i];//customerCode
|
||||
NSString *sourceKey = [sourceKeys objectAtIndex: i];
|
||||
NSString *destKey = [destinationKeys objectAtIndex: i];
|
||||
id sourceValue = [relayedValues objectForKey: sourceKey];
|
||||
|
||||
EOFLOGObjectLevelArgs(@"EODatabaseContext", @"sourceKey=%@",
|
||||
EOFLOGObjectLevelArgs(@"EODatabaseContext", @"sourceKey=%@",
|
||||
sourceKey);
|
||||
EOFLOGObjectLevelArgs(@"EODatabaseContext", @"destKey=%@",
|
||||
EOFLOGObjectLevelArgs(@"EODatabaseContext", @"destKey=%@",
|
||||
destKey);
|
||||
EOFLOGObjectLevelArgs(@"EODatabaseContext", @"sourceValue=%@",
|
||||
EOFLOGObjectLevelArgs(@"EODatabaseContext", @"sourceValue=%@",
|
||||
sourceValue);
|
||||
|
||||
[relayedValues removeObjectForKey: sourceKey];
|
||||
[relayedValues setObject: sourceValue
|
||||
forKey: destKey];
|
||||
[relayedValues removeObjectForKey: sourceKey];
|
||||
[relayedValues setObject: sourceValue
|
||||
forKey: destKey];
|
||||
}
|
||||
|
||||
EOFLOGObjectLevelArgs(@"EODatabaseContext", @"relayedValues=%@",
|
||||
|
@ -3855,9 +3855,6 @@ Raises an exception is the adaptor is unable to perform the operations.
|
|||
object: object
|
||||
entity: entity]; //OK
|
||||
|
||||
EOFLOGObjectLevelArgs(@"EODatabaseContext",
|
||||
@"CREATED databaseOpe=%@\nfor object %p",
|
||||
databaseOpe, object);
|
||||
EOFLOGObjectLevelArgs(@"EODatabaseContext",
|
||||
@"CREATED databaseOpe=%@\nfor object %p %@",
|
||||
databaseOpe, object, object);
|
||||
|
@ -3968,6 +3965,7 @@ Raises an exception is the adaptor is unable to perform the operations.
|
|||
|
||||
return databaseOpe;
|
||||
}
|
||||
|
||||
- (void)relayPrimaryKey: (NSDictionary*)pk
|
||||
sourceObject: (id)sourceObject
|
||||
destObject: (id)destObject
|
||||
|
@ -4005,7 +4003,7 @@ Raises an exception is the adaptor is unable to perform the operations.
|
|||
count = [values count];
|
||||
|
||||
for (i = 0; nullPKValues && i < count; i++)
|
||||
nullPKValues = ([values objectAtIndex:i] == [EONull null]);
|
||||
nullPKValues = isNilOrEONull([values objectAtIndex:i]);
|
||||
|
||||
EOFLOGObjectLevelArgs(@"EODatabaseContext", @"nullPKValues=%s",
|
||||
(nullPKValues ? "YES" : "NO"));
|
||||
|
@ -4026,9 +4024,9 @@ Raises an exception is the adaptor is unable to perform the operations.
|
|||
EOFLOGObjectFnStop();
|
||||
}
|
||||
|
||||
-(void)relayPrimaryKey: (NSDictionary*)pk
|
||||
object: (id)object
|
||||
entity: (EOEntity*)entity
|
||||
- (void)relayPrimaryKey: (NSDictionary*)pk
|
||||
object: (id)object
|
||||
entity: (EOEntity*)entity
|
||||
{
|
||||
//TODO finish
|
||||
NSArray *relationships = nil;
|
||||
|
@ -6692,16 +6690,35 @@ _numLocked = 0;
|
|||
|
||||
if (destinationEntity)
|
||||
{
|
||||
EOFLOGObjectLevelArgs(@"EODatabaseContext",
|
||||
@"destination entity: %@ No PrimaryKey Generation [Relatiuonship = %@]",
|
||||
[destinationEntity name],
|
||||
[relationship name]);
|
||||
NSArray *destAttrs;
|
||||
NSArray *pkAttrs;
|
||||
int i, count;
|
||||
BOOL destPK = NO;
|
||||
|
||||
if (!_nonPrimaryKeyGenerators)
|
||||
_nonPrimaryKeyGenerators = NSCreateHashTable(NSObjectHashCallBacks, 32);
|
||||
destAttrs = [relationship destinationAttributes];
|
||||
pkAttrs = [destinationEntity primaryKeyAttributes];
|
||||
count = [destAttrs count];
|
||||
|
||||
NSHashInsertIfAbsent(_nonPrimaryKeyGenerators, [destinationEntity name]);
|
||||
[entityToProcess addObject: destinationEntity];
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
if ([pkAttrs containsObject: [destAttrs
|
||||
objectAtIndex: i]])
|
||||
destPK = YES;
|
||||
}
|
||||
|
||||
if (destPK)
|
||||
{
|
||||
EOFLOGObjectLevelArgs(@"EODatabaseContext",
|
||||
@"destination entity: %@ No PrimaryKey Generation [Relationship = %@]",
|
||||
[destinationEntity name],
|
||||
[relationship name]);
|
||||
|
||||
if (!_nonPrimaryKeyGenerators)
|
||||
_nonPrimaryKeyGenerators = NSCreateHashTable(NSObjectHashCallBacks, 32);
|
||||
|
||||
NSHashInsertIfAbsent(_nonPrimaryKeyGenerators, [destinationEntity name]);
|
||||
[entityToProcess addObject: destinationEntity];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1978,47 +1978,47 @@ becomes "name", and "FIRST_NAME" becomes "firstName".*/
|
|||
return _sourceToDestinationKeyMap;
|
||||
}
|
||||
|
||||
-(BOOL)foreignKeyInDestination
|
||||
- (BOOL)foreignKeyInDestination
|
||||
{
|
||||
NSArray *destAttributes;
|
||||
NSArray *primaryKeyAttributes;
|
||||
int destAttributesCount;
|
||||
int primaryKeyAttributesCount;
|
||||
BOOL foreignKeyInDestination = NO;
|
||||
|
||||
EOFLOGObjectFnStart();
|
||||
|
||||
if ([self isToMany])
|
||||
destAttributes = [self destinationAttributes];
|
||||
primaryKeyAttributes = [[self destinationEntity] primaryKeyAttributes];
|
||||
|
||||
destAttributesCount = [destAttributes count];
|
||||
primaryKeyAttributesCount = [primaryKeyAttributes count];
|
||||
|
||||
EOFLOGObjectLevelArgs(@"EORelationship", @"destAttributes=%@",
|
||||
destAttributes);
|
||||
EOFLOGObjectLevelArgs(@"EORelationship", @"primaryKeyAttributes=%@",
|
||||
primaryKeyAttributes);
|
||||
|
||||
if (destAttributesCount > 0 && primaryKeyAttributesCount > 0)
|
||||
{
|
||||
foreignKeyInDestination = YES;
|
||||
}
|
||||
else
|
||||
{
|
||||
NSArray *sourceAttributes = [self sourceAttributes];
|
||||
NSArray *primaryKeyAttributes = [_entity primaryKeyAttributes];
|
||||
int sourceAttributesCount = [sourceAttributes count];
|
||||
int primaryKeyAttributesCount = [primaryKeyAttributes count];
|
||||
int i;
|
||||
|
||||
EOFLOGObjectLevelArgs(@"EORelationship", @"sourceAttributes=%@", sourceAttributes);
|
||||
EOFLOGObjectLevelArgs(@"EORelationship", @"primaryKeyAttributes=%@", primaryKeyAttributes);
|
||||
for (i = 0;
|
||||
!foreignKeyInDestination && i < destAttributesCount;
|
||||
i++)
|
||||
{
|
||||
EOAttribute *attribute = [destAttributes objectAtIndex: i];
|
||||
int pkAttrIndex = [primaryKeyAttributes
|
||||
indexOfObjectIdenticalTo: attribute];
|
||||
|
||||
if (sourceAttributesCount > 0 && primaryKeyAttributesCount > 0)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0;
|
||||
!foreignKeyInDestination && i < sourceAttributesCount;
|
||||
i++) //TODO-VERIFY
|
||||
{
|
||||
EOAttribute *attribute = [sourceAttributes objectAtIndex: i];
|
||||
int pkAttrIndex = [primaryKeyAttributes
|
||||
indexOfObjectIdenticalTo: attribute];
|
||||
|
||||
foreignKeyInDestination = (pkAttrIndex != NSNotFound);
|
||||
}
|
||||
}
|
||||
foreignKeyInDestination = (pkAttrIndex == NSNotFound);
|
||||
}
|
||||
}
|
||||
|
||||
EOFLOGObjectFnStop();
|
||||
|
||||
EOFLOGObjectLevelArgs(@"EORelationship", @"foreignKeyInDestination=%s",
|
||||
(foreignKeyInDestination ? "YES" : "NO"));
|
||||
(foreignKeyInDestination ? "YES" : "NO"));
|
||||
|
||||
return foreignKeyInDestination;
|
||||
}
|
||||
|
@ -2325,7 +2325,7 @@ dst entity primaryKeyAttributeNames
|
|||
//NSEmitTODO(); //TODO
|
||||
}
|
||||
|
||||
return self;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) _joinsChanged
|
||||
|
|
Loading…
Reference in a new issue