mirror of
https://github.com/gnustep/libs-gdl2.git
synced 2025-02-22 02:41:05 +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>
|
2002-12-08 Mirko Viviani <mirko.viviani@rccr.cremona.it>
|
||||||
|
|
||||||
* EOAccess/EOEntity.m ([EOEntity -classDescriptionForInstances]):
|
* EOAccess/EOEntity.m ([EOEntity -classDescriptionForInstances]):
|
||||||
|
|
|
@ -3451,9 +3451,9 @@ Raises an exception is the adaptor is unable to perform the operations.
|
||||||
EOFLOGObjectFnStop();
|
EOFLOGObjectFnStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)relayAttributesInRelationship: (EORelationship*)relationship
|
- (void)relayAttributesInRelationship: (EORelationship*)relationship
|
||||||
sourceObject: (id)sourceObject
|
sourceObject: (id)sourceObject
|
||||||
destinationObjects: (NSArray*)destinationObjects
|
destinationObjects: (NSArray*)destinationObjects
|
||||||
{
|
{
|
||||||
int destinationObjectsCount = 0;
|
int destinationObjectsCount = 0;
|
||||||
|
|
||||||
|
@ -3526,7 +3526,7 @@ Raises an exception is the adaptor is unable to perform the operations.
|
||||||
objectForKey: @"destinationKeys"];//(customerCode)
|
objectForKey: @"destinationKeys"];//(customerCode)
|
||||||
NSArray *sourceKeys = [sourceToDestinationKeyMap
|
NSArray *sourceKeys = [sourceToDestinationKeyMap
|
||||||
objectForKey: @"sourceKeys"];//(code)
|
objectForKey: @"sourceKeys"];//(code)
|
||||||
NSMutableDictionary* sourceNewRow = [sourceDBOpe newRow];//OK in foreignKeyInDestination
|
NSMutableDictionary *sourceNewRow = [sourceDBOpe newRow];//OK in foreignKeyInDestination
|
||||||
BOOL foreignKeyInDestination = [relationship foreignKeyInDestination];
|
BOOL foreignKeyInDestination = [relationship foreignKeyInDestination];
|
||||||
int i, count;
|
int i, count;
|
||||||
|
|
||||||
|
@ -3548,7 +3548,7 @@ Raises an exception is the adaptor is unable to perform the operations.
|
||||||
NSAssert([destinationKeys count] == [sourceKeys count],
|
NSAssert([destinationKeys count] == [sourceKeys count],
|
||||||
@"destination keys count!=source keys count");
|
@"destination keys count!=source keys count");
|
||||||
|
|
||||||
if (foreignKeyInDestination)
|
if (foreignKeyInDestination || [relationship propagatesPrimaryKey])
|
||||||
{
|
{
|
||||||
relayedValues = [[[sourceNewRow valuesForKeys: sourceKeys]
|
relayedValues = [[[sourceNewRow valuesForKeys: sourceKeys]
|
||||||
mutableCopy] autorelease];// {code = 0; }
|
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++)
|
for (i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
id sourceKey = [sourceKeys objectAtIndex: i];
|
NSString *sourceKey = [sourceKeys objectAtIndex: i];
|
||||||
id destKey = [destinationKeys objectAtIndex: i];//customerCode
|
NSString *destKey = [destinationKeys objectAtIndex: i];
|
||||||
id sourceValue = [relayedValues objectForKey: sourceKey];
|
id sourceValue = [relayedValues objectForKey: sourceKey];
|
||||||
|
|
||||||
EOFLOGObjectLevelArgs(@"EODatabaseContext", @"sourceKey=%@",
|
EOFLOGObjectLevelArgs(@"EODatabaseContext", @"sourceKey=%@",
|
||||||
sourceKey);
|
sourceKey);
|
||||||
EOFLOGObjectLevelArgs(@"EODatabaseContext", @"destKey=%@",
|
EOFLOGObjectLevelArgs(@"EODatabaseContext", @"destKey=%@",
|
||||||
destKey);
|
destKey);
|
||||||
EOFLOGObjectLevelArgs(@"EODatabaseContext", @"sourceValue=%@",
|
EOFLOGObjectLevelArgs(@"EODatabaseContext", @"sourceValue=%@",
|
||||||
sourceValue);
|
sourceValue);
|
||||||
|
|
||||||
[relayedValues removeObjectForKey: sourceKey];
|
[relayedValues removeObjectForKey: sourceKey];
|
||||||
[relayedValues setObject: sourceValue
|
[relayedValues setObject: sourceValue
|
||||||
forKey: destKey];
|
forKey: destKey];
|
||||||
}
|
}
|
||||||
|
|
||||||
EOFLOGObjectLevelArgs(@"EODatabaseContext", @"relayedValues=%@",
|
EOFLOGObjectLevelArgs(@"EODatabaseContext", @"relayedValues=%@",
|
||||||
|
@ -3855,9 +3855,6 @@ Raises an exception is the adaptor is unable to perform the operations.
|
||||||
object: object
|
object: object
|
||||||
entity: entity]; //OK
|
entity: entity]; //OK
|
||||||
|
|
||||||
EOFLOGObjectLevelArgs(@"EODatabaseContext",
|
|
||||||
@"CREATED databaseOpe=%@\nfor object %p",
|
|
||||||
databaseOpe, object);
|
|
||||||
EOFLOGObjectLevelArgs(@"EODatabaseContext",
|
EOFLOGObjectLevelArgs(@"EODatabaseContext",
|
||||||
@"CREATED databaseOpe=%@\nfor object %p %@",
|
@"CREATED databaseOpe=%@\nfor object %p %@",
|
||||||
databaseOpe, object, object);
|
databaseOpe, object, object);
|
||||||
|
@ -3968,6 +3965,7 @@ Raises an exception is the adaptor is unable to perform the operations.
|
||||||
|
|
||||||
return databaseOpe;
|
return databaseOpe;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)relayPrimaryKey: (NSDictionary*)pk
|
- (void)relayPrimaryKey: (NSDictionary*)pk
|
||||||
sourceObject: (id)sourceObject
|
sourceObject: (id)sourceObject
|
||||||
destObject: (id)destObject
|
destObject: (id)destObject
|
||||||
|
@ -4005,7 +4003,7 @@ Raises an exception is the adaptor is unable to perform the operations.
|
||||||
count = [values count];
|
count = [values count];
|
||||||
|
|
||||||
for (i = 0; nullPKValues && i < count; i++)
|
for (i = 0; nullPKValues && i < count; i++)
|
||||||
nullPKValues = ([values objectAtIndex:i] == [EONull null]);
|
nullPKValues = isNilOrEONull([values objectAtIndex:i]);
|
||||||
|
|
||||||
EOFLOGObjectLevelArgs(@"EODatabaseContext", @"nullPKValues=%s",
|
EOFLOGObjectLevelArgs(@"EODatabaseContext", @"nullPKValues=%s",
|
||||||
(nullPKValues ? "YES" : "NO"));
|
(nullPKValues ? "YES" : "NO"));
|
||||||
|
@ -4026,9 +4024,9 @@ Raises an exception is the adaptor is unable to perform the operations.
|
||||||
EOFLOGObjectFnStop();
|
EOFLOGObjectFnStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)relayPrimaryKey: (NSDictionary*)pk
|
- (void)relayPrimaryKey: (NSDictionary*)pk
|
||||||
object: (id)object
|
object: (id)object
|
||||||
entity: (EOEntity*)entity
|
entity: (EOEntity*)entity
|
||||||
{
|
{
|
||||||
//TODO finish
|
//TODO finish
|
||||||
NSArray *relationships = nil;
|
NSArray *relationships = nil;
|
||||||
|
@ -6692,16 +6690,35 @@ _numLocked = 0;
|
||||||
|
|
||||||
if (destinationEntity)
|
if (destinationEntity)
|
||||||
{
|
{
|
||||||
EOFLOGObjectLevelArgs(@"EODatabaseContext",
|
NSArray *destAttrs;
|
||||||
@"destination entity: %@ No PrimaryKey Generation [Relatiuonship = %@]",
|
NSArray *pkAttrs;
|
||||||
[destinationEntity name],
|
int i, count;
|
||||||
[relationship name]);
|
BOOL destPK = NO;
|
||||||
|
|
||||||
if (!_nonPrimaryKeyGenerators)
|
destAttrs = [relationship destinationAttributes];
|
||||||
_nonPrimaryKeyGenerators = NSCreateHashTable(NSObjectHashCallBacks, 32);
|
pkAttrs = [destinationEntity primaryKeyAttributes];
|
||||||
|
count = [destAttrs count];
|
||||||
|
|
||||||
NSHashInsertIfAbsent(_nonPrimaryKeyGenerators, [destinationEntity name]);
|
for (i = 0; i < count; i++)
|
||||||
[entityToProcess addObject: destinationEntity];
|
{
|
||||||
|
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;
|
return _sourceToDestinationKeyMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
-(BOOL)foreignKeyInDestination
|
- (BOOL)foreignKeyInDestination
|
||||||
{
|
{
|
||||||
|
NSArray *destAttributes;
|
||||||
|
NSArray *primaryKeyAttributes;
|
||||||
|
int destAttributesCount;
|
||||||
|
int primaryKeyAttributesCount;
|
||||||
BOOL foreignKeyInDestination = NO;
|
BOOL foreignKeyInDestination = NO;
|
||||||
|
|
||||||
EOFLOGObjectFnStart();
|
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;
|
int i;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
NSArray *sourceAttributes = [self sourceAttributes];
|
|
||||||
NSArray *primaryKeyAttributes = [_entity primaryKeyAttributes];
|
|
||||||
int sourceAttributesCount = [sourceAttributes count];
|
|
||||||
int primaryKeyAttributesCount = [primaryKeyAttributes count];
|
|
||||||
|
|
||||||
EOFLOGObjectLevelArgs(@"EORelationship", @"sourceAttributes=%@", sourceAttributes);
|
for (i = 0;
|
||||||
EOFLOGObjectLevelArgs(@"EORelationship", @"primaryKeyAttributes=%@", primaryKeyAttributes);
|
!foreignKeyInDestination && i < destAttributesCount;
|
||||||
|
i++)
|
||||||
|
{
|
||||||
|
EOAttribute *attribute = [destAttributes objectAtIndex: i];
|
||||||
|
int pkAttrIndex = [primaryKeyAttributes
|
||||||
|
indexOfObjectIdenticalTo: attribute];
|
||||||
|
|
||||||
if (sourceAttributesCount > 0 && primaryKeyAttributesCount > 0)
|
foreignKeyInDestination = (pkAttrIndex == NSNotFound);
|
||||||
{
|
}
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0;
|
|
||||||
!foreignKeyInDestination && i < sourceAttributesCount;
|
|
||||||
i++) //TODO-VERIFY
|
|
||||||
{
|
|
||||||
EOAttribute *attribute = [sourceAttributes objectAtIndex: i];
|
|
||||||
int pkAttrIndex = [primaryKeyAttributes
|
|
||||||
indexOfObjectIdenticalTo: attribute];
|
|
||||||
|
|
||||||
foreignKeyInDestination = (pkAttrIndex != NSNotFound);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EOFLOGObjectFnStop();
|
EOFLOGObjectFnStop();
|
||||||
|
|
||||||
EOFLOGObjectLevelArgs(@"EORelationship", @"foreignKeyInDestination=%s",
|
EOFLOGObjectLevelArgs(@"EORelationship", @"foreignKeyInDestination=%s",
|
||||||
(foreignKeyInDestination ? "YES" : "NO"));
|
(foreignKeyInDestination ? "YES" : "NO"));
|
||||||
|
|
||||||
return foreignKeyInDestination;
|
return foreignKeyInDestination;
|
||||||
}
|
}
|
||||||
|
@ -2325,7 +2325,7 @@ dst entity primaryKeyAttributeNames
|
||||||
//NSEmitTODO(); //TODO
|
//NSEmitTODO(); //TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) _joinsChanged
|
- (void) _joinsChanged
|
||||||
|
|
Loading…
Reference in a new issue