* EOAccess/EOEntity.m (initWithPropertyList:owner:):

Reformatting for GNU coding standards.
        (-attributes): Fix memory leak.  Use global class cache.
        Handle partially converted attributes array.
        (-_attributeNameChangedFrom:to:): New privat method.
        * EOAccess/EOEntityPriv.h (-_attributeNameChangedFrom:to:):
        Declare new private method.
        * EOAccess/EOAttribute.m (setName:): Call
        -[EOEntity _attributeNameChangedFrom:to:] if attribute is in
        an EOEntity.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gdl2/trunk@20835 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
David Ayers 2005-03-03 12:17:57 +00:00
parent 627c340174
commit 6a28dfbc6e
4 changed files with 100 additions and 81 deletions

View file

@ -1,3 +1,17 @@
2005-03-03 Matt Rice <ratmice@yahoo.com>
David Ayers <d.ayers@inode.at>
* EOAccess/EOEntity.m (initWithPropertyList:owner:): Reformatting
for GNU coding standards.
(-attributes): Fix memory leak. Use global class cache.
Handle partially converted attributes array.
(-_attributeNameChangedFrom:to:): New privat method.
* EOAccess/EOEntityPriv.h (-_attributeNameChangedFrom:to:):
Declare new private method.
* EOAccess/EOAttribute.m (setName:): Call
-[EOEntity _attributeNameChangedFrom:to:] if attribute is in
an EOEntity.
2005-03-02 David Ayers <d.ayers@inode.at> 2005-03-02 David Ayers <d.ayers@inode.at>
* EOControl/EOKeyValueCoding.h/m: (-setNilValueForKey:): * EOControl/EOKeyValueCoding.h/m: (-setNilValueForKey:):

View file

@ -780,13 +780,19 @@ RCS_ID("$Id$")
- (void)setName: (NSString *)name - (void)setName: (NSString *)name
{ {
if ([_name isEqual: name]==NO)
{
NSString *oldName = nil;
[[self validateName: name] raise]; [[self validateName: name] raise];
oldName = AUTORELEASE(RETAIN(_name));
[self willChange]; [self willChange];
ASSIGN(_name, name); ASSIGN(_name, name);
if (_flags.isParentAnEOEntity) if (_flags.isParentAnEOEntity)
{ {
[_parent _setIsEdited]; [_parent _setIsEdited];
[_parent _attributeNameChangedFrom: oldName to: name];
}
} }
} }

View file

@ -111,7 +111,7 @@ NSString *EONextPrimaryKeyProcedureOperation = @"EONextPrimaryKeyProcedureOperat
}; };
/* Not documented becuase it is not a public method. */ /* Not documented becuase it is not a public method. */
- (id) initWithPropertyList: (NSDictionary*)propertyList - (id)initWithPropertyList: (NSDictionary*)propertyList
owner: (id)owner owner: (id)owner
{ {
[EOObserverCenter suppressObserverNotification]; [EOObserverCenter suppressObserverNotification];
@ -130,8 +130,8 @@ NSString *EONextPrimaryKeyProcedureOperation = @"EONextPrimaryKeyProcedureOperat
ASSIGN(_name, [propertyList objectForKey: @"name"]); ASSIGN(_name, [propertyList objectForKey: @"name"]);
[self setExternalName: [propertyList objectForKey: @"externalName"]]; [self setExternalName: [propertyList objectForKey: @"externalName"]];
[self setExternalQuery: tmpObject = [propertyList objectForKey: @"externalQuery"];
[propertyList objectForKey: @"externalQuery"]]; [self setExternalQuery: tmpObject];
tmpString = [propertyList objectForKey: @"restrictingQualifier"]; tmpString = [propertyList objectForKey: @"restrictingQualifier"];
@ -139,8 +139,8 @@ NSString *EONextPrimaryKeyProcedureOperation = @"EONextPrimaryKeyProcedureOperat
if (tmpString) if (tmpString)
{ {
EOQualifier *restrictingQualifier = EOQualifier *restrictingQualifier
[EOQualifier qualifierWithQualifierFormat: @"%@", tmpString]; = [EOQualifier qualifierWithQualifierFormat: @"%@", tmpString];
[self setRestrictingQualifier: restrictingQualifier]; [self setRestrictingQualifier: restrictingQualifier];
} }
@ -152,32 +152,20 @@ NSString *EONextPrimaryKeyProcedureOperation = @"EONextPrimaryKeyProcedureOperat
NSEmitTODO(); //TODO NSEmitTODO(); //TODO
} }
[self setReadOnly: [[propertyList objectForKey: @"isReadOnly"] tmpObject = [propertyList objectForKey: @"isReadOnly"];
boolValue]]; [self setReadOnly: [tmpObject boolValue]];
[self setCachesObjects: [[propertyList objectForKey: tmpObject = [propertyList objectForKey: @"cachesObjects"];
@"cachesObjects"] [self setCachesObjects: [tmpObject boolValue]];
boolValue]];
tmpObject = [propertyList objectForKey: @"userInfo"]; tmpObject = [propertyList objectForKey: @"userInfo"];
EOFLOGObjectLevelArgs(@"EOEntity", @"tmpObject=%@", tmpObject); EOFLOGObjectLevelArgs(@"EOEntity", @"tmpObject=%@", tmpObject);
/*NSAssert2((!tmpString
|| [tmpString isKindOfClass:[NSString class]]),
@"tmpString is not a NSString but a %@. tmpString:\n%@",
[tmpString class],
tmpString);
*/
if (tmpObject) if (tmpObject)
//[self setUserInfo:[tmpString propertyList]]; {
[self setUserInfo: tmpObject]; [self setUserInfo: tmpObject];
}
else else
{ {
tmpObject = [propertyList objectForKey: @"userDictionary"]; tmpObject = [propertyList objectForKey: @"userDictionary"];
/*NSAssert2((!tmpString
|| [tmpString isKindOfClass:[NSString class]]),
@"tmpString is not a NSString but a %@ tmpString:\n%@",
[tmpString class],
tmpString);*/
[self setUserInfo: tmpObject]; [self setUserInfo: tmpObject];
} }
@ -189,8 +177,8 @@ NSString *EONextPrimaryKeyProcedureOperation = @"EONextPrimaryKeyProcedureOperat
[self _setInternalInfo: tmpObject]; [self _setInternalInfo: tmpObject];
[self setDocComment:[propertyList objectForKey:@"docComment"]]; [self setDocComment:[propertyList objectForKey:@"docComment"]];
[self setClassName: [propertyList objectForKey: @"className"]]; [self setClassName: [propertyList objectForKey: @"className"]];
[self setIsAbstractEntity: tmpObject = [propertyList objectForKey: @"isAbstractEntity"];
[[propertyList objectForKey: @"isAbstractEntity"] boolValue]]; [self setIsAbstractEntity: [tmpObject boolValue]];
tmpString = [propertyList objectForKey: @"isFetchable"]; tmpString = [propertyList objectForKey: @"isFetchable"];
@ -218,8 +206,8 @@ NSString *EONextPrimaryKeyProcedureOperation = @"EONextPrimaryKeyProcedureOperat
_flags.attributesUsedForLockingIsLazy = YES; _flags.attributesUsedForLockingIsLazy = YES;
} }
array = [[propertyList objectForKey: @"primaryKeyAttributes"] array = [propertyList objectForKey: @"primaryKeyAttributes"];
sortedArrayUsingSelector: @selector(compare:)]; array = [array sortedArrayUsingSelector: @selector(compare:)];
EOFLOGObjectLevelArgs(@"EOEntity", @"primaryKeyAttributes: %@", EOFLOGObjectLevelArgs(@"EOEntity", @"primaryKeyAttributes: %@",
array); array);
@ -262,8 +250,8 @@ NSString *EONextPrimaryKeyProcedureOperation = @"EONextPrimaryKeyProcedureOperat
NSEmitTODO(); //TODO NSEmitTODO(); //TODO
} }
tmpString = [propertyList objectForKey: tmpString
@"maxNumberOfInstancesToBatchFetch"]; = [propertyList objectForKey: @"maxNumberOfInstancesToBatchFetch"];
EOFLOGObjectLevelArgs(@"EOEntity", EOFLOGObjectLevelArgs(@"EOEntity",
@"maxNumberOfInstancesToBatchFetch=%@ [%@]", @"maxNumberOfInstancesToBatchFetch=%@ [%@]",
@ -279,8 +267,8 @@ NSString *EONextPrimaryKeyProcedureOperation = @"EONextPrimaryKeyProcedureOperat
//[self setBatchFaultingMaxSize: [tmpString intValue]]; //[self setBatchFaultingMaxSize: [tmpString intValue]];
} }
tmpObject = [propertyList objectForKey: tmpObject
@"fetchSpecificationDictionary"]; = [propertyList objectForKey: @"fetchSpecificationDictionary"];
EOFLOGObjectLevelArgs(@"EOEntity", EOFLOGObjectLevelArgs(@"EOEntity",
@"fetchSpecificationDictionary=%@ [%@]", @"fetchSpecificationDictionary=%@ [%@]",
@ -310,7 +298,8 @@ NSString *EONextPrimaryKeyProcedureOperation = @"EONextPrimaryKeyProcedureOperat
NSString* path; NSString* path;
fileName = [NSString stringWithFormat: @"%@.fspec", _name]; fileName = [NSString stringWithFormat: @"%@.fspec", _name];
path = [[(EOModel *)owner path] stringByAppendingPathComponent: fileName]; path = [(EOModel *)owner path];
path = [path stringByAppendingPathComponent: fileName];
if ([[NSFileManager defaultManager] fileExistsAtPath: path]) if ([[NSFileManager defaultManager] fileExistsAtPath: path])
plist plist
= [[NSString stringWithContentsOfFile: path] propertyList]; = [[NSString stringWithContentsOfFile: path] propertyList];
@ -322,13 +311,13 @@ NSString *EONextPrimaryKeyProcedureOperation = @"EONextPrimaryKeyProcedureOperat
NSEnumerator *variablesEnum; NSEnumerator *variablesEnum;
id fetchSpecName; id fetchSpecName;
unarchiver = AUTORELEASE([[EOKeyValueUnarchiver alloc] unarchiver
= AUTORELEASE([[EOKeyValueUnarchiver alloc]
initWithDictionary: initWithDictionary:
[NSDictionary dictionaryWithObject: plist [NSDictionary dictionaryWithObject: plist
forKey: @"fspecs"]]); forKey: @"fspecs"]]);
variables = [unarchiver decodeObjectForKey: @"fspecs"]; variables = [unarchiver decodeObjectForKey: @"fspecs"];
//NSLog(@"fspecs variables:%@",variables);
[unarchiver finishInitializationOfObjects]; [unarchiver finishInitializationOfObjects];
[unarchiver awakeObjects]; [unarchiver awakeObjects];
@ -338,8 +327,6 @@ NSString *EONextPrimaryKeyProcedureOperation = @"EONextPrimaryKeyProcedureOperat
{ {
id fetchSpec = [variables objectForKey: fetchSpecName]; id fetchSpec = [variables objectForKey: fetchSpecName];
//NSLog(@"fetchSpecName:%@ fetchSpec:%@", fetchSpecName, fetchSpec);
[self addFetchSpecification: fetchSpec [self addFetchSpecification: fetchSpec
withName: fetchSpecName]; withName: fetchSpecName];
} }
@ -357,9 +344,6 @@ NSString *EONextPrimaryKeyProcedureOperation = @"EONextPrimaryKeyProcedureOperat
NSLog(@"exception in EOEntity initWithPropertyList:owner:"); NSLog(@"exception in EOEntity initWithPropertyList:owner:");
NSLog(@"exception=%@", localException); NSLog(@"exception=%@", localException);
/* localException=ExceptionByAddingUserInfoObjectFrameInfo(localException,
@"In EOEntity initWithPropertyList:owner:");*/
NSLog(@"exception=%@", localException); NSLog(@"exception=%@", localException);
[localException raise]; [localException raise];
} }
@ -933,13 +917,12 @@ NSString *EONextPrimaryKeyProcedureOperation = @"EONextPrimaryKeyProcedureOperat
- (NSArray *)attributes - (NSArray *)attributes
{ {
//OK
if (_flags.attributesIsLazy) if (_flags.attributesIsLazy)
{ {
int count = 0; int count = 0;
EOFLOGObjectLevelArgs(@"EOEntity", @"START construct attributes on %p", EOFLOGObjectLevelArgs(@"EOEntity",
self); @"START construct attributes on %p", self);
count = [_attributes count]; count = [_attributes count];
EOFLOGObjectLevelArgs(@"EOEntity", @"Entity %@: Lazy _attributes=%@", EOFLOGObjectLevelArgs(@"EOEntity", @"Entity %@: Lazy _attributes=%@",
@ -949,17 +932,17 @@ NSString *EONextPrimaryKeyProcedureOperation = @"EONextPrimaryKeyProcedureOperat
if (count > 0) if (count > 0)
{ {
int i = 0; int i = 0;
NSArray *attributePLists = _attributes; NSArray *attributePLists = AUTORELEASE(RETAIN(_attributes));
NSDictionary *relationshipsByName = nil; NSDictionary *relationshipsByName = nil;
DESTROY(_attributes);
DESTROY(_attributesByName); DESTROY(_attributesByName);
_attributes = [GCMutableArray new]; _attributes = [GCMutableArray new];
_attributesByName = [GCMutableDictionary new]; _attributesByName = [GCMutableDictionary new];
NSAssert2((!_attributesByName NSAssert2((!_attributesByName
|| [_attributesByName isKindOfClass: || [_attributesByName isKindOfClass: GDL2_NSDictionaryClass]),
[NSDictionary class]]),
@"_attributesByName is not a NSDictionary but a %@. _attributesByName [%p]", @"_attributesByName is not a NSDictionary but a %@. _attributesByName [%p]",
[_attributesByName class], [_attributesByName class],
_attributesByName); _attributesByName);
@ -978,16 +961,22 @@ NSString *EONextPrimaryKeyProcedureOperation = @"EONextPrimaryKeyProcedureOperat
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
{ {
NSDictionary *attrPList = [attributePLists objectAtIndex: i]; id attrPList = [attributePLists objectAtIndex: i];
EOAttribute *attribute = [EOAttribute EOAttribute *attribute = nil;
attributeWithPropertyList: NSString *attributeName = nil;
attrPList
owner: self];
NSString *attributeName = [attribute name];
EOFLOGObjectLevelArgs(@"EOEntity", @"XXX 1 ATTRIBUTE: attribute=%@", attribute = [attrPList isKindOfClass: GDL2_EOAttributeClass]
? attrPList
: [EOAttribute attributeWithPropertyList: attrPList
owner: self];
attributeName = [attribute name];
EOFLOGObjectLevelArgs(@"EOEntity",
@"XXX 1 ATTRIBUTE: attribute=%@",
attribute); attribute);
/* We just created this dictionary so the ivar is
initialized. */
if ([_attributesByName objectForKey: attributeName]) if ([_attributesByName objectForKey: attributeName])
{ {
[NSException raise: NSInvalidArgumentException [NSException raise: NSInvalidArgumentException
@ -1077,24 +1066,28 @@ NSString *EONextPrimaryKeyProcedureOperation = @"EONextPrimaryKeyProcedureOperat
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
{ {
NSString *attrName = [attrNames objectAtIndex: i]; NSString *attrName = [attrNames objectAtIndex: i];
NSDictionary *attrPList = [attributePLists NSDictionary *attrPList = nil;
objectAtIndex: i];
EOAttribute *attribute = nil; EOAttribute *attribute = nil;
id definition = nil;
EOFLOGObjectLevelArgs(@"EOEntity", @"XXX attrName=%@", EOFLOGObjectLevelArgs(@"EOEntity", @"XXX attrName=%@",
attrName); attrName);
if ((pass == 0 && attrPList = [attributePLists objectAtIndex: i];
![attrPList objectForKey: @"definition"]) if ([attrPList isKindOfClass: GDL2_EOAttributeClass])
|| (pass == 1 continue;
&& [attrPList objectForKey: @"definition"])) definition = [attrPList objectForKey: @"definition"];
if ((pass == 0 && definition == nil)
|| (pass == 1 && definition != nil))
{ {
attribute = [self attributeNamed: attrName]; attribute = [self attributeNamed: attrName];
EOFLOGObjectLevelArgs(@"EOEntity", @"XXX 2A ATTRIBUTE: self=%p AWAKE attribute=%@", EOFLOGObjectLevelArgs(@"EOEntity",
@"XXX 2A ATTRIBUTE: self=%p AWAKE attribute=%@",
self, attribute); self, attribute);
[attribute awakeWithPropertyList: attrPList]; [attribute awakeWithPropertyList: attrPList];
EOFLOGObjectLevelArgs(@"EOEntity", @"XXX 2B ATTRIBUTE: self=%p attribute=%@", EOFLOGObjectLevelArgs(@"EOEntity",
@"XXX 2B ATTRIBUTE: self=%p attribute=%@",
self, attribute); self, attribute);
} }
} }
@ -1109,15 +1102,12 @@ NSString *EONextPrimaryKeyProcedureOperation = @"EONextPrimaryKeyProcedureOperat
} }
NS_HANDLER NS_HANDLER
{ {
DESTROY(attributePLists);
_flags.updating = NO; _flags.updating = NO;
[EOObserverCenter enableObserverNotification]; [EOObserverCenter enableObserverNotification];
[localException raise]; [localException raise];
} }
NS_ENDHANDLER; NS_ENDHANDLER;
DESTROY(attributePLists);
_flags.updating = NO; _flags.updating = NO;
[EOObserverCenter enableObserverNotification]; [EOObserverCenter enableObserverNotification];
[_attributes sortUsingSelector: @selector(eoCompareOnName:)];//Very important to have always the same order. [_attributes sortUsingSelector: @selector(eoCompareOnName:)];//Very important to have always the same order.
@ -1973,8 +1963,8 @@ createInstanceWithEditingContext:globalID:zone:
if ([self createsMutableObjects]) if ([self createsMutableObjects])
[(GCMutableArray *)_attributes addObject: attribute]; [(GCMutableArray *)_attributes addObject: attribute];
else else
_attributes = RETAIN([AUTORELEASE(_attributes) _attributes
arrayByAddingObject: attribute]); = RETAIN([AUTORELEASE(_attributes) arrayByAddingObject: attribute]);
if (_attributesByName == nil) if (_attributesByName == nil)
{ {
@ -2858,6 +2848,14 @@ createInstanceWithEditingContext:globalID:zone:
EOFLOGObjectLevelArgs(@"EOEntity", @"STOP%s", ""); EOFLOGObjectLevelArgs(@"EOEntity", @"STOP%s", "");
} }
- (void)_attributeNameChangedFrom: (NSString *)oldName to: (NSString *)newName
{
EOAttribute *attribute = [_attributesByName objectForKey: oldName];
[_attributesByName setObject: attribute forKey: newName];
[_attributesByName removeObjectForKey: oldName];
}
/** Returns attributes by name (only attributes, not relationships) **/ /** Returns attributes by name (only attributes, not relationships) **/
- (NSDictionary*)attributesByName - (NSDictionary*)attributesByName
{ {

View file

@ -87,6 +87,7 @@
- (EOMKKDInitializer *)_propertyDictionaryInitializer; - (EOMKKDInitializer *)_propertyDictionaryInitializer;
- (EOMKKDInitializer *)_instanceDictionaryInitializer; - (EOMKKDInitializer *)_instanceDictionaryInitializer;
- (void)_setIsEdited; - (void)_setIsEdited;
- (void)_attributeNameChangedFrom: (NSString *)oldName to: (NSString *)newName;
- (NSArray *)_classPropertyAttributes; - (NSArray *)_classPropertyAttributes;
- (Class)classForObjectWithGlobalID: (EOKeyGlobalID *)globalID; - (Class)classForObjectWithGlobalID: (EOKeyGlobalID *)globalID;