* EOAccess/EOModel.m/h

new (still empty) _loadFetchSpecificationDictionaryForEntityNamed:
  added _removePropertiesReferencingProperty:
  added _removePropertiesReferencingEntity:
  loadAllModelObjects: load storedProcedures, call _loadEntity  
  fixed referencesToProperty:
  added referencesProperty:
  
* EOAccess/EOAttribute.m
  fixed valueForSQLExpression:
  changed return type of _definitionArray to EOExpressionArray *

* EOAccess/EOEntity.m
  fixed attributesUsedForLocking
  fixed removeAttribute:
  fixed removeRelationship:
  fixed _fetchSpecificationDictionary
  fixed _loadEntity
  
* EOAccess/EORelationship.m
  verified valueForSQLExpression, removed logs
  fixed referencesProperty:
  
* Apps/EOModelEditor/EOMEDocument.m
  make deleting of attributes work.



git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gdl2/trunk@30536 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Dave Wetzel 2010-06-02 07:55:16 +00:00
parent 2f44a63450
commit 8f66ac4667
7 changed files with 286 additions and 130 deletions

View file

@ -903,6 +903,30 @@ NSString *EOMConsistencyModelObjectKey = @"EOMConsistencyModelObjectKey";
- (IBAction)delete:(id)sender - (IBAction)delete:(id)sender
{ {
if ((_selectedObjects) && ([_selectedObjects count])) {
NSEnumerator * objEnumer = [[NSArray arrayWithArray:_selectedObjects] objectEnumerator];
id currentObj = nil;
BOOL topTableViewNeedsRefresh = NO;
[self setSelectedObjects:nil];
while ((currentObj = [objEnumer nextObject])) {
if (([currentObj class] == [EOAttribute class])) {
EOEntity * entity = [currentObj entity];
[_eomodel _removePropertiesReferencingProperty:currentObj];
[entity removeAttribute:currentObj];
topTableViewNeedsRefresh = YES;
}
}
if (topTableViewNeedsRefresh) {
[_topTableViewController setRepresentedObject:[_outlineSelection attributes]];
[_topTableView reloadData];
}
}
} }
#pragma mark - #pragma mark -
@ -959,7 +983,7 @@ NSString *EOMConsistencyModelObjectKey = @"EOMConsistencyModelObjectKey";
} }
if ((action == @selector(delete:))) { if ((action == @selector(delete:))) {
if (!_outlineSelection) { if ((!_outlineSelection) || (!_selectedObjects)) {
return NO; return NO;
} }
} }

View file

@ -1,3 +1,30 @@
2010-06-02 David Wetzel <dave@turbocat.de>
* EOAccess/EOModel.m/h
new (still empty) _loadFetchSpecificationDictionaryForEntityNamed:
added _removePropertiesReferencingProperty:
added _removePropertiesReferencingEntity:
loadAllModelObjects: load storedProcedures, call _loadEntity
fixed referencesToProperty:
added referencesProperty:
* EOAccess/EOAttribute.m
fixed valueForSQLExpression:
changed return type of _definitionArray to EOExpressionArray *
* EOAccess/EOEntity.m
fixed attributesUsedForLocking
fixed removeAttribute:
fixed removeRelationship:
fixed _fetchSpecificationDictionary
fixed _loadEntity
* EOAccess/EORelationship.m
verified valueForSQLExpression, removed logs
fixed referencesProperty:
* Apps/EOModelEditor/EOMEDocument.m
make deleting of attributes work.
2010-06-01 David Wetzel <dave@turbocat.de> 2010-06-01 David Wetzel <dave@turbocat.de>
* Apps/EOModelEditor/Resources/PlusCorner.tiff added * Apps/EOModelEditor/Resources/PlusCorner.tiff added

View file

@ -450,14 +450,8 @@ RCS_ID("$Id$")
{ {
NSString *definition = nil; NSString *definition = nil;
//
// EOFLOGObjectLevel(@"gsdb",@"_definitionArray:%@",_definitionArray);
definition = [_definitionArray valueForSQLExpression: nil]; definition = [_definitionArray valueForSQLExpression: nil];
// EOFLOGObjectLevel(@"gsdb",@"definition:%@",definition);
//
return definition; return definition;
} }
@ -709,15 +703,17 @@ RCS_ID("$Id$")
- (NSString *) valueForSQLExpression: (EOSQLExpression *)sqlExpression - (NSString *) valueForSQLExpression: (EOSQLExpression *)sqlExpression
{ {
NSString *value=nil; NSString *value=nil;
// EOFLOGObjectLevel(@"gsdb",@"EOAttribute %p",self); if (sqlExpression != nil)
NSEmitTODO(); //TODO {
return [sqlExpression sqlStringForAttribute:self];
}
if (_definitionArray) if (_definitionArray)
value = [_definitionArray valueForSQLExpression: sqlExpression]; value = [_definitionArray valueForSQLExpression: sqlExpression];
else else
value = [self name]; value = [self name];
return value; return value;
} }
@ -1867,6 +1863,21 @@ More details:
@implementation EOAttribute (EOAttributePrivate) @implementation EOAttribute (EOAttributePrivate)
/**
* Returns YES if the attribute references aProperty, NO otherwise.
*/
- (BOOL)referencesProperty:(id)aProperty
{
if (!_definitionArray)
{
return NO;
} else {
// _definitionArray is an EOExpressionArray
return [_definitionArray referencesObject:aProperty];
}
}
- (void)setParent: (id)parent - (void)setParent: (id)parent
{ {
//OK //OK
@ -1881,7 +1892,7 @@ More details:
return _realAttribute; return _realAttribute;
} }
- (NSMutableArray *)_definitionArray - (EOExpressionArray *)_definitionArray
{ {
return _definitionArray; return _definitionArray;
} }

View file

@ -1252,52 +1252,38 @@ static void performSelectorOnArrayWithEachObjectOfClass(NSArray *arr, SEL select
- (NSArray *)attributesUsedForLocking - (NSArray *)attributesUsedForLocking
{ {
//OK
if (_flags.attributesUsedForLockingIsLazy) if (_flags.attributesUsedForLockingIsLazy)
{
int count = [_attributesUsedForLocking count];
if (count > 0)
{ {
int count = [_attributesUsedForLocking count]; int i = 0;
NSArray *attributesUsedForLocking = _attributesUsedForLocking;
EOFLOGObjectLevelArgs(@"EOEntity", @"Lazy _attributesUsedForLocking=%@",
_attributesUsedForLocking); _attributesUsedForLocking = [NSMutableArray new];
_flags.attributesUsedForLockingIsLazy = NO;
if (count > 0)
for (i = 0; i < count; i++)
{
NSString *attributeName = [attributesUsedForLocking
objectAtIndex: i];
EOAttribute *attribute = [self attributeNamed: attributeName];
if (attribute)
{ {
int i = 0; [_attributesUsedForLocking addObject: attribute];
NSArray *attributesUsedForLocking = _attributesUsedForLocking;
_attributesUsedForLocking = [NSMutableArray new];
_flags.attributesUsedForLockingIsLazy = NO;
for (i = 0; i < count; i++)
{
NSString *attributeName = [attributesUsedForLocking
objectAtIndex: i];
EOAttribute *attribute = [self attributeNamed: attributeName];
NSAssert1(attribute,
@"No attribute named %@ to use for locking",
attribute);
if ([self isValidAttributeUsedForLocking: attribute])
[_attributesUsedForLocking addObject: attribute];
else
{
NSEmitTODO(); //TODO
[self notImplemented: _cmd]; //TODO
}
}
EOFLOGObjectLevelArgs(@"EOEntity", @"_attributesUsedForLocking class=%@",
[_attributesUsedForLocking class]);
DESTROY(attributesUsedForLocking);
[self _setIsEdited]; //To Clean Buffers
} }
else }
_flags.attributesUsedForLockingIsLazy = NO;
DESTROY(attributesUsedForLocking);
[self _setIsEdited]; //To Clean Buffers
} }
else
_flags.attributesUsedForLockingIsLazy = NO;
}
return _attributesUsedForLocking; return _attributesUsedForLocking;
} }
@ -1695,13 +1681,20 @@ createInstanceWithEditingContext:globalID:zone:
if (attribute) if (attribute)
{ {
[self willChange]; [self willChange];
[attribute setParent: nil]; // make sure everything is initialized
NSEmitTODO(); //TODO [self attributes];
[self classProperties];
[self attributesUsedForLocking];
[self primaryKeyAttributes];
[_attributes removeObject: attribute]; [_attributesByName removeObjectForKey:[attribute name]];
[_classProperties removeObject:attribute]; [_classProperties removeObject: attribute];
[_attributesUsedForLocking removeObject: attribute];
[_primaryKeyAttributes removeObject:attribute]; [_primaryKeyAttributes removeObject:attribute];
[attribute setParent: nil];
[_attributes removeObject: attribute];
[self _setIsEdited];//To clean caches [self _setIsEdited];//To clean caches
} }
} }
@ -1749,21 +1742,22 @@ createInstanceWithEditingContext:globalID:zone:
- (void)removeRelationship: (EORelationship *)relationship - (void)removeRelationship: (EORelationship *)relationship
{ {
if (relationship) if (relationship)
{ {
[self willChange]; [self willChange];
[self relationships];
if(_relationshipsByName != nil) [self classProperties];
[_relationshipsByName removeObjectForKey:[relationship name]];
[_relationshipsByName removeObjectForKey:[relationship name]];
[_relationships removeObject: relationship];
[_classProperties removeObject: relationship]; [_classProperties removeObject: relationship];
[_relationships removeObject: relationship];
/* We call this after adjusting the arrays so that setEntity: has
the opportunity to check the relationships before calling /* We call this after adjusting the arrays so that setEntity: has
removeRelationshipt which would lead to an infinite loop. */ the opportunity to check the relationships before calling
[relationship setEntity:nil]; removeRelationshipt which would lead to an infinite loop. */
[self _setIsEdited];//To clean caches [relationship setEntity:nil];
} [self _setIsEdited];//To clean caches
}
} }
- (void)addFetchSpecification: (EOFetchSpecification *)fetchSpec - (void)addFetchSpecification: (EOFetchSpecification *)fetchSpec
@ -2575,14 +2569,19 @@ createInstanceWithEditingContext:globalID:zone:
- (NSDictionary*) _fetchSpecificationDictionary - (NSDictionary*) _fetchSpecificationDictionary
{ {
//OK if ((!_fetchSpecificationDictionary) && (_model))
{
ASSIGN(_fetchSpecificationDictionary,
[_model _loadFetchSpecificationDictionaryForEntityNamed:_name]);
}
return _fetchSpecificationDictionary; return _fetchSpecificationDictionary;
} }
- (void) _loadEntity - (void) _loadEntity
{ {
//TODO [self attributes];
[self notImplemented: _cmd]; [self relationships];
[self _fetchSpecificationDictionary];
} }
- (id) parentRelationship - (id) parentRelationship

View file

@ -137,6 +137,7 @@
- (void)_resetPrototypeCache; - (void)_resetPrototypeCache;
- (BOOL)isPrototypesEntity: (id)param0; - (BOOL)isPrototypesEntity: (id)param0;
- (NSMutableDictionary *) _loadFetchSpecificationDictionaryForEntityNamed:(NSString *) entName;
- (void)_classDescriptionNeeded: (NSNotification *)notification; - (void)_classDescriptionNeeded: (NSNotification *)notification;
- (id)_instantiatedEntities; - (id)_instantiatedEntities;
- (void)_setPath: (NSString *)path; - (void)_setPath: (NSString *)path;
@ -145,6 +146,14 @@
- (void)_registerChild: (id)param0 - (void)_registerChild: (id)param0
forParent: (id)param1; forParent: (id)param1;
- (void)_setInheritanceLinks: (id)param0; - (void)_setInheritanceLinks: (id)param0;
/**
* Before removing attributes we need to remove all references
*/
- (void) _removePropertiesReferencingProperty:(id) property;
- (void) _removePropertiesReferencingEntity:(EOEntity*) entity;
- (void)_removeEntity: (EOEntity *)entity; - (void)_removeEntity: (EOEntity *)entity;
- (EOEntity *)_addEntityWithPropertyList: (NSDictionary *)propertyList; - (EOEntity *)_addEntityWithPropertyList: (NSDictionary *)propertyList;
- (void)_addFakeEntityWithPropertyList: (NSDictionary *)propertyList; - (void)_addFakeEntityWithPropertyList: (NSDictionary *)propertyList;

View file

@ -1071,6 +1071,13 @@ NSString *EOEntityLoadedNotification = @"EOEntityLoadedNotification";
@implementation EOModel (EOModelHidden) @implementation EOModel (EOModelHidden)
- (NSMutableDictionary *) _loadFetchSpecificationDictionaryForEntityNamed:(NSString *) entName
{
NSEmitTODO();
return nil;
}
-(void) _classDescriptionNeeded: (NSNotification *)notification -(void) _classDescriptionNeeded: (NSNotification *)notification
{ {
//TODO //TODO
@ -1249,6 +1256,76 @@ NSString *EOEntityLoadedNotification = @"EOEntityLoadedNotification";
return; return;
} }
/**
* Before removing attributes we need to remove all references
*/
- (void) _removePropertiesReferencingProperty:(id) property
{
NSUInteger refCount, refIdx = 0;
NSArray * references = nil;
references = [self referencesToProperty:property];
refCount = [references count];
for (; refIdx < refCount; refIdx++) {
id refObj = [references objectAtIndex:refIdx];
if ([refObj class] == [EOAttribute class])
{
[[(EOAttribute*) refObj entity] removeAttribute:refObj];
} else {
[[(EORelationship*) refObj entity] removeRelationship:refObj];
}
}
}
/**
* Before removing entities we need to remove all references
*/
- (void) _removePropertiesReferencingEntity:(EOEntity*) entity
{
int i;
for (i = 0; i < 2; i++)
{
NSArray * attrsOrRels;
NSArray * names = nil;
NSUInteger index = 0;
NSUInteger count = 0;
if ((i == 0))
{
attrsOrRels = [entity attributes];
} else {
attrsOrRels = [entity relationships];
}
// get name from the array
names = [attrsOrRels resultsOfPerformingSelector:@selector(name:)];
for (count = [names count]; index < count; index++)
{
id attrOrRel = nil;
if (i == 0) {
attrOrRel = [entity attributeNamed:[names objectAtIndex:index]];
} else {
attrOrRel = [entity relationshipNamed:[names objectAtIndex:index]];
}
if (attrOrRel) {
[self _removePropertiesReferencingProperty:attrOrRel];
}
}
}
}
- (void) _removeEntity: (EOEntity *)entity - (void) _removeEntity: (EOEntity *)entity
{ {
//should be ok //should be ok
@ -1521,15 +1598,21 @@ NSString *EOEntityLoadedNotification = @"EOEntityLoadedNotification";
- (void)loadAllModelObjects - (void)loadAllModelObjects
{ {
NSArray *entityNames = [_entitiesByName allKeys]; NSArray *entityNames = [_entitiesByName allKeys];
unsigned i,n = [entityNames count]; NSUInteger i,n = [entityNames count];
[self storedProcedures];
for (i=0; i<n; i++) for (i=0; i<n; i++)
{ {
NSString *name = [entityNames objectAtIndex: i]; NSString *name = [entityNames objectAtIndex: i];
id entity = [_entitiesByName objectForKey: name]; id entity = [_entitiesByName objectForKey: name];
[self _verifyBuiltEntityObject: entity
named: name]; // the reference imp does not do verify here.
} [self _verifyBuiltEntityObject: entity
named: name];
[entity _loadEntity];
}
} }
/** /**
@ -1545,30 +1628,42 @@ NSString *EOEntityLoadedNotification = @"EOEntityLoadedNotification";
NSMutableArray *refProps = [NSMutableArray array]; NSMutableArray *refProps = [NSMutableArray array];
while ((ent = GDL2_NextObjectWithImpPtr(entityEnumerator,&enumNO))) while ((ent = GDL2_NextObjectWithImpPtr(entityEnumerator,&enumNO)))
{
NSEnumerator *propEnumerator = [[ent attributes] objectEnumerator];
EOAttribute *attr;
EORelationship *rel;
IMP propEnumNO=NULL;
while ((attr = GDL2_NextObjectWithImpPtr(propEnumerator,&propEnumNO)))
{ {
NSEnumerator *propEnumerator = [[ent attributes] objectEnumerator]; if ([attr referencesProperty:property])
EOAttribute *attr;
EORelationship *rel;
IMP propEnumNO=NULL;
while ((attr = GDL2_NextObjectWithImpPtr(propEnumerator,&propEnumNO)))
{
if ([attr isFlattened] && [[attr realAttribute] isEqual: property])
{ {
NSArray * newArray;
[refProps addObject:attr]; [refProps addObject:attr];
newArray = [self referencesToProperty:attr];
if ([newArray count] > 0) {
[refProps addObjectsFromArray:newArray];
}
} }
} }
propEnumerator = [[ent relationships] objectEnumerator]; propEnumerator = [[ent relationships] objectEnumerator];
propEnumNO = NULL; propEnumNO = NULL;
while ((rel = GDL2_NextObjectWithImpPtr(propEnumerator, &propEnumNO))) while ((rel = GDL2_NextObjectWithImpPtr(propEnumerator, &propEnumNO)))
{ {
if ([rel referencesProperty:property]) if ([rel referencesProperty:property])
{ {
NSArray * newArray;
[refProps addObject:rel]; [refProps addObject:rel];
newArray = [self referencesToProperty:rel];
if ([newArray count] > 0) {
[refProps addObjectsFromArray:newArray];
}
} }
} }
} }
return [refProps count] ? [NSArray arrayWithArray:refProps] : nil; return [refProps count] ? [NSArray arrayWithArray:refProps] : nil;
} }

View file

@ -777,41 +777,33 @@ to know what to-many mean :-) **/
/** Returns the value to use in an EOSQLExpression. **/ /** Returns the value to use in an EOSQLExpression. **/
- (NSString*) valueForSQLExpression: (EOSQLExpression*)sqlExpression - (NSString*) valueForSQLExpression: (EOSQLExpression*)sqlExpression
{ {
EOFLOGObjectLevelArgs(@"EORelationship", @"EORelationship %p", self);
NSEmitTODO(); //TODO
// return [self notImplemented:_cmd]; //TODO
//return name ??
return [self name]; return [self name];
} }
- (BOOL)referencesProperty: (id)property - (BOOL)referencesProperty: (id)property
{ {
BOOL referencesProperty = NO;
NSArray *srcAttribs;
NSArray *destAttribs;
NSArray *compRels;
if (property == nil) if (property == nil)
return NO; return NO;
destAttribs = [self destinationAttributes]; if ([self isFlattened])
srcAttribs = [self sourceAttributes]; {
compRels = [self componentRelationships]; return [_definitionArray referencesObject:property];
}
EOFLOGObjectLevelArgs(@"EORelationship", @"in referencesProperty:%@",
property); if (_joins) {
referencesProperty = NSEnumerator *joinEnumer = [_joins objectEnumerator];
((srcAttribs EOJoin *join;
&& [srcAttribs indexOfObject: property] != NSNotFound)
|| (destAttribs while ((join = [joinEnumer nextObject])) {
&& [destAttribs indexOfObject: property] != NSNotFound) if (([join sourceAttribute] == property) || ([join destinationAttribute] == property))
|| (compRels {
&& [compRels indexOfObject: property] != NSNotFound) return YES;
|| (_destination == property)); }
return referencesProperty; }
}
return NO;
} }
- (EODeleteRule)deleteRule - (EODeleteRule)deleteRule
@ -2226,7 +2218,6 @@ dst entity primaryKeyAttributeNames
- (EOExpressionArray*) _definitionArray - (EOExpressionArray*) _definitionArray
{ {
//VERIFY
return _definitionArray; return _definitionArray;
} }