* EOAccess/EOModel.m (-addEntity:): Reword assertion message.

(-_setEntity:forEntityName:className:): Add assertion.
        * EOAccess/EOAttribute.m (-initWithPropertyList:owner:): Validate the
        name.
        * EOAccess/EORelationship.m (-initWithPropertyList:owner:): Ditto.
        * EOAccess/EOEntity.m (-initWithPropertyList:owner:): Ditto.
        (-attributes): Remove checks for duplicate names.
        (-relationships): Remove checks for duplicate names.



git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gdl2/trunk@26275 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
ratmice 2008-03-11 19:43:57 +00:00
parent ec8cbbc72b
commit 86f1337534
5 changed files with 42 additions and 69 deletions

View file

@ -1,3 +1,14 @@
2008-03-11 Matt Rice <ratmice@gmail.com>
* EOAccess/EOModel.m (-addEntity:): Reword assertion message.
(-_setEntity:forEntityName:className:): Add assertion.
* EOAccess/EOAttribute.m (-initWithPropertyList:owner:): Validate the
name.
* EOAccess/EORelationship.m (-initWithPropertyList:owner:): Ditto.
* EOAccess/EOEntity.m (-initWithPropertyList:owner:): Ditto.
(-attributes): Remove checks for duplicate names.
(-relationships): Remove checks for duplicate names.
2008-03-06 David Ayers <ayers@fsfe.org>
* DBModeler/GNUmakefile,

View file

@ -109,12 +109,13 @@ RCS_ID("$Id$")
NSString *tmpString = nil;
id tmpObject = nil;
// set this first so the name can validate against the parent.
[self setParent: owner];
[self setName: [propertyList objectForKey: @"name"]];
EOFLOGObjectLevelArgs(@"gsdb", @"Attribute parent=%p %@",
owner, [(EOEntity *)owner name]);
[self setParent: owner];
// EOFLOGObjectLevel(@"gsdb", @"Attribute Entity=%@", [self entity]);
[self setExternalType: [propertyList objectForKey: @"externalType"]];

View file

@ -181,7 +181,20 @@ NSString *EONextPrimaryKeyProcedureOperation = @"EONextPrimaryKeyProcedureOperat
id tmpObject = nil;
_flags.updating = YES;
ASSIGN(_name, [propertyList objectForKey: @"name"]);
/* set this before validation. */
if ([owner isKindOfClass:[EOModel class]])
[self _setModel:owner];
// else _setParent:??
tmpString = [propertyList objectForKey:@"name"];
/*
we dont want it to call _updateCache. So we validate and
set the name directly, as we haven't been added to the model yet,
and this would causes problems.
*/
[[self validateName:tmpString] raise];
ASSIGN(_name, tmpString);
[self setExternalName: [propertyList objectForKey: @"externalName"]];
tmpObject = [propertyList objectForKey: @"externalQuery"];
@ -748,7 +761,6 @@ static void performSelectorOnArrayWithEachObjectOfClass(NSArray *arr, SEL select
{
int i = 0;
NSArray *attributePLists = AUTORELEASE(RETAIN(_attributes));
NSDictionary *relationshipsByName = nil;
DESTROY(_attributes);
DESTROY(_attributesByName);
@ -756,8 +768,9 @@ static void performSelectorOnArrayWithEachObjectOfClass(NSArray *arr, SEL select
_attributes = [NSMutableArray new];
_attributesByName = [NSMutableDictionary new];
if (!_flags.relationshipsIsLazy)
relationshipsByName = [self relationshipsByName];
/* if we've already loaded relationships rebuild the name cache */
if (!_flags.relationshipsIsLazy && _relationshipsByName == nil)
[self relationshipsByName];
_flags.attributesIsLazy = NO;
@ -773,38 +786,13 @@ static void performSelectorOnArrayWithEachObjectOfClass(NSArray *arr, SEL select
id attrPList = [attributePLists objectAtIndex: i];
EOAttribute *attribute = nil;
NSString *attributeName = nil;
// this should validate name against its owner via setName:
attribute = [EOAttribute attributeWithPropertyList: attrPList
owner: self];
attributeName = [attribute name];
EOFLOGObjectLevelArgs(@"EOEntity",
@"XXX 1 ATTRIBUTE: attribute=%@",
attribute);
/* We just created this dictionary so the ivar is
initialized. */
// FIXME -validatename instead? or checks for invalid name
if ([_attributesByName objectForKey: attributeName])
{
[NSException raise: NSInvalidArgumentException
format: @"%@ -- %@ 0x%x: \"%@\" already used in the model as attribute",
NSStringFromSelector(_cmd),
NSStringFromClass([self class]),
self,
attributeName];
}
if ([relationshipsByName objectForKey: attributeName])
{
[NSException raise: NSInvalidArgumentException
format: @"%@ -- %@ 0x%x: \"%@\" already used in the model",
NSStringFromSelector(_cmd),
NSStringFromClass([self class]),
self,
attributeName];
}
// don't call -addAttribute: because it wipes our name cache
[_attributes addObject: attribute];
[_attributesByName setObject: attribute
forKey: attributeName];
@ -941,17 +929,14 @@ static void performSelectorOnArrayWithEachObjectOfClass(NSArray *arr, SEL select
{
int i = 0;
NSArray *relationshipPLists = _relationships;
NSDictionary *attributesByName = nil;
DESTROY(_relationshipsByName);
_relationships = [NSMutableArray new];
_relationshipsByName = [NSMutableDictionary new];
if (!_flags.attributesIsLazy)
{
attributesByName = [self attributesByName];
}
if (!_flags.attributesIsLazy && _attributesByName == nil)
[self attributesByName];
_flags.relationshipsIsLazy = NO;
[EOObserverCenter suppressObserverNotification];
@ -968,41 +953,13 @@ static void performSelectorOnArrayWithEachObjectOfClass(NSArray *arr, SEL select
EORelationship *relationship = nil;
NSString *relationshipName = nil;
/* this should cause validation to occur. */
relationship= [EORelationship
relationshipWithPropertyList: attrPList
owner: self];
relationshipName = [relationship name];
EOFLOGObjectLevelArgs(@"EOEntity", @"relationshipName: %@",
relationshipName);
// FIXME -validatename instead (also checks for invalid name)
if ([attributesByName objectForKey: relationshipName])
{
[NSException raise: NSInvalidArgumentException
format: @"%@ -- %@ 0x%x: \"%@\" already used in the model as attribute",
NSStringFromSelector(_cmd),
NSStringFromClass([self class]),
self,
relationshipName];
}
if ([_relationshipsByName objectForKey: relationshipName])
{
[NSException raise: NSInvalidArgumentException
format: @"%@ -- %@ 0x%x: \"%@\" already used in the model",
NSStringFromSelector(_cmd),
NSStringFromClass([self class]),
self,
relationshipName];
}
EOFLOGObjectLevelArgs(@"EOEntity", @"Add rel %p",
relationship);
EOFLOGObjectLevelArgs(@"EOEntity", @"Add rel=%@",
relationship);
[_relationships addObject: relationship];
[_relationshipsByName setObject: relationship
forKey: relationshipName];

View file

@ -1358,6 +1358,9 @@ NSString *EOEntityLoadedNotification = @"EOEntityLoadedNotification";
NSAssert(entityName, @"No entity name");
NSAssert(className, @"No class name");
NSAssert1([_entitiesByName objectForKey: entityName] == nil,
@"Entity '%@' is already registered with this model",
entityName);
//Seems OK
[_entitiesByName setObject: entity
forKey: entityName];
@ -1430,7 +1433,7 @@ NSString *EOEntityLoadedNotification = @"EOEntityLoadedNotification";
NSString *className = nil;
NSAssert1([self entityNamed: [entity name]] == nil,
@"Entity '%@' already registered as with this model",
@"Entity '%@' is already registered with this model",
entityName);
NSAssert2([entity model]==nil,

View file

@ -146,8 +146,9 @@ RCS_ID("$Id$")
model = [owner model];
relationshipName = [propertyList objectForKey: @"name"];
[self setName: relationshipName];
/* so setName: can validate against the owner */
[self setEntity: owner];
[self setName: relationshipName];
destinationEntityName = [propertyList objectForKey: @"destination"];