diff --git a/ChangeLog b/ChangeLog index ce2239e..1dd61ce 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2005-02-02 Matt Rice + + * EOAccess/EOEntity.m (-setName:): Validate the new name and remove + the checks from here. + (-validateName): Don't check if an attribute or a relationship with + the name exist. Check if an entity of the same name exists. + Return an exception with a valid reason in all cases. + * EOAccess/EOAttribute.m (validateName): Return an exception with a + valid reason in all cases. Don't check if a relationship with the + name exists. + * EOAccess/EOAttribute.m (validateName): Return an exception with a + valid reason in all cases. Don't check if a attribute with the + name exists. + 2005-01-27 David Ayers * EOAccess/EODatabase.h/m:(EODistantPastTimeInterval): Added diff --git a/EOAccess/EOAttribute.m b/EOAccess/EOAttribute.m index a2901f2..20e0573 100644 --- a/EOAccess/EOAttribute.m +++ b/EOAccess/EOAttribute.m @@ -739,10 +739,17 @@ static Class NSCalendarDateClass; if (!exc && *s == '$') exc++; + if (exc) + return [NSException exceptionWithName: NSInvalidArgumentException + reason: [NSString stringWithFormat:@"%@ -- %@ 0x%x: argument \"%@\" contains invalid char '%c'", + NSStringFromSelector(_cmd), + NSStringFromClass([self class]), + self, + name, + *p] + userInfo: nil]; if ([[self entity] attributeNamed:name]) exc++; - else if ([[self entity] relationshipNamed:name]) - exc++; else if ((storedProcedures = [[[self entity] model] storedProcedures])) { NSEnumerator *stEnum = [storedProcedures objectEnumerator]; @@ -768,16 +775,18 @@ static Class NSCalendarDateClass; } } } - - if (exc) - return [NSException exceptionWithName: NSInvalidArgumentException - reason: [NSString stringWithFormat:@"%@ -- %@ 0x%x: argument \"%@\" contains invalid chars", - NSStringFromSelector(_cmd), - NSStringFromClass([self class]), - self, - name] - userInfo: nil]; + if (exc) + { + return [NSException exceptionWithName: NSInvalidArgumentException + reason: [NSString stringWithFormat: @"%@ -- %@ 0x%x: \"%@\" already used in the model", + NSStringFromSelector(_cmd), + NSStringFromClass([self class]), + self, + name] + userInfo: nil]; + } + return nil; } diff --git a/EOAccess/EOEntity.m b/EOAccess/EOEntity.m index 7db857c..e1c87a3 100644 --- a/EOAccess/EOEntity.m +++ b/EOAccess/EOEntity.m @@ -1874,18 +1874,8 @@ createInstanceWithEditingContext:globalID:zone: - (void)setName: (NSString *)name { if (name && [name isEqual: _name]) return; - - if (name - && [name isEqual: _name] == NO - && [_model entityNamed: name] != nil) - { - [NSException raise: NSInvalidArgumentException - format: @"%@ -- %@ 0x%x: \"%@\" already used in the model", - NSStringFromSelector(_cmd), - NSStringFromClass([self class]), - self, - name]; - } + + [[self validateName: name] raise]; [self willChange]; ASSIGNCOPY(_name, name); @@ -2200,8 +2190,17 @@ createInstanceWithEditingContext:globalID:zone: } if (!exc && *s == '$') exc++; - if ([self attributeNamed: name]) exc++; - else if ([self relationshipNamed: name]) exc++; + if (exc) + return [NSException exceptionWithName: NSInvalidArgumentException + reason: [NSString stringWithFormat:@"%@ -- %@ 0x%x: argument \"%@\" contains invalid char '%c'", + NSStringFromSelector(_cmd), + NSStringFromClass([self class]), + self, + name, + *p] + userInfo: nil]; + + if ([_model entityNamed: name]) exc++; else if ((storedProcedures = [[self model] storedProcedures])) { NSEnumerator *stEnum = [storedProcedures objectEnumerator]; @@ -2226,17 +2225,19 @@ createInstanceWithEditingContext:globalID:zone: } } } - - if (exc) + + if (exc) + { return [NSException exceptionWithName: NSInvalidArgumentException - reason: [NSString stringWithFormat:@"%@ -- %@ 0x%x: argument \"%@\" contains invalid chars", - NSStringFromSelector(_cmd), - NSStringFromClass([self class]), - self, - name] - userInfo: nil]; - else - return nil; + reason: [NSString stringWithFormat: @"%@ -- %@ 0x%x: \"%@\" already used in the model", + NSStringFromSelector(_cmd), + NSStringFromClass([self class]), + self, + name] + userInfo: nil]; + } + + return nil; } - (void)addSubEntity: (EOEntity *)child diff --git a/EOAccess/EORelationship.m b/EOAccess/EORelationship.m index 86d1935..8b7d66f 100644 --- a/EOAccess/EORelationship.m +++ b/EOAccess/EORelationship.m @@ -1223,6 +1223,16 @@ relationships. Nil if none" **/ } if (!exc && *s == '$') exc++; + + if (exc) + return [NSException exceptionWithName: NSInvalidArgumentException + reason: [NSString stringWithFormat: @"%@ -- %@ 0x%x: argument \"%@\" contains invalid char '%c'", + NSStringFromSelector(_cmd), + NSStringFromClass([self class]), + self, + name, + *p] + userInfo: nil]; if ([[self entity] anyAttributeNamed: name]) exc++; @@ -1254,15 +1264,17 @@ relationships. Nil if none" **/ } if (exc) - return [NSException exceptionWithName: NSInvalidArgumentException - reason: [NSString stringWithFormat: @"%@ -- %@ 0x%x: argument \"%@\" contains invalid chars", - NSStringFromSelector(_cmd), - NSStringFromClass([self class]), - self, - name] + { + return [NSException exceptionWithName: NSInvalidArgumentException + reason: [NSString stringWithFormat: @"%@ -- %@ 0x%x: \"%@\" already used in the model", + NSStringFromSelector(_cmd), + NSStringFromClass([self class]), + self, + name] userInfo: nil]; - else - return nil; + } + + return nil; } - (void)setToMany: (BOOL)flag