* EOAccess/EOModelGroup.m

add include
* EOAccess/EOEntity.m
- classProperties
small cleanup 
* EOAccess/EODatabaseOperation.m
-rowDiffsForAttributes:
add checks
* EOAccess/EODatabaseContext.h
add _missingObjectGIDs, _checkPropagatedPKs
add databaseContextFailedToFetchObject
+ _setUseToManyCaching:
added
removed -coordinator
add -missingObjectGlobalIDs
* EOAccess/EODatabaseContextPriv.h
add -_entityForObject:
* EOAccess/EODatabaseContext.m
add _useToManyCaching
add + _setUseToManyCaching:
add - _delegateHandledDatabaseException:
add -setCoordinator:
removed -coordinator
add databaseContextFailedToFetchObject
add -missingObjectGlobalIDs
cleanup _objectsChanged
-_snapshotsChangedInDatabase
renamed vars
- _batchNewPrimaryKeysWithEntity:count:
add
- prepareForSaveWithCoordinator:editingContext:
add checks
cleanup code
- _patchUpPK:
add
- recordChangesInEditingContext
rewritten
- _primaryKeyForIntermediateRowFromSourceObject:relationship:destinationObject:
add
- _databaseOperationForIntermediateRowFromSourceObject:relationship:destinationObject:
add
- _recordDeleteForIntermediateRowFromSourceObject:relationship:destinationObject:
add
- nullifyAttributesInRelationship:sourceObject:destinationObjects:
fixed, rewritten
- _entityForObject:
add
* EOAccess/EOAdaptorChannel.h
* EOAccess/EOAdaptorChannel.m
add primaryKeysForNewRowsWithEntity:count:
* Apps/EOModelEditor/DataBrowser.m
fix typo in import
* EOControl/EONSAddOns.h
* EOControl/EONSAddOns.m
add +dictionaryWithDictionary:keys:
add -translateFromKeys:toKeys:
add -containsAnyNullObject
* EOControl/EOSharedEditingContext.m
fix include
* EOControl/EOObjectStoreCoordinator.h
* EOControl/EOObjectStoreCoordinator.m
remove observers now
add setCoordinator and use it.
-coordinator
moved up from EODatabaseContext.



git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gdl2/trunk@30918 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
dwetzel 2010-07-04 10:00:57 +00:00
parent 2e927042fb
commit fe2d1a281f
15 changed files with 1384 additions and 1245 deletions

View file

@ -28,7 +28,7 @@
#import "DataBrowser.h"
#import <Renaissance/Renaissance.h>
#import "TableViewController.h"
#import <EOContol/EOContol.h>
#import <EOControl/EOControl.h>
static DataBrowser *sharedDataBrowser = nil;

View file

@ -1,3 +1,70 @@
2010-07-04 David Wetzel <dave@turbocat.de>
* EOAccess/EOModelGroup.m
add include
* EOAccess/EOEntity.m
- classProperties
small cleanup
* EOAccess/EODatabaseOperation.m
-rowDiffsForAttributes:
add checks
* EOAccess/EODatabaseContext.h
add _missingObjectGIDs, _checkPropagatedPKs
add databaseContextFailedToFetchObject
+ _setUseToManyCaching:
added
removed -coordinator
add -missingObjectGlobalIDs
* EOAccess/EODatabaseContextPriv.h
add -_entityForObject:
* EOAccess/EODatabaseContext.m
add _useToManyCaching
add + _setUseToManyCaching:
add - _delegateHandledDatabaseException:
add -setCoordinator:
removed -coordinator
add databaseContextFailedToFetchObject
add -missingObjectGlobalIDs
cleanup _objectsChanged
-_snapshotsChangedInDatabase
renamed vars
- _batchNewPrimaryKeysWithEntity:count:
add
- prepareForSaveWithCoordinator:editingContext:
add checks
cleanup code
- _patchUpPK:
add
- recordChangesInEditingContext
rewritten
- _primaryKeyForIntermediateRowFromSourceObject:relationship:destinationObject:
add
- _databaseOperationForIntermediateRowFromSourceObject:relationship:destinationObject:
add
- _recordDeleteForIntermediateRowFromSourceObject:relationship:destinationObject:
add
- nullifyAttributesInRelationship:sourceObject:destinationObjects:
fixed, rewritten
- _entityForObject:
add
* EOAccess/EOAdaptorChannel.h
* EOAccess/EOAdaptorChannel.m
add primaryKeysForNewRowsWithEntity:count:
* Apps/EOModelEditor/DataBrowser.m
fix typo in import
* EOControl/EONSAddOns.h
* EOControl/EONSAddOns.m
add +dictionaryWithDictionary:keys:
add -translateFromKeys:toKeys:
add -containsAnyNullObject
* EOControl/EOSharedEditingContext.m
fix include
* EOControl/EOObjectStoreCoordinator.h
* EOControl/EOObjectStoreCoordinator.m
remove observers now
add setCoordinator and use it.
-coordinator
moved up from EODatabaseContext.
2010-07-01 David Wetzel <dave@turbocat.de>
* EOAccess/EODatabaseOperation.m
fix typo in string

View file

@ -147,6 +147,15 @@ inRowDescribedByQualifier: (EOQualifier *)qualifier
*/
- (NSDictionary *)primaryKeyForNewRowWithEntity: (EOEntity *)entity;
/**
* The default implementation just calls
* primaryKeyForNewRowWithEntity count times.
* you might override this in subclasses for optimized results.
*/
- (NSArray *)primaryKeysForNewRowsWithEntity:(EOEntity *)entity
count:(NSUInteger)count;
- (NSArray *)describeTableNames;
- (NSArray *)describeStoredProcedureNames;

View file

@ -303,6 +303,21 @@ inRowDescribedByQualifier: (EOQualifier *)qualifier
return nil;
}
- (NSArray *)primaryKeysForNewRowsWithEntity:(EOEntity *)entity count:(NSUInteger)count
{
NSMutableArray * array = [NSMutableArray array];
NSUInteger i;
for (i = 0; i < count; i++) {
NSDictionary * newDict = [self primaryKeyForNewRowWithEntity:entity];
if (newDict) {
[array addObject: newDict];
}
}
return array;
}
- (NSArray *)describeTableNames
{
return nil;

View file

@ -67,17 +67,19 @@ struct _EOTransactionScope;
@interface EODatabaseContext : EOCooperatingObjectStore
{
EODatabase *_database;
EOAdaptorContext *_adaptorContext;
EOUpdateStrategy _updateStrategy;
NSMutableArray *_uniqueStack; /* simple snapshots */
NSMutableArray *_deleteStack;
EOAdaptorContext * _adaptorContext;
EOUpdateStrategy _updateStrategy;
NSMutableArray * _uniqueStack; /* simple snapshots */
NSMutableArray * _deleteStack;
NSMutableArray *_registeredChannels;
NSMapTable *_dbOperationsByGlobalID;
EOObjectStoreCoordinator *_coordinator; /* unretained */
EOEditingContext *_editingContext; /* unretained */
NSHashTable *_lockedObjects;//void*
/*TO ADD unsigned int _currentGeneration;
NSMutableArray * _registeredChannels;
NSMapTable * _dbOperationsByGlobalID;
EOEditingContext * _editingContext; /* unretained */
NSHashTable * _lockedObjects;//void*
NSMutableSet * _missingObjectGIDs;
NSMutableArray * _checkPropagatedPKs;
/*TO ADD unsigned int _currentGeneration;
unsigned int _concurentFetches;
*/
@ -114,7 +116,8 @@ struct _EOTransactionScope;
unsigned int shouldFetchObjectFault:1;
unsigned int shouldFetchArrayFault:1;
unsigned int shouldHandleDatabaseException:1;
unsigned int _reserved:20;
unsigned int databaseContextFailedToFetchObject:1;
unsigned int _reserved:19;
} _delegateRespondsTo;
NSRecursiveLock *_lock; //TODO: not lock object !
@ -127,6 +130,9 @@ struct _EOTransactionScope;
+ (EODatabaseContext *)registeredDatabaseContextForModel: (EOModel *)model
editingContext: (EOEditingContext *)editingContext;
// PRIVATE, since at least EOF 2.2
+ (void) _setUseToManyCaching:(BOOL) yn;
+ (Class)contextClassToRegister;
+ (void)setContextClassToRegister: (Class)contextClass;
@ -142,8 +148,6 @@ struct _EOTransactionScope;
- (EODatabase *)database;
- (EOObjectStoreCoordinator *)coordinator;
- (EOAdaptorContext *)adaptorContext;
- (void)setUpdateStrategy: (EOUpdateStrategy)strategy;
@ -152,6 +156,20 @@ struct _EOTransactionScope;
- (id)delegate;
- (void)setDelegate: (id)delegate;
- (void)handleDroppedConnection;
/*
Returns the globalIDs of any 'missing' enterprise objects,
or an empty array if no missing objects are known.
An object is 'missing' when a fault fires and the
row for the fault isn't found in the database.
To be notified when a missing object is found,
implement the delegate method
databaseContext:failedToFetchObject:globalID:
*/
- (NSArray *) missingObjectGlobalIDs;
@end /* EODatabaseContext */

File diff suppressed because it is too large Load diff

View file

@ -32,7 +32,7 @@
@class EOAccessArrayFaultHandler;
@class EOKeyGlobalID;
@class EOFault;
@class EOCustomObject;
@interface EODatabaseContext (EODatabaseContextPrivate)
@ -69,6 +69,7 @@
- (void)_cleanUpAfterSave;
- (void)_assertValidStateWithSelector: (SEL)sel;
- (BOOL)_shouldGeneratePrimaryKeyForEntityName: (NSString *)entityName;
- (EOEntity*) _entityForObject:(EOCustomObject*) eo;
- (void)_buildPrimaryKeyGeneratorListForEditingContext: (EOEditingContext *)context;
@end

View file

@ -225,36 +225,35 @@ RCS_ID("$Id$")
- (NSDictionary*)rowDiffsForAttributes: (NSArray*)attributes
{
//OK
NSMutableDictionary *row = nil;
EOAttribute *attr = nil;
NSEnumerator *attrsEnum = nil;
attrsEnum = [attributes objectEnumerator];
while ((attr = [attrsEnum nextObject]))
{
NSString *name = [attr name];
NSString *snapname = [_entity snapshotKeyForAttributeName: name];
id value = [_newRow objectForKey: snapname];
id snapValue = [_dbSnapshot objectForKey: snapname];
if ((!value) || (!snapValue))
{
NSString *name = [attr name];
NSString *snapname = [_entity snapshotKeyForAttributeName: name];
id value = [_newRow objectForKey: name];
if (value && [value isEqual: [_dbSnapshot objectForKey: snapname]] == NO)
{
if (!row)
row = (NSMutableDictionary*)[NSMutableDictionary dictionary];
[row setObject: value
forKey: name];
}
[NSException raise: NSInternalInconsistencyException
format: @"%s does not contain value for attribute named '%@' with snapshot key '%@'",
__PRETTY_FUNCTION__, name, snapname];
}
if (([value isEqual: snapValue] == NO))
{
if (!row)
row = (NSMutableDictionary*)[NSMutableDictionary dictionary];
[row setObject: value
forKey: snapname];
}
}
return row;
}

View file

@ -1068,68 +1068,62 @@ static void performSelectorOnArrayWithEachObjectOfClass(NSArray *arr, SEL select
- (NSArray *)classProperties
{
//OK
if (_flags.classPropertiesIsLazy)
{
int count = [_classProperties count];
if (count > 0)
{
int count = [_classProperties count];
EOFLOGObjectLevelArgs(@"EOEntity", @"Lazy _classProperties=%@",
_classProperties);
if (count > 0)
{
NSArray *classPropertiesList = _classProperties;
int i;
_classProperties = [NSMutableArray new];
_flags.classPropertiesIsLazy = NO;
for (i = 0; i < count; i++)
{
NSArray *classPropertiesList = _classProperties;
int i;
_classProperties = [NSMutableArray new];
_flags.classPropertiesIsLazy = NO;
for (i = 0; i < count; i++)
{
#if 0
NSString *classPropertyName = [classPropertiesList
objectAtIndex: i];
NSString *classPropertyName = [classPropertiesList
objectAtIndex: i];
#else
id classPropertyName = (
[[classPropertiesList objectAtIndex:i] isKindOfClass:[NSString class]] ?
[classPropertiesList objectAtIndex:i] :
[(EOEntity *)[classPropertiesList objectAtIndex: i] name]);
id classPropertyName = (
[[classPropertiesList objectAtIndex:i] isKindOfClass:[NSString class]] ?
[classPropertiesList objectAtIndex:i] :
[(EOEntity *)[classPropertiesList objectAtIndex: i] name]);
#endif
id classProperty = [self attributeNamed: classPropertyName];
if (!classProperty)
classProperty = [self relationshipNamed: classPropertyName];
NSAssert4(classProperty,
@"No attribute or relationship named '%@' (property at index %d) to use as classProperty in entity name '%@' : %@",
classPropertyName,
i+1,
[self name],
self);
if ([self isValidClassProperty: classProperty])
[_classProperties addObject: classProperty];
else
{
//TODO
NSAssert2(NO, @"not valid class prop %@ in %@",
classProperty, [self name]);
}
}
DESTROY(classPropertiesList);
[_classProperties sortUsingSelector: @selector(eoCompareOnName:)]; //Very important to have always the same order.
[self _setIsEdited]; //To Clean Buffers
id classProperty = [self attributeNamed: classPropertyName];
if (!classProperty)
classProperty = [self relationshipNamed: classPropertyName];
NSAssert4(classProperty,
@"No attribute or relationship named '%@' (property at index %d) to use as classProperty in entity name '%@' : %@",
classPropertyName,
i+1,
[self name],
self);
if ([self isValidClassProperty: classProperty])
[_classProperties addObject: classProperty];
else
{
//TODO
NSAssert2(NO, @"not valid class prop %@ in %@",
classProperty, [self name]);
}
else
_flags.classPropertiesIsLazy = NO;
}
DESTROY(classPropertiesList);
[_classProperties sortUsingSelector: @selector(eoCompareOnName:)]; //Very important to have always the same order.
[self _setIsEdited]; //To Clean Buffers
}
else
_flags.classPropertiesIsLazy = NO;
}
return _classProperties;
}

View file

@ -50,6 +50,7 @@ RCS_ID("$Id$")
#ifndef GNUSTEP
#include <GNUstepBase/GNUstep.h>
#include <GNUstepBase/NSDebug+GNUstepBase.h>
#include <GNUstepBase/NSObject+GNUstepBase.h>
#endif
#include <EOAccess/EOModelGroup.h>

View file

@ -127,4 +127,40 @@ GDL2_Activate(Class sup, Class cls);
withObject: (id)object3;
@end
@interface NSMutableDictionary (EOAdditions)
/**
* Creates an autoreleased mutable dictionary based on otherDictionary
* but only with keys from the keys array.
*/
+ (NSMutableDictionary*) dictionaryWithDictionary:(NSDictionary *)otherDictionary
keys:(NSArray*)keys;
/**
* replaces the current keys with the new ones without changing the contents
* only keys from currentKeys are left in the receiver.
*/
- (void) translateFromKeys:(NSArray *) currentKeys
toKeys:(NSArray *) newKeys;
@end
@interface NSDictionary (EOAdditions)
/**
* return YES if any EONull is into receiver.
* otherwise return NO.
*/
- (BOOL) containsAnyNullObject;
/**
* creates an new dictionary with EONull for the keys
*/
+ (NSDictionary*) dictionaryWithNullValuesForKeys:(NSArray*) keys;
@end
#endif /* __EONSAddOns_h__ */

View file

@ -52,7 +52,6 @@ RCS_ID("$Id$")
#ifndef GNUSTEP
#include <GNUstepBase/GNUstep.h>
#include <GNUstepBase/GSCategories.h>
#include <GNUstepBase/GSObjCRuntime.h>
#include <GNUstepBase/NSDebug+GNUstepBase.h>
#endif
@ -241,7 +240,7 @@ GDL2_Activate(Class sup, Class cls)
@"%@: No result for object %@ resultOfPerformingSelector:\"%s\"",
self,
object,
sel_get_name(sel));
sel_getName(sel));
[results addObject: result]; //TODO What to do if nil ??
}
@ -299,7 +298,7 @@ GDL2_Activate(Class sup, Class cls)
@"%@: No result for object %@ resultOfPerformingSelector:\"%s\"",
self,
object,
sel_get_name(sel));
sel_getName(sel));
[results addObject: result]; //TODO What to do if nil ??
}
@ -358,7 +357,7 @@ GDL2_Activate(Class sup, Class cls)
@"%@: No result for object %@ resultOfPerformingSelector:\"%s\"",
self,
object,
sel_get_name(sel));
sel_getName(sel));
[results addObject: result]; //TODO What to do if nil ??
}
@ -393,12 +392,12 @@ GDL2_Activate(Class sup, Class cls)
result = self;
else
{
int i;
NSUInteger i;
for (i = 0; i < selfCount; i++)
{
id object = [self objectAtIndex: i];
int index = [array indexOfObjectIdenticalTo: object];
NSUInteger index = [array indexOfObjectIdenticalTo: object];
if (index == NSNotFound)
{
@ -671,7 +670,7 @@ GDL2_Activate(Class sup, Class cls)
if (!msg)
{
[NSException raise: NSGenericException
format: @"invalid selector passed to %s", sel_get_name(_cmd)];
format: @"invalid selector passed to %s", sel_getName(_cmd)];
return nil;
}
@ -679,3 +678,128 @@ GDL2_Activate(Class sup, Class cls)
}
@end
@implementation NSMutableDictionary (EOAdditions)
/**
* Creates an autoreleased mutable dictionary based on otherDictionary
* but only with keys from the keys array.
*/
+ (NSMutableDictionary *) dictionaryWithDictionary:(NSDictionary *)otherDictionary
keys:(NSArray*)keys
{
if (!keys)
{
return [NSMutableDictionary dictionary];
} else {
NSUInteger keyCount = [keys count];
NSUInteger i = 0;
NSMutableDictionary * mDict = [NSMutableDictionary dictionaryWithCapacity:keyCount];
for (; i < keyCount; i++) {
NSString * key = [keys objectAtIndex:i];
id value = [otherDictionary valueForKey:key];
if (!value) {
value = GDL2_EONull;
}
[mDict setObject:value
forKey:key];
}
return mDict;
}
}
// "translateFromKeys:toKeys:",
- (void) translateFromKeys:(NSArray *) currentKeys
toKeys:(NSArray *) newKeys
{
NSUInteger count = [currentKeys count];
NSString * nullPlaceholder = @"__EOAdditionsDummy__";
NSMutableArray * buffer;
NSUInteger i;
if(count != [newKeys count])
{
[NSException raise: NSInvalidArgumentException
format: @"%s key arrays must contain equal number of keys", __PRETTY_FUNCTION__];
}
buffer = [NSMutableArray arrayWithCapacity:count];
for (i = 0; i < count; i++)
{
id key = [currentKeys objectAtIndex:i];
id value = [self objectForKey:key];
if (!value)
{
value = nullPlaceholder;
[buffer addObject:value];
} else {
[buffer addObject:value];
[self removeObjectForKey:key];
}
}
[self removeAllObjects];
for (i = 0; i < count; i++)
{
id value = [buffer objectAtIndex:i];
if(value != nullPlaceholder)
{
[self setObject:value
forKey:[newKeys objectAtIndex:i]];
}
}
}
@end
@implementation NSDictionary (EOAdditions)
- (BOOL) containsAnyNullObject
{
NSArray * values = [self allValues];
NSUInteger count = [values count];
NSUInteger i = 0;
for (; i < count; i++)
{
if (([values objectAtIndex:i] == GDL2_EONull))
{
return YES;
}
}
return NO;
}
+ (NSDictionary*) dictionaryWithNullValuesForKeys:(NSArray*) keys
{
NSMutableDictionary * dict = nil;
NSUInteger count = [keys count];
if (count > 0)
{
dict = [NSMutableDictionary dictionaryWithCapacity:count];
NSUInteger i;
for (i = 0; i < count; i++)
{
NSString * key = [keys objectAtIndex:i];
[dict setObject:GDL2_EONull
forKey: key];
}
}
return dict;
}
@end

View file

@ -81,6 +81,12 @@ GDL2CONTROL_EXPORT NSString *EOCooperatingObjectStoreNeeded;
@interface EOCooperatingObjectStore : EOObjectStore
{
EOObjectStoreCoordinator *_coordinator; /* unretained */
}
- (EOObjectStoreCoordinator *)coordinator;
- (void) setCoordinator:(EOObjectStoreCoordinator *) newCoordinator;
- (BOOL)ownsGlobalID: (EOGlobalID *)globalID;

View file

@ -49,11 +49,13 @@ RCS_ID("$Id$")
#ifndef GNUSTEP
#include <GNUstepBase/GNUstep.h>
#include <GNUstepBase/NSDebug+GNUstepBase.h>
#include <GNUstepBase/NSObject+GNUstepBase.h>
#endif
#include <EOControl/EOObjectStoreCoordinator.h>
#include <EOControl/EOEditingContext.h>
#include <EOControl/EODebug.h>
#include <EOControl/EOGlobalID.h>
@implementation EOObjectStoreCoordinator
@ -100,7 +102,14 @@ NSString *EOCooperatingObjectStoreNeeded = @"EOCooperatingObjectStoreNeeded";
{
if ([_stores containsObject:store] == NO)
{
if ([store coordinator])
{
[NSException raise: NSInternalInconsistencyException
format: @"%s Cannot add %@ to this EOObjectStoreCoordinator because it already has another.",
__PRETTY_FUNCTION__, store];
}
[_stores addObject:store];
[store setCoordinator:self];
[[NSNotificationCenter defaultCenter]
postNotificationName: EOCooperatingObjectStoreWasAdded
@ -122,12 +131,25 @@ NSString *EOCooperatingObjectStoreNeeded = @"EOCooperatingObjectStoreNeeded";
{
if ([_stores containsObject:store] == YES)
{
NSNotificationCenter * nCenter = [NSNotificationCenter defaultCenter];
[_stores removeObject: store];
[store setCoordinator: nil];
[[NSNotificationCenter defaultCenter]
postNotificationName: EOCooperatingObjectStoreWasRemoved
object: store];
//ODO remove aboservers
[nCenter postNotificationName:EOCooperatingObjectStoreWasRemoved
object:store];
[nCenter removeObserver:self
name:EOObjectsChangedInStoreNotification
object:store];
[nCenter removeObserver:self
name:EOInvalidatedAllObjectsInStoreNotification
object:store];
[nCenter removeObserver:self
name:EOGlobalIDChangedNotification
object:store];
}
}
@ -573,6 +595,16 @@ NSString *EOCooperatingObjectStoreNeeded = @"EOCooperatingObjectStoreNeeded";
@implementation EOCooperatingObjectStore
- (void) setCoordinator:(EOObjectStoreCoordinator *) newCoordinator
{
_coordinator = newCoordinator;
}
- (EOObjectStoreCoordinator *)coordinator
{
return _coordinator;
}
- (BOOL)ownsGlobalID: (EOGlobalID *)globalID
{
[self subclassResponsibility: _cmd];

View file

@ -30,7 +30,6 @@ RCS_ID("$Id$")
#ifndef GNUSTEP
#include <GNUstepBase/GNUstep.h>
#include <GNUstepBase/GSCategories.h>
#include <Foundation/Foundation.h>
#else
#include <Foundation/NSArray.h>