Call -willChange: to support EOObserving in EOModel, EOEntity, EOAttribute,

EORelationship, EOStoredProcedure.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gdl2/trunk@20745 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Matt Rice 2005-02-18 16:46:38 +00:00
parent 6b4ef319c9
commit 74a8e976bf
6 changed files with 87 additions and 1 deletions

View file

@ -1,3 +1,37 @@
2005-02-18 Matt Rice <ratmice@yahoo.com>
* EOAccess/EOModel.m (-addEntity:, -setName:): Call -willChange:
when modifying the receiver.
(-setConnectionDictionary:, -addEntity:, -removeEntity:): Ditto.
(-addStoredProcedure:, -removeStoredProcedure:, -setAdaptorName): Ditto.
* EOAccess/EOAttribute.m (-setName:, -setProtoType:,): Ditto.
(-setDefinition:, -setReadOnly:, -setWidth:, -setPrecision:): Ditto.
(-setScale:, -setWriteFormat:, -setReadFormat:): Ditto.
(-setParameterDirection:, -setServerTimeZone:): Ditto.
(-setValueFactoryMethodName:): Ditto.
(-setAdaptorValueConversionMethodName:): Ditto.
(-setFactoryMethodArgumentType:): Ditto.
* EOAccess/EOEntity.m (-setRestrictingQualifier:): Ditto.
(-setCachesObjects:, -setReadOnly:, -addAttribute:): Ditto.
(-removeAttribute:, -addRelationship:, -removeRelationship:): Ditto.
(-addFetchSpecification:withName:): Ditto.
(-removeFetchSpecificationNamed:): Ditto.
(-setClassProperties:, -setPrimaryKeyAttributes:): Ditto.
(-setAttributesUsedForLocking:, -addSubEntity:): Ditto.
(-removeSubEntity:, -setIsAbstractEntity:): Ditto.
(-setMaxNumberOfInstancesToBatch:): Ditto.
(-setStoredProcedure:forOperation:): Ditto.
(-setParentEntity:): Ditto, And add comments
* EOAccess/EORelationship.m (setToMany:): Call -willChange when
modifying the receiver
(-setNumberOfToManyFaultsToBatch:, -setDeleteRule:): Ditto.
(-setInverseRelationship:): Ditto and comment.
(-removeJoin:): Move -willChange call after error handling.
* EOAccess/EOStoredProcedure: Include EOObserving headers.
(-setName:, -setExternalName:, -setArguments:): Call -willChange:
when modifying the receiver.
(-setUserInfo:): Ditto.
2005-02-17 David Ayers <d.ayers@inode.at> 2005-02-17 David Ayers <d.ayers@inode.at>
* EOAccess/EOEntity.m: Remove unnecessary include. * EOAccess/EOEntity.m: Remove unnecessary include.

View file

@ -782,6 +782,7 @@ RCS_ID("$Id$")
{ {
[[self validateName: name] raise]; [[self validateName: name] raise];
[self willChange];
ASSIGN(_name, name); ASSIGN(_name, name);
if (_flags.isParentAnEOEntity) if (_flags.isParentAnEOEntity)
{ {
@ -792,6 +793,7 @@ RCS_ID("$Id$")
- (void)setPrototype: (EOAttribute *)prototype - (void)setPrototype: (EOAttribute *)prototype
{ {
[self willChange];
ASSIGN(_prototype, prototype); ASSIGN(_prototype, prototype);
} }
@ -857,6 +859,7 @@ return nexexp
{ {
if(definition) if(definition)
{ {
[self willChange];
[self _setDefinitionWithoutFlushingCaches: definition]; [self _setDefinitionWithoutFlushingCaches: definition];
[_parent _setIsEdited]; [_parent _setIsEdited];
DESTROY(_columnName);//?? DESTROY(_columnName);//??
@ -872,6 +875,7 @@ return nexexp
NSStringFromClass([self class]), NSStringFromClass([self class]),
self]; self];
[self willChange];
_flags.isReadOnly = yn; _flags.isReadOnly = yn;
} }
@ -916,16 +920,19 @@ return nexexp
- (void)setWidth: (unsigned)length - (void)setWidth: (unsigned)length
{ {
[self willChange];
_width = length; _width = length;
} }
- (void)setPrecision: (unsigned)precision - (void)setPrecision: (unsigned)precision
{ {
[self willChange];
_precision = precision; _precision = precision;
} }
- (void)setScale: (int)scale - (void)setScale: (int)scale
{ {
[self willChange];
_scale = scale; _scale = scale;
} }
@ -941,16 +948,19 @@ return nexexp
- (void)setWriteFormat: (NSString *)string - (void)setWriteFormat: (NSString *)string
{ {
[self willChange];
ASSIGN(_writeFormat, string); ASSIGN(_writeFormat, string);
} }
- (void)setReadFormat: (NSString *)string - (void)setReadFormat: (NSString *)string
{ {
[self willChange];
ASSIGN(_readFormat, string); ASSIGN(_readFormat, string);
} }
- (void)setParameterDirection: (EOParameterDirection)parameterDirection - (void)setParameterDirection: (EOParameterDirection)parameterDirection
{ {
[self willChange];
_parameterDirection = parameterDirection; _parameterDirection = parameterDirection;
} }
@ -1051,6 +1061,7 @@ return nexexp
- (void)setServerTimeZone: (NSTimeZone *)tz - (void)setServerTimeZone: (NSTimeZone *)tz
{ {
[self willChange];
ASSIGN(_serverTimeZone, tz); ASSIGN(_serverTimeZone, tz);
} }
@ -1360,12 +1371,14 @@ return nexexp
- (void)setValueFactoryMethodName: (NSString *)factoryMethodName - (void)setValueFactoryMethodName: (NSString *)factoryMethodName
{ {
[self willChange];
ASSIGN(_valueFactoryMethodName, factoryMethodName); ASSIGN(_valueFactoryMethodName, factoryMethodName);
_valueFactoryMethod = NSSelectorFromString(_valueFactoryMethodName); _valueFactoryMethod = NSSelectorFromString(_valueFactoryMethodName);
} }
- (void)setAdaptorValueConversionMethodName: (NSString *)conversionMethodName - (void)setAdaptorValueConversionMethodName: (NSString *)conversionMethodName
{ {
[self willChange];
ASSIGN(_adaptorValueConversionMethodName, conversionMethodName); ASSIGN(_adaptorValueConversionMethodName, conversionMethodName);
_adaptorValueConversionMethod = NSSelectorFromString(_adaptorValueConversionMethodName); _adaptorValueConversionMethod = NSSelectorFromString(_adaptorValueConversionMethodName);
@ -1373,6 +1386,7 @@ return nexexp
- (void)setFactoryMethodArgumentType: (EOFactoryMethodArgumentType)argumentType - (void)setFactoryMethodArgumentType: (EOFactoryMethodArgumentType)argumentType
{ {
[self willChange];
_argumentType = argumentType; _argumentType = argumentType;
} }

View file

@ -1929,18 +1929,21 @@ createInstanceWithEditingContext:globalID:zone:
- (void)setRestrictingQualifier: (EOQualifier *)qualifier - (void)setRestrictingQualifier: (EOQualifier *)qualifier
{ {
[self willChange];
ASSIGN(_restrictingQualifier, qualifier); ASSIGN(_restrictingQualifier, qualifier);
} }
- (void)setReadOnly: (BOOL)flag - (void)setReadOnly: (BOOL)flag
{ {
//OK //OK
[self willChange];
_flags.isReadOnly = flag; _flags.isReadOnly = flag;
} }
- (void)setCachesObjects: (BOOL)flag - (void)setCachesObjects: (BOOL)flag
{ {
//OK //OK
[self willChange];
_flags.cachesObjects = flag; _flags.cachesObjects = flag;
} }
@ -1965,6 +1968,7 @@ createInstanceWithEditingContext:globalID:zone:
NSStringFromClass([[attribute parent] class]), NSStringFromClass([[attribute parent] class]),
[(EOEntity *)[attribute parent] name]); [(EOEntity *)[attribute parent] name]);
[self willChange];
if ([self createsMutableObjects]) if ([self createsMutableObjects])
[(GCMutableArray *)_attributes addObject: attribute]; [(GCMutableArray *)_attributes addObject: attribute];
else else
@ -1985,6 +1989,7 @@ createInstanceWithEditingContext:globalID:zone:
{ {
if (attribute) if (attribute)
{ {
[self willChange];
[attribute setParent: nil]; [attribute setParent: nil];
NSEmitTODO(); //TODO NSEmitTODO(); //TODO
@ -2026,6 +2031,7 @@ createInstanceWithEditingContext:globalID:zone:
self, self,
relationshipName]; relationshipName];
[self willChange];
if ([self createsMutableObjects]) if ([self createsMutableObjects])
[(GCMutableArray *)_relationships addObject: relationship]; [(GCMutableArray *)_relationships addObject: relationship];
else else
@ -2049,6 +2055,7 @@ createInstanceWithEditingContext:globalID:zone:
//TODO //TODO
if (relationship) if (relationship)
{ {
[self willChange];
[relationship setEntity:nil]; [relationship setEntity:nil];
if(_relationshipsByName != nil) if(_relationshipsByName != nil)
@ -2077,6 +2084,7 @@ createInstanceWithEditingContext:globalID:zone:
_fetchSpecificationDictionary = [NSMutableDictionary new]; _fetchSpecificationDictionary = [NSMutableDictionary new];
} }
[self willChange];
[_fetchSpecificationDictionary setObject: fetchSpec forKey: name]; [_fetchSpecificationDictionary setObject: fetchSpec forKey: name];
ASSIGN(_fetchSpecificationNames, [[_fetchSpecificationDictionary allKeys] ASSIGN(_fetchSpecificationNames, [[_fetchSpecificationDictionary allKeys]
sortedArrayUsingSelector: sortedArrayUsingSelector:
@ -2085,6 +2093,7 @@ createInstanceWithEditingContext:globalID:zone:
- (void)removeFetchSpecificationNamed: (NSString *)name - (void)removeFetchSpecificationNamed: (NSString *)name
{ {
[self willChange];
[_fetchSpecificationDictionary removeObjectForKey:name]; [_fetchSpecificationDictionary removeObjectForKey:name];
ASSIGN(_fetchSpecificationNames, [[_fetchSpecificationDictionary allKeys] ASSIGN(_fetchSpecificationNames, [[_fetchSpecificationDictionary allKeys]
sortedArrayUsingSelector: sortedArrayUsingSelector:
@ -2138,6 +2147,7 @@ createInstanceWithEditingContext:globalID:zone:
if (![self isValidClassProperty: [properties objectAtIndex:i]]) if (![self isValidClassProperty: [properties objectAtIndex:i]])
return NO; return NO;
[self willChange];
DESTROY(_classProperties); DESTROY(_classProperties);
if ([properties isKindOfClass:[GCArray class]] if ([properties isKindOfClass:[GCArray class]]
|| [properties isKindOfClass: [GCMutableArray class]]) || [properties isKindOfClass: [GCMutableArray class]])
@ -2158,6 +2168,7 @@ createInstanceWithEditingContext:globalID:zone:
if (![self isValidPrimaryKeyAttribute: [keys objectAtIndex:i]]) if (![self isValidPrimaryKeyAttribute: [keys objectAtIndex:i]])
return NO; return NO;
[self willChange];
DESTROY(_primaryKeyAttributes); DESTROY(_primaryKeyAttributes);
if ([keys isKindOfClass:[GCArray class]] if ([keys isKindOfClass:[GCArray class]]
@ -2179,6 +2190,7 @@ createInstanceWithEditingContext:globalID:zone:
if (![self isValidAttributeUsedForLocking: [attributes objectAtIndex: i]]) if (![self isValidAttributeUsedForLocking: [attributes objectAtIndex: i]])
return NO; return NO;
[self willChange];
DESTROY(_attributesUsedForLocking); DESTROY(_attributesUsedForLocking);
if ([attributes isKindOfClass: [GCArray class]] // TODO if ([attributes isKindOfClass: [GCArray class]] // TODO
@ -2268,12 +2280,14 @@ createInstanceWithEditingContext:globalID:zone:
- (void)addSubEntity: (EOEntity *)child - (void)addSubEntity: (EOEntity *)child
{ {
[self willChange];
[_subEntities addObject: child]; [_subEntities addObject: child];
[child setParentEntity: self]; [child setParentEntity: self];
} }
- (void)removeSubEntity: (EOEntity *)child - (void)removeSubEntity: (EOEntity *)child
{ {
[self willChange];
[child setParentEntity: nil]; [child setParentEntity: nil];
[_subEntities removeObject: child]; [_subEntities removeObject: child];
} }
@ -2281,11 +2295,13 @@ createInstanceWithEditingContext:globalID:zone:
- (void)setIsAbstractEntity: (BOOL)flag - (void)setIsAbstractEntity: (BOOL)flag
{ {
//OK //OK
[self willChange];
_flags.isAbstractEntity = flag; _flags.isAbstractEntity = flag;
} }
- (void)setMaxNumberOfInstancesToBatchFetch: (unsigned int)size - (void)setMaxNumberOfInstancesToBatchFetch: (unsigned int)size
{ {
[self willChange];
_batchCount = size; _batchCount = size;
} }
@ -2404,6 +2420,7 @@ createInstanceWithEditingContext:globalID:zone:
- (void)setStoredProcedure: (EOStoredProcedure *)storedProcedure - (void)setStoredProcedure: (EOStoredProcedure *)storedProcedure
forOperation: (NSString *)operation forOperation: (NSString *)operation
{ {
[self willChange];
[_storedProcedures setObject: storedProcedure [_storedProcedures setObject: storedProcedure
forKey: operation]; forKey: operation];
} }
@ -2618,8 +2635,12 @@ createInstanceWithEditingContext:globalID:zone:
_model = model; _model = model;
} }
/* TODO this method should probably be private.
it doesn't tell the parent we are a subEntity and since
-addSubEntity: calls it doing so would cause a recursive loop */
- (void)setParentEntity: (EOEntity *)parent - (void)setParentEntity: (EOEntity *)parent
{ {
[self willChange]; // TODO: verify
ASSIGN(_parent, parent); ASSIGN(_parent, parent);
} }

View file

@ -1423,6 +1423,7 @@ NSString *EOEntityLoadedNotification = @"EOEntityLoadedNotification";
self modelGroup; self modelGroup;
//todo if modelgroup; //todo if modelgroup;
*/ */
[self willChange];
ASSIGN(_name, name); ASSIGN(_name, name);
/* /*
self modelGroup; self modelGroup;
@ -1433,11 +1434,13 @@ NSString *EOEntityLoadedNotification = @"EOEntityLoadedNotification";
- (void) setAdaptorName: (NSString *)adaptorName - (void) setAdaptorName: (NSString *)adaptorName
{ {
[self willChange];
ASSIGN(_adaptorName, adaptorName); ASSIGN(_adaptorName, adaptorName);
} }
- (void) setConnectionDictionary: (NSDictionary *)connectionDictionary - (void) setConnectionDictionary: (NSDictionary *)connectionDictionary
{ {
[self willChange];
ASSIGN(_connectionDictionary, connectionDictionary); ASSIGN(_connectionDictionary, connectionDictionary);
} }
@ -1468,6 +1471,7 @@ NSString *EOEntityLoadedNotification = @"EOEntityLoadedNotification";
@"Entity '%@' is already owned by model '%@'.", @"Entity '%@' is already owned by model '%@'.",
[entity name], [[entity model] name]); [entity name], [[entity model] name]);
[self willChange];
/* Do not access _entities until cache is triggered */ /* Do not access _entities until cache is triggered */
if ([self createsMutableObjects]) if ([self createsMutableObjects])
[(GCMutableArray *)[self entities] addObject: entity]; [(GCMutableArray *)[self entities] addObject: entity];
@ -1505,6 +1509,7 @@ NSString *EOEntityLoadedNotification = @"EOEntityLoadedNotification";
className = [entity className]; className = [entity className];
NSAssert1(className, @"No className in %@", entity); NSAssert1(className, @"No className in %@", entity);
[self willChange];
NSMapRemove(_entitiesByClass, className); NSMapRemove(_entitiesByClass, className);
/* Do not access _entities until cache is triggered */ /* Do not access _entities until cache is triggered */
@ -1535,6 +1540,7 @@ NSString *EOEntityLoadedNotification = @"EOEntityLoadedNotification";
self, self,
[storedProcedure name]]; [storedProcedure name]];
NSAssert(_storedProcedures, @"Uninitialised _storedProcedures!"); NSAssert(_storedProcedures, @"Uninitialised _storedProcedures!");
[self willChange];
if ([self createsMutableObjects]) if ([self createsMutableObjects])
[(GCMutableArray *)_storedProcedures addObject: storedProcedure]; [(GCMutableArray *)_storedProcedures addObject: storedProcedure];
else else
@ -1551,6 +1557,7 @@ NSString *EOEntityLoadedNotification = @"EOEntityLoadedNotification";
{ {
NSAssert(_storedProcedures, @"Uninitialised _storedProcedures!"); NSAssert(_storedProcedures, @"Uninitialised _storedProcedures!");
[self willChange];
if ([self createsMutableObjects]) if ([self createsMutableObjects])
[(GCMutableArray *)_storedProcedures removeObject: storedProcedure]; [(GCMutableArray *)_storedProcedures removeObject: storedProcedure];
else else

View file

@ -1288,6 +1288,7 @@ relationships. Nil if none" **/
NSStringFromClass([self class]), NSStringFromClass([self class]),
self]; self];
[self willChange];
_flags.isToMany = flag; _flags.isToMany = flag;
} }
@ -1587,7 +1588,6 @@ relationships. Nil if none" **/
EOFLOGObjectFnStart(); EOFLOGObjectFnStart();
[self _flushCache]; [self _flushCache];
[self willChange];
if ([self isFlattened] == YES) if ([self isFlattened] == YES)
[NSException raise: NSInvalidArgumentException [NSException raise: NSInvalidArgumentException
@ -1597,6 +1597,7 @@ relationships. Nil if none" **/
self]; self];
else else
{ {
[self willChange];
if ([self createsMutableObjects]) if ([self createsMutableObjects])
{ {
[(GCMutableArray *)_joins removeObject: join]; [(GCMutableArray *)_joins removeObject: join];
@ -1698,6 +1699,7 @@ becomes "name", and "FIRST_NAME" becomes "firstName".*/
- (void)setNumberOfToManyFaultsToBatchFetch: (unsigned int)size - (void)setNumberOfToManyFaultsToBatchFetch: (unsigned int)size
{ {
[self willChange];
_batchCount = size; _batchCount = size;
} }
@ -1707,6 +1709,7 @@ becomes "name", and "FIRST_NAME" becomes "firstName".*/
@"Bad deleteRule numeric value: %d", @"Bad deleteRule numeric value: %d",
deleteRule); deleteRule);
[self willChange];
_flags.deleteRule = deleteRule; _flags.deleteRule = deleteRule;
} }
@ -1821,8 +1824,10 @@ becomes "name", and "FIRST_NAME" becomes "firstName".*/
return _flags.createsMutableObjects; return _flags.createsMutableObjects;
} }
/* TODO this method should probably be private. */
- (void)setInverseRelationship: (EORelationship*)relationship - (void)setInverseRelationship: (EORelationship*)relationship
{ {
[self willChange]; // TODO: verify
ASSIGN(_inverseRelationship,relationship); ASSIGN(_inverseRelationship,relationship);
} }

View file

@ -50,6 +50,7 @@ RCS_ID("$Id$")
#include <GNUstepBase/GCObject.h> #include <GNUstepBase/GCObject.h>
#include <EOControl/EODebug.h> #include <EOControl/EODebug.h>
#include <EOControl/EOObserver.h>
#include <EOAccess/EOStoredProcedure.h> #include <EOAccess/EOStoredProcedure.h>
#include <EOAccess/EOAttribute.h> #include <EOAccess/EOAttribute.h>
@ -222,16 +223,19 @@ RCS_ID("$Id$")
- (void)setName: (NSString *)name - (void)setName: (NSString *)name
{ {
[self willChange];
ASSIGN(_name, name); ASSIGN(_name, name);
} }
- (void)setExternalName: (NSString *)name - (void)setExternalName: (NSString *)name
{ {
[self willChange];
ASSIGN(_externalName, name); ASSIGN(_externalName, name);
} }
- (void)setArguments: (NSArray *)arguments - (void)setArguments: (NSArray *)arguments
{ {
[self willChange];
if ([arguments isKindOfClass: [GCArray class]] if ([arguments isKindOfClass: [GCArray class]]
|| [arguments isKindOfClass: [GCMutableArray class]]) || [arguments isKindOfClass: [GCMutableArray class]])
ASSIGN(_arguments, arguments); ASSIGN(_arguments, arguments);
@ -241,6 +245,7 @@ RCS_ID("$Id$")
- (void)setUserInfo: (NSDictionary *)dictionary - (void)setUserInfo: (NSDictionary *)dictionary
{ {
[self willChange];
ASSIGN(_userInfo, dictionary); ASSIGN(_userInfo, dictionary);
} }