mirror of
https://github.com/gnustep/libs-gdl2.git
synced 2025-04-22 12:55:44 +00:00
* EOAccess/EOModel.m:
entities: make sure we use a mutable array. Destroy _entities cache when adding a new one. (We run into wrong sorted arrays otherwise) * EOAccess/EOEntity.m: make setName: work * EOAccess/EORelationship.m add support for KVObserving. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gdl2/trunk@30397 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
9ef3e0ff2a
commit
b6d3915786
4 changed files with 195 additions and 129 deletions
|
@ -1,3 +1,12 @@
|
|||
2010-05-16 David Wetzel <dave@turbocat.de>
|
||||
* EOAccess/EOModel.m:
|
||||
entities: make sure we use a mutable array. Destroy _entities cache when adding a new one.
|
||||
(We run into wrong sorted arrays otherwise)
|
||||
* EOAccess/EOEntity.m:
|
||||
make setName: work
|
||||
* EOAccess/EORelationship.m
|
||||
add support for KVObserving.
|
||||
|
||||
2010-05-03 David Wetzel <dave@turbocat.de>
|
||||
* EOAccess/EOAttribute.m: Add comment
|
||||
* EOControl/EOEditingContext.m: Do not raise on inserting bad objects for now
|
||||
|
|
|
@ -1544,13 +1544,47 @@ createInstanceWithEditingContext:globalID:zone:
|
|||
|
||||
- (void)setName: (NSString *)name
|
||||
{
|
||||
NSInteger fCount = -1;
|
||||
NSInteger i;
|
||||
EOModel * oldModel = nil;
|
||||
|
||||
if (name && [name isEqual: _name]) return;
|
||||
|
||||
[[self validateName: name] raise];
|
||||
|
||||
[self willChange];
|
||||
|
||||
RETAIN(self);
|
||||
ASSIGN(oldModel,_model);
|
||||
|
||||
// We have to make sure all references are loaded before we change the name
|
||||
// if somebody finds a better solution, please tell me -- dw
|
||||
[_model referencesToProperty:self];
|
||||
|
||||
[_model removeEntity:self];
|
||||
|
||||
// update the fetch specifications
|
||||
|
||||
if (_fetchSpecificationNames)
|
||||
{
|
||||
fCount = [_fetchSpecificationNames count];
|
||||
}
|
||||
|
||||
for (i = 0; i < fCount; i++)
|
||||
{
|
||||
EOFetchSpecification * fetchSpec = [self fetchSpecificationNamed:[_fetchSpecificationNames objectAtIndex:i]];
|
||||
[fetchSpec setEntityName:name];
|
||||
}
|
||||
|
||||
ASSIGNCOPY(_name, name);
|
||||
[_model _updateCache];
|
||||
|
||||
[oldModel addEntity:self];
|
||||
RELEASE(oldModel);
|
||||
RELEASE(self);
|
||||
[self _setIsEdited];
|
||||
|
||||
// this destroys everything. -- dw
|
||||
//[_model _updateCache];
|
||||
}
|
||||
|
||||
- (void)setExternalName: (NSString *)name
|
||||
|
|
|
@ -303,16 +303,15 @@ NSString *EOEntityLoadedNotification = @"EOEntityLoadedNotification";
|
|||
|
||||
- (NSArray*) entities
|
||||
{
|
||||
//TODO revoir ?
|
||||
if (!_entities)
|
||||
{
|
||||
NSArray *entityNames = [self entityNames];
|
||||
|
||||
ASSIGN(_entities,
|
||||
[self resultsOfPerformingSelector: @selector(entityNamed:)
|
||||
withEachObjectInArray: entityNames]);
|
||||
}
|
||||
|
||||
{
|
||||
NSArray *entityNames = [self entityNames];
|
||||
|
||||
// we need an mutable array here, otherwise we cannot remove entities from it. -- dw
|
||||
ASSIGN(_entities,[NSMutableArray arrayWithArray:[self resultsOfPerformingSelector: @selector(entityNamed:)
|
||||
withEachObjectInArray: entityNames]]);
|
||||
}
|
||||
|
||||
return _entities;
|
||||
}
|
||||
|
||||
|
@ -1442,8 +1441,10 @@ NSString *EOEntityLoadedNotification = @"EOEntityLoadedNotification";
|
|||
|
||||
[self willChange];
|
||||
|
||||
/* Do not access _entities until cache is triggered */
|
||||
[(NSMutableArray *)[self entities] addObject: entity];
|
||||
/* _entities is sorted. we want a new one! */
|
||||
if (_entities) {
|
||||
DESTROY(_entities);
|
||||
}
|
||||
|
||||
NSAssert(_entitiesByClass, @"No _entitiesByClass");
|
||||
|
||||
|
|
|
@ -87,6 +87,18 @@ RCS_ID("$Id$")
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
this is used for key-value observing.
|
||||
*/
|
||||
|
||||
+ (BOOL)automaticallyNotifiesObserversForKey:(NSString *)theKey
|
||||
{
|
||||
if ([theKey isEqualToString:@"joins"]) {
|
||||
return NO;
|
||||
}
|
||||
return [super automaticallyNotifiesObserversForKey:theKey];
|
||||
}
|
||||
|
||||
+ (id) relationshipWithPropertyList: (NSDictionary *)propertyList
|
||||
owner: (id)owner
|
||||
{
|
||||
|
@ -1444,134 +1456,140 @@ relationships. Nil if none" **/
|
|||
{
|
||||
EOAttribute *sourceAttribute = nil;
|
||||
EOAttribute *destinationAttribute = nil;
|
||||
|
||||
|
||||
EOFLOGObjectFnStart();
|
||||
|
||||
|
||||
EOFLOGObjectLevelArgs(@"EORelationship", @"Add join: %@\nto %@", join, self);
|
||||
|
||||
|
||||
if ([self isFlattened] == YES)
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"%@ -- %@ 0x%x: receiver is a flattened relationship",
|
||||
NSStringFromSelector(_cmd),
|
||||
NSStringFromClass([self class]),
|
||||
self];
|
||||
format: @"%@ -- %@ 0x%x: receiver is a flattened relationship",
|
||||
NSStringFromSelector(_cmd),
|
||||
NSStringFromClass([self class]),
|
||||
self];
|
||||
else
|
||||
{
|
||||
EOEntity *destinationEntity = [self destinationEntity];
|
||||
EOEntity *sourceEntity = [self entity];
|
||||
|
||||
EOFLOGObjectLevelArgs(@"EORelationship", @"destinationEntity=%@", destinationEntity);
|
||||
|
||||
if (!destinationEntity)
|
||||
{
|
||||
EOEntity *destinationEntity = [self destinationEntity];
|
||||
EOEntity *sourceEntity = [self entity];
|
||||
|
||||
EOFLOGObjectLevelArgs(@"EORelationship", @"destinationEntity=%@", destinationEntity);
|
||||
|
||||
if (!destinationEntity)
|
||||
{
|
||||
NSEmitTODO(); //TODO
|
||||
EOFLOGObjectLevelArgs(@"EORelationship", @"self=%@", self);
|
||||
//TODO ??
|
||||
};
|
||||
|
||||
sourceAttribute = [join sourceAttribute];
|
||||
|
||||
NSAssert3(sourceAttribute, @"No source attribute in join %@ in relationship %@ of entity %@",
|
||||
join,
|
||||
self,
|
||||
sourceEntity);
|
||||
|
||||
destinationAttribute = [join destinationAttribute];
|
||||
|
||||
NSAssert3(destinationAttribute, @"No destination attribute in join %@ in relationship %@ of entity %@",
|
||||
join,
|
||||
self,
|
||||
sourceEntity);
|
||||
|
||||
if ([sourceAttribute isFlattened] == YES
|
||||
|| [destinationAttribute isFlattened] == YES)
|
||||
#warning checkme: do we need this? -- dw
|
||||
//NSEmitTODO(); //TODO
|
||||
//EOFLOGObjectLevelArgs(@"EORelationship", @"self=%@", self);
|
||||
//TODO ??
|
||||
};
|
||||
|
||||
sourceAttribute = [join sourceAttribute];
|
||||
|
||||
NSAssert3(sourceAttribute, @"No source attribute in join %@ in relationship %@ of entity %@",
|
||||
join,
|
||||
self,
|
||||
sourceEntity);
|
||||
|
||||
destinationAttribute = [join destinationAttribute];
|
||||
|
||||
NSAssert3(destinationAttribute, @"No destination attribute in join %@ in relationship %@ of entity %@",
|
||||
join,
|
||||
self,
|
||||
sourceEntity);
|
||||
|
||||
if ([sourceAttribute isFlattened] == YES
|
||||
|| [destinationAttribute isFlattened] == YES)
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"%@ -- %@ 0x%x: join's attributes are flattened",
|
||||
NSStringFromSelector(_cmd),
|
||||
NSStringFromClass([self class]),
|
||||
self];
|
||||
else
|
||||
{
|
||||
EOEntity *joinDestinationEntity = [destinationAttribute entity];
|
||||
EOEntity *joinSourceEntity = [sourceAttribute entity];
|
||||
|
||||
/* if (destinationEntity && ![[destinationEntity name] isEqual:[joinSourceEntity name]])
|
||||
{
|
||||
[NSException raise:NSInvalidArgumentException
|
||||
format:@"%@ -- %@ 0x%x: join source entity (%@) is not equal to last join entity (%@)",
|
||||
NSStringFromSelector(_cmd),
|
||||
NSStringFromClass([self class]),
|
||||
self,
|
||||
[joinSourceEntity name],
|
||||
[destinationEntity name]];
|
||||
}*/
|
||||
|
||||
if (sourceEntity
|
||||
&& ![[joinSourceEntity name] isEqual: [sourceEntity name]])
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"%@ -- %@ 0x%x: join's attributes are flattened",
|
||||
NSStringFromSelector(_cmd),
|
||||
NSStringFromClass([self class]),
|
||||
self];
|
||||
format: @"%@ -- %@ 0x%x (%@): join source entity (%@) is not equal to relationship entity (%@)",
|
||||
NSStringFromSelector(_cmd),
|
||||
NSStringFromClass([self class]),
|
||||
self,
|
||||
[self name],
|
||||
[joinSourceEntity name],
|
||||
[sourceEntity name]];
|
||||
else if (destinationEntity
|
||||
&& ![[joinDestinationEntity name]
|
||||
isEqual: [destinationEntity name]])
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"%@ -- %@ 0x%x (%@): join destination entity (%@) is not equal to relationship destination entity (%@)",
|
||||
NSStringFromSelector(_cmd),
|
||||
NSStringFromClass([self class]),
|
||||
self,
|
||||
[self name],
|
||||
[joinDestinationEntity name],
|
||||
[destinationEntity name]];
|
||||
else
|
||||
{
|
||||
if ([_sourceAttributes count])
|
||||
{
|
||||
EOEntity *joinDestinationEntity = [destinationAttribute entity];
|
||||
EOEntity *joinSourceEntity = [sourceAttribute entity];
|
||||
|
||||
/* if (destinationEntity && ![[destinationEntity name] isEqual:[joinSourceEntity name]])
|
||||
{
|
||||
[NSException raise:NSInvalidArgumentException
|
||||
format:@"%@ -- %@ 0x%x: join source entity (%@) is not equal to last join entity (%@)",
|
||||
NSStringFromSelector(_cmd),
|
||||
NSStringFromClass([self class]),
|
||||
self,
|
||||
[joinSourceEntity name],
|
||||
[destinationEntity name]];
|
||||
}*/
|
||||
|
||||
if (sourceEntity
|
||||
&& ![[joinSourceEntity name] isEqual: [sourceEntity name]])
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"%@ -- %@ 0x%x (%@): join source entity (%@) is not equal to relationship entity (%@)",
|
||||
NSStringFromSelector(_cmd),
|
||||
NSStringFromClass([self class]),
|
||||
self,
|
||||
[self name],
|
||||
[joinSourceEntity name],
|
||||
[sourceEntity name]];
|
||||
else if (destinationEntity
|
||||
&& ![[joinDestinationEntity name]
|
||||
isEqual: [destinationEntity name]])
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"%@ -- %@ 0x%x (%@): join destination entity (%@) is not equal to relationship destination entity (%@)",
|
||||
NSStringFromSelector(_cmd),
|
||||
NSStringFromClass([self class]),
|
||||
self,
|
||||
[self name],
|
||||
[joinDestinationEntity name],
|
||||
[destinationEntity name]];
|
||||
else
|
||||
{
|
||||
if ([_sourceAttributes count])
|
||||
{
|
||||
EOAttribute *sourceAttribute = [join sourceAttribute];
|
||||
EOAttribute *destinationAttribute;
|
||||
|
||||
destinationAttribute = [join destinationAttribute];
|
||||
|
||||
if (([_sourceAttributes indexOfObject: sourceAttribute]
|
||||
!= NSNotFound)
|
||||
&& ([_destinationAttributes
|
||||
indexOfObject: destinationAttribute]
|
||||
!= NSNotFound))
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"%@ -- %@ 0x%x: TODO",
|
||||
NSStringFromSelector(_cmd),
|
||||
NSStringFromClass([self class]),
|
||||
self];
|
||||
}
|
||||
|
||||
[self _flushCache];
|
||||
[self willChange];
|
||||
|
||||
EOFLOGObjectLevel(@"EORelationship", @"really add");
|
||||
EOFLOGObjectLevelArgs(@"EORelationship", @"XXjoins %p class%@",
|
||||
_joins, [_joins class]);
|
||||
|
||||
if (!_joins)
|
||||
_joins = [NSMutableArray new];
|
||||
|
||||
[(NSMutableArray *)_joins addObject: join];
|
||||
|
||||
EOFLOGObjectLevelArgs(@"EORelationship", @"XXjoins %p class%@",
|
||||
_joins, [_joins class]);
|
||||
|
||||
EOFLOGObjectLevel(@"EORelationship", @"added");
|
||||
|
||||
[self _joinsChanged];
|
||||
/* Ayers: Not sure what justifies this. */
|
||||
[_entity _setIsEdited];
|
||||
}
|
||||
EOAttribute *sourceAttribute = [join sourceAttribute];
|
||||
EOAttribute *destinationAttribute;
|
||||
|
||||
destinationAttribute = [join destinationAttribute];
|
||||
|
||||
if (([_sourceAttributes indexOfObject: sourceAttribute]
|
||||
!= NSNotFound)
|
||||
&& ([_destinationAttributes
|
||||
indexOfObject: destinationAttribute]
|
||||
!= NSNotFound))
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"%@ -- %@ 0x%x: TODO",
|
||||
NSStringFromSelector(_cmd),
|
||||
NSStringFromClass([self class]),
|
||||
self];
|
||||
}
|
||||
}
|
||||
|
||||
[self _flushCache];
|
||||
// do we still need willChange when we are not putting EORelationships into ECs? -- dw
|
||||
[self willChange];
|
||||
// needed for KV bbserving
|
||||
[self willChangeValueForKey:@"joins"];
|
||||
|
||||
EOFLOGObjectLevel(@"EORelationship", @"really add");
|
||||
EOFLOGObjectLevelArgs(@"EORelationship", @"XXjoins %p class%@",
|
||||
_joins, [_joins class]);
|
||||
|
||||
if (!_joins)
|
||||
_joins = [NSMutableArray new];
|
||||
|
||||
[(NSMutableArray *)_joins addObject: join];
|
||||
|
||||
EOFLOGObjectLevelArgs(@"EORelationship", @"XXjoins %p class%@",
|
||||
_joins, [_joins class]);
|
||||
|
||||
EOFLOGObjectLevel(@"EORelationship", @"added");
|
||||
|
||||
[self _joinsChanged];
|
||||
[self didChangeValueForKey:@"joins"];
|
||||
|
||||
/* Ayers: Not sure what justifies this. */
|
||||
[_entity _setIsEdited];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EOFLOGObjectFnStop();
|
||||
}
|
||||
|
||||
|
@ -1589,6 +1607,8 @@ relationships. Nil if none" **/
|
|||
self];
|
||||
else
|
||||
{
|
||||
[self willChangeValueForKey:@"joins"];
|
||||
|
||||
[self willChange];
|
||||
[(NSMutableArray *)_joins removeObject: join];
|
||||
|
||||
|
@ -1602,8 +1622,10 @@ relationships. Nil if none" **/
|
|||
_joins, [_joins class]);
|
||||
|
||||
[self _joinsChanged];
|
||||
|
||||
/* Ayers: Not sure what justifies this. */
|
||||
[_entity _setIsEdited];
|
||||
[self didChangeValueForKey:@"joins"];
|
||||
}
|
||||
|
||||
EOFLOGObjectFnStop();
|
||||
|
|
Loading…
Reference in a new issue