* 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
{
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 -
@ -959,7 +983,7 @@ NSString *EOMConsistencyModelObjectKey = @"EOMConsistencyModelObjectKey";
}
if ((action == @selector(delete:))) {
if (!_outlineSelection) {
if ((!_outlineSelection) || (!_selectedObjects)) {
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>
* Apps/EOModelEditor/Resources/PlusCorner.tiff added

View file

@ -450,14 +450,8 @@ RCS_ID("$Id$")
{
NSString *definition = nil;
//
// EOFLOGObjectLevel(@"gsdb",@"_definitionArray:%@",_definitionArray);
definition = [_definitionArray valueForSQLExpression: nil];
// EOFLOGObjectLevel(@"gsdb",@"definition:%@",definition);
//
return definition;
}
@ -709,15 +703,17 @@ RCS_ID("$Id$")
- (NSString *) valueForSQLExpression: (EOSQLExpression *)sqlExpression
{
NSString *value=nil;
// EOFLOGObjectLevel(@"gsdb",@"EOAttribute %p",self);
NSEmitTODO(); //TODO
if (sqlExpression != nil)
{
return [sqlExpression sqlStringForAttribute:self];
}
if (_definitionArray)
value = [_definitionArray valueForSQLExpression: sqlExpression];
else
value = [self name];
return value;
}
@ -1867,6 +1863,21 @@ More details:
@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
{
//OK
@ -1881,7 +1892,7 @@ More details:
return _realAttribute;
}
- (NSMutableArray *)_definitionArray
- (EOExpressionArray *)_definitionArray
{
return _definitionArray;
}

View file

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

View file

@ -137,6 +137,7 @@
- (void)_resetPrototypeCache;
- (BOOL)isPrototypesEntity: (id)param0;
- (NSMutableDictionary *) _loadFetchSpecificationDictionaryForEntityNamed:(NSString *) entName;
- (void)_classDescriptionNeeded: (NSNotification *)notification;
- (id)_instantiatedEntities;
- (void)_setPath: (NSString *)path;
@ -145,6 +146,14 @@
- (void)_registerChild: (id)param0
forParent: (id)param1;
- (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;
- (EOEntity *)_addEntityWithPropertyList: (NSDictionary *)propertyList;
- (void)_addFakeEntityWithPropertyList: (NSDictionary *)propertyList;

View file

@ -1071,6 +1071,13 @@ NSString *EOEntityLoadedNotification = @"EOEntityLoadedNotification";
@implementation EOModel (EOModelHidden)
- (NSMutableDictionary *) _loadFetchSpecificationDictionaryForEntityNamed:(NSString *) entName
{
NSEmitTODO();
return nil;
}
-(void) _classDescriptionNeeded: (NSNotification *)notification
{
//TODO
@ -1249,6 +1256,76 @@ NSString *EOEntityLoadedNotification = @"EOEntityLoadedNotification";
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
{
//should be ok
@ -1521,15 +1598,21 @@ NSString *EOEntityLoadedNotification = @"EOEntityLoadedNotification";
- (void)loadAllModelObjects
{
NSArray *entityNames = [_entitiesByName allKeys];
unsigned i,n = [entityNames count];
NSUInteger i,n = [entityNames count];
[self storedProcedures];
for (i=0; i<n; i++)
{
NSString *name = [entityNames objectAtIndex: i];
id entity = [_entitiesByName objectForKey: name];
[self _verifyBuiltEntityObject: entity
named: name];
}
{
NSString *name = [entityNames objectAtIndex: i];
id entity = [_entitiesByName objectForKey: 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];
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];
EOAttribute *attr;
EORelationship *rel;
IMP propEnumNO=NULL;
while ((attr = GDL2_NextObjectWithImpPtr(propEnumerator,&propEnumNO)))
{
if ([attr isFlattened] && [[attr realAttribute] isEqual: property])
if ([attr referencesProperty:property])
{
NSArray * newArray;
[refProps addObject:attr];
newArray = [self referencesToProperty:attr];
if ([newArray count] > 0) {
[refProps addObjectsFromArray:newArray];
}
}
}
propEnumerator = [[ent relationships] objectEnumerator];
propEnumNO = NULL;
while ((rel = GDL2_NextObjectWithImpPtr(propEnumerator, &propEnumNO)))
{
if ([rel referencesProperty:property])
}
propEnumerator = [[ent relationships] objectEnumerator];
propEnumNO = NULL;
while ((rel = GDL2_NextObjectWithImpPtr(propEnumerator, &propEnumNO)))
{
if ([rel referencesProperty:property])
{
NSArray * newArray;
[refProps addObject:rel];
newArray = [self referencesToProperty:rel];
if ([newArray count] > 0) {
[refProps addObjectsFromArray:newArray];
}
}
}
}
}
}
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. **/
- (NSString*) valueForSQLExpression: (EOSQLExpression*)sqlExpression
{
EOFLOGObjectLevelArgs(@"EORelationship", @"EORelationship %p", self);
NSEmitTODO(); //TODO
// return [self notImplemented:_cmd]; //TODO
//return name ??
return [self name];
}
- (BOOL)referencesProperty: (id)property
{
BOOL referencesProperty = NO;
NSArray *srcAttribs;
NSArray *destAttribs;
NSArray *compRels;
if (property == nil)
return NO;
destAttribs = [self destinationAttributes];
srcAttribs = [self sourceAttributes];
compRels = [self componentRelationships];
EOFLOGObjectLevelArgs(@"EORelationship", @"in referencesProperty:%@",
property);
referencesProperty =
((srcAttribs
&& [srcAttribs indexOfObject: property] != NSNotFound)
|| (destAttribs
&& [destAttribs indexOfObject: property] != NSNotFound)
|| (compRels
&& [compRels indexOfObject: property] != NSNotFound)
|| (_destination == property));
return referencesProperty;
if ([self isFlattened])
{
return [_definitionArray referencesObject:property];
}
if (_joins) {
NSEnumerator *joinEnumer = [_joins objectEnumerator];
EOJoin *join;
while ((join = [joinEnumer nextObject])) {
if (([join sourceAttribute] == property) || ([join destinationAttribute] == property))
{
return YES;
}
}
}
return NO;
}
- (EODeleteRule)deleteRule
@ -2226,7 +2218,6 @@ dst entity primaryKeyAttributeNames
- (EOExpressionArray*) _definitionArray
{
//VERIFY
return _definitionArray;
}