* EOAccess/EODatabaseContext.m

recordUpdateForObject: changes:
more checks, call coordinator's 
forwardUpdateForObject:changes:
recordInsertForObject:
raise exception on inconsistency
recordDeleteForObject:
raise exception on inconsistency
commitChanges:
remove NSLog 


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gdl2/trunk@30722 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
dwetzel 2010-06-15 03:48:52 +00:00
parent 7671304816
commit aef2be1753
2 changed files with 44 additions and 38 deletions

View file

@ -1,3 +1,15 @@
2010-06-14 David Wetzel <dave@turbocat.de>
* EOAccess/EODatabaseContext.m
recordUpdateForObject: changes:
more checks, call coordinator's
forwardUpdateForObject:changes:
recordInsertForObject:
raise exception on inconsistency
recordDeleteForObject:
raise exception on inconsistency
commitChanges:
remove NSLog
2010-06-11 David Wetzel <dave@turbocat.de> 2010-06-11 David Wetzel <dave@turbocat.de>
* EOAccess/EODatabase.m * EOAccess/EODatabase.m
* EOAccess/EODatabase.h * EOAccess/EODatabase.h

View file

@ -2848,32 +2848,25 @@ but not owned by this context to the coordinator.
- (void)recordUpdateForObject: (id)object - (void)recordUpdateForObject: (id)object
changes: (NSDictionary *)changes changes: (NSDictionary *)changes
{ {
//OK
EODatabaseOperation *dbOpe = nil; EODatabaseOperation *dbOpe = nil;
NSAssert(object, @"No object"); NSAssert(object, @"No object");
[self _assertValidStateWithSelector: [self _assertValidStateWithSelector:
@selector(recordUpdateForObject:changes:)]; @selector(recordUpdateForObject:changes:)];
dbOpe = [self databaseOperationForObject: object]; dbOpe = [self databaseOperationForObject: object];
if (dbOpe) {
[dbOpe setDatabaseOperator:EODatabaseUpdateOperator]; [dbOpe setDatabaseOperator:EODatabaseUpdateOperator];
if ((changes) && ([changes count]))
if ([changes count])
{ {
[[dbOpe newRow] addEntriesFromDictionary: changes]; [[dbOpe newRow] addEntriesFromDictionary: changes];
} }
} else {
[[self coordinator] forwardUpdateForObject:object
changes:changes];
}
} }
-(void)recordInsertForObject: (id)object -(void)recordInsertForObject: (id)object
@ -2881,20 +2874,18 @@ but not owned by this context to the coordinator.
NSDictionary *snapshot = nil; NSDictionary *snapshot = nil;
EODatabaseOperation *dbOpe = nil; EODatabaseOperation *dbOpe = nil;
dbOpe = [self databaseOperationForObject: object]; dbOpe = [self databaseOperationForObject: object];
[dbOpe setDatabaseOperator: EODatabaseInsertOperator]; [dbOpe setDatabaseOperator: EODatabaseInsertOperator];
snapshot = [dbOpe dbSnapshot];
snapshot = [dbOpe dbSnapshot]; //TODO: sowhat if ([snapshot count] != 0)
NSDebugMLLog(@"EODatabaseContext", @"object=%p snapshot=%@", {
object, snapshot); [NSException raise:NSInternalInconsistencyException
format:@"%s found a snapshot for EO with Global ID: %@ that has been inserted into %@."
//call snapshot count @"Cannot insert an object that is already in the database",
__PRETTY_FUNCTION__, [dbOpe globalID], _editingContext];
}
} }
@ -2902,16 +2893,20 @@ but not owned by this context to the coordinator.
{ {
NSDictionary *snapshot = nil; NSDictionary *snapshot = nil;
EODatabaseOperation *dbOpe = nil; EODatabaseOperation *dbOpe = nil;
dbOpe = [self databaseOperationForObject: object]; dbOpe = [self databaseOperationForObject: object];
[dbOpe setDatabaseOperator: EODatabaseDeleteOperator]; [dbOpe setDatabaseOperator: EODatabaseDeleteOperator];
snapshot = [dbOpe dbSnapshot]; //TODO: sowhat
snapshot = [dbOpe dbSnapshot];
if (([snapshot count] == 0))
{
[NSException raise:NSInternalInconsistencyException
format:@"%s failed to find a snapshot for EO with Global ID: %@ that has been deleted from %@."
@"Cannot delete an object that has not been fetched from the database",
__PRETTY_FUNCTION__, [dbOpe globalID], _editingContext];
}
} }
/** Constructs EOAdaptorOperations for all EODatabaseOperations constructed in /** Constructs EOAdaptorOperations for all EODatabaseOperations constructed in
@ -3219,7 +3214,6 @@ Raises an exception is the adaptor is unable to perform the operations.
newRowValues = [dbOpe rowDiffsForAttributes: [entity _classPropertyAttributes]]; newRowValues = [dbOpe rowDiffsForAttributes: [entity _classPropertyAttributes]];
break; break;
default: default:
NSLog(@"%s databaseOperator %d unknown", __PRETTY_FUNCTION__, databaseOperator);
break; break;
} }
id object = [dbOpe object]; id object = [dbOpe object];