From f14aafa3fc363904f1d5ded627b6365576040031 Mon Sep 17 00:00:00 2001 From: Dave Wetzel Date: Mon, 28 Jun 2010 09:31:49 +0000 Subject: [PATCH] * EOAccess/EOEntity.m - createInstanceWithEditingContext:globalID:zone: reformat, remove logs * EOAccess/EODatabaseContext.m -initializeObject:withGlobalID:editingContext: rewritten, add exceptions * EOAccess/EODatabaseChannel.m -fetchObject remove logs, add exceptions * EOAdaptors/PostgreSQLAdaptor/PostgreSQLAdaptor.m postgresClientVersion() use stringWithCString:encoding: not stringWithCString: * Apps/EOModelEditor/CodeGenerator.m don't add to generated code * EOControl/EOCustomObject.h * EOControl/EOCustomObject.m add -encodeWithCoder: add -initWithCoder: git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gdl2/trunk@30875 72102866-910b-0410-8b05-ffd578937521 --- Apps/EOModelEditor/CodeGenerator.m | 2 +- ChangeLog | 20 +++++ EOAccess/EODatabaseChannel.m | 50 +++-------- EOAccess/EODatabaseContext.m | 87 +++++++++++-------- EOAccess/EOEntity.m | 31 +++---- .../PostgreSQLAdaptor/PostgreSQLAdaptor.m | 3 +- EOControl/EOCustomObject.h | 5 +- EOControl/EOCustomObject.m | 12 ++- 8 files changed, 114 insertions(+), 96 deletions(-) diff --git a/Apps/EOModelEditor/CodeGenerator.m b/Apps/EOModelEditor/CodeGenerator.m index 22faa76..4911381 100644 --- a/Apps/EOModelEditor/CodeGenerator.m +++ b/Apps/EOModelEditor/CodeGenerator.m @@ -330,7 +330,7 @@ void addToUsedClasses(NSMutableArray * mutArray,NSSet * knownNames, NSArray * ot [cs appendString:[self classDummysForEntity:entity]]; - [cs appendFormat:@"@interface _%@ : EOCustomObject \n{\n", className]; + [cs appendFormat:@"@interface _%@ : EOCustomObject\n{\n", className]; while ((eoAttr = [enumer nextObject])) { [cs appendFormat:@" %@ _%@;\n", [eoAttr cScalarTypeString], [eoAttr name]]; diff --git a/ChangeLog b/ChangeLog index f2deb9a..12cfbce 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,23 @@ +2010-06-28 David Wetzel + * EOAccess/EOEntity.m + - createInstanceWithEditingContext:globalID:zone: + reformat, remove logs + * EOAccess/EODatabaseContext.m + -initializeObject:withGlobalID:editingContext: + rewritten, add exceptions + * EOAccess/EODatabaseChannel.m + -fetchObject + remove logs, add exceptions + * EOAdaptors/PostgreSQLAdaptor/PostgreSQLAdaptor.m + postgresClientVersion() + use stringWithCString:encoding: not stringWithCString: + * Apps/EOModelEditor/CodeGenerator.m + don't add to generated code + * EOControl/EOCustomObject.h + * EOControl/EOCustomObject.m + add -encodeWithCoder: + add -initWithCoder: + 2010-06-27 David Wetzel * EOAccess/EODatabaseContext.m -isValidQualifierTypeForAttribute: diff --git a/EOAccess/EODatabaseChannel.m b/EOAccess/EODatabaseChannel.m index 736f8d8..7a3be3b 100644 --- a/EOAccess/EODatabaseChannel.m +++ b/EOAccess/EODatabaseChannel.m @@ -302,14 +302,11 @@ RCS_ID("$Id$") //seems OK EODatabase *database=nil; id object = nil; - + database = [_databaseContext database]; if (![self isFetchInProgress]) - { - NSLog(@"No Fetch in progress"); - NSDebugMLog(@"No Fetch in progress", ""); - + { [NSException raise: NSInvalidArgumentException format: @"%@ -- %@ 0x%x: no fetch in progress", NSStringFromSelector(_cmd), @@ -326,12 +323,8 @@ RCS_ID("$Id$") propertiesToFetch = [self _propertiesToFetch]; - EOFLOGObjectLevel(@"gsdb", @"Will fetchRow"); - row = [_adaptorChannel fetchRowWithZone: NULL]; - EOFLOGObjectLevelArgs(@"gsdb", @"row=%@", row); - if (!row) { //TODO @@ -359,12 +352,8 @@ RCS_ID("$Id$") gid = [_currentEntity globalIDForRow: row isFinal: YES];//OK - EOFLOGObjectLevelArgs(@"gsdb", @"gid=%@", gid); - object = [_currentEditingContext objectForGlobalID: gid]; //OK //nil - EOFLOGObjectLevelArgs(@"gsdb", @"object=%@", object); - if (object) isObjectNew = NO; @@ -372,17 +361,8 @@ RCS_ID("$Id$") snapshot = [_databaseContext snapshotForGlobalID: gid]; //OK - EOFLOGObjectLevelArgs(@"gsdb", @"snapshot=%@", snapshot); - if (snapshot) - { - EOFLOGObjectLevelArgs(@"gsdb", @"_delegateRespondsTo.shouldUpdateSnapshot=%d", - (int)_delegateRespondsTo.shouldUpdateSnapshot); - EOFLOGObjectLevelArgs(@"gsdb", @"[self isLocking]=%d", - (int)[self isLocking]); - EOFLOGObjectLevelArgs(@"gsdb", @"[self isRefreshingObjects]=%d", - (int)[self isRefreshingObjects]); - + { //mirko: if((_delegateRespondsTo.shouldUpdateSnapshot == NO && ([self isLocking] == YES @@ -394,8 +374,6 @@ RCS_ID("$Id$") globalID: gid databaseChannel: self]))) { // TODO delegate not correct ! - EOFLOGObjectLevelArgs(@"gsdb", @"Updating Snapshot=%@", snapshot); - EOFLOGObjectLevelArgs(@"gsdb", @"row=%@", row); [_databaseContext recordSnapshot: row forGlobalID: gid]; @@ -404,17 +382,12 @@ RCS_ID("$Id$") } else { - EOFLOGObjectLevelArgs(@"gsdb", @"database class=%@", [database class]); - NSAssert(database, @"No database-context database"); [database recordSnapshot: row forGlobalID: gid]; } - EOFLOGObjectLevelArgs(@"gsdb", @"[self isRefreshingObjects]=%d", - (int)[self isRefreshingObjects]); - //From mirko if ([self isRefreshingObjects] == YES) { @@ -434,7 +407,6 @@ RCS_ID("$Id$") globalID: gid zone: NULL]; - EOFLOGObjectLevelArgs(@"gsdb", @"object=%@", object); NSAssert1(object, @"No Object. entityClassDescripton=%@", entityClassDescripton); EOEditingContext_recordObjectGlobalIDWithImpPtr(_currentEditingContext, @@ -447,7 +419,6 @@ RCS_ID("$Id$") EOKeyGlobalID *handlerGID = (EOKeyGlobalID *)[handler globalID]; isObjectNew = YES; //TODO - [handlerGID isFinal]; //YES //TODO [EOFault clearFault: object]; @@ -461,11 +432,14 @@ RCS_ID("$Id$") if (isObjectNew) //TODO { + if ((!object) || ([object isKindOfClass:[EOCustomObject class]] == NO)) { + [NSException raise: NSInternalInconsistencyException + format: @"%s:%d cannot initialize nil/non EOCustomObject object!", __FILE__, __LINE__]; + } [EOObserverCenter suppressObserverNotification]; NS_DURING { - EOFLOGObjectLevelArgs(@"gsdb", @"Initialize %p", object); [_currentEditingContext initializeObject: object withGlobalID: gid @@ -479,15 +453,19 @@ RCS_ID("$Id$") NS_ENDHANDLER; [EOObserverCenter enableObserverNotification]; + + if ((!object) || ([object isKindOfClass:[EOCustomObject class]] == NO)) { + [NSException raise: NSInternalInconsistencyException + format: @"%s:%d cannot initialize nil/non EOCustomObject object!", __FILE__, __LINE__]; + } + [object awakeFromFetchInEditingContext: _currentEditingContext]; } } } - - return object; -}; +} - (BOOL)isFetchInProgress { diff --git a/EOAccess/EODatabaseContext.m b/EOAccess/EODatabaseContext.m index 4a59190..2b0d47c 100644 --- a/EOAccess/EODatabaseContext.m +++ b/EOAccess/EODatabaseContext.m @@ -820,45 +820,64 @@ classPropertyNames = [entity classPropertyNames]; } - (void)initializeObject: (id)object - withGlobalID: (EOGlobalID *)globalID + withGlobalID: (EOGlobalID *)globalID editingContext: (EOEditingContext *)context { -//near OK - EOEntity *entity = nil; - - + NSDictionary * snapDict = nil; + EOEntity * entity = nil; + /* + TODO use this stuff -- dw + if (globalID == _currentGlobalID) + { + snapDict = _currentSnapshot; + entity = _lastEntity; + } else ... + */ + if ([globalID isTemporary]) + { + return; + } + + snapDict = [self snapshotForGlobalID:globalID]; + + if ([(EOKeyGlobalID *)globalID isFinal]) + { + entity = [self entityForGlobalID:globalID]; + } else { + object = [context objectForGlobalID:globalID]; + if (!object) { - NSEmitTODO(); - [self notImplemented: _cmd]; //TODO + [NSException raise: NSInternalInconsistencyException + format: @"%s No object for gid %@ in %@", __PRETTY_FUNCTION__, globalID, context]; } + entity = [_database entityForObject:object]; + } - if (![(EOKeyGlobalID *)globalID isFinal]) - { - NSEmitTODO(); - [self notImplemented: _cmd]; //TODO + if (!snapDict) + { + [NSException raise: NSInternalInconsistencyException + format: @"%s No snapshot for gid %@", __PRETTY_FUNCTION__, globalID]; + } else { + if ((!object) || ([object isKindOfClass:[EOCustomObject class]] == NO)) { + [NSException raise: NSInternalInconsistencyException + format: @"%s:%d cannot initialize nil/non EOCustomObject object!", __FILE__, __LINE__]; } - - //mirko: - if (_updateStrategy == EOUpdateWithPessimisticLocking) - [self registerLockedObjectWithGlobalID: globalID]; - - entity = [self entityForGlobalID: globalID]; - -/*Mirko: - if ([object respondsToSelector:@selector(entity)]) - entity = [object entity]; - else - entity = [_database entityNamed:[globalID entityName]]; -*/ - - [self initializeObject: object - row: EODatabaseContext_snapshotForGlobalIDWithImpPtr(self,NULL,globalID) //shound be _currentSnapshot - entity: entity - editingContext: context]; - - + + [self initializeObject: object + row: snapDict + entity: entity + editingContext: context]; + + if ((!object) || ([object isKindOfClass:[EOCustomObject class]] == NO)) { + [NSException raise: NSInternalInconsistencyException + format: @"%s:%d Something went wrong!", __FILE__, __LINE__]; + } + + [_database incrementSnapshotCountForGlobalID:globalID]; + } + } - (void) _objectsChanged: (NSNotification*)notification @@ -6124,15 +6143,9 @@ Raises an exception is the adaptor is unable to perform the operations. IMP objectTakeStoredValueForKeyIMP=NULL; IMP rowObjectForKeyIMP=NULL; - - - - classPropertyAttributeNames = [entity classPropertyAttributeNames]; count = [classPropertyAttributeNames count]; - - //row is usuallly a EOMutableKnownKeyDictionary so will use EOMKKD_objectForKeyWithImpPtr if (count>0) diff --git a/EOAccess/EOEntity.m b/EOAccess/EOEntity.m index a78399f..87643bb 100644 --- a/EOAccess/EOEntity.m +++ b/EOAccess/EOEntity.m @@ -4206,29 +4206,22 @@ fromInsertionInEditingContext: (EOEditingContext *)context { id obj = nil; Class objectClass; - - - + NSAssert1(_entity, @"No _entity in %@", self); - + objectClass = [_entity classForObjectWithGlobalID: (EOKeyGlobalID*)globalID]; - EOFLOGObjectLevelArgs(@"EOEntity", @"objectClass=%p", objectClass); - + NSAssert2(objectClass, @"No objectClass for globalID=%@. EntityName=%@", - globalID, [_entity name]); - + globalID, [_entity name]); + if (objectClass) - { - EOFLOGObjectLevelArgs(@"EOEntity", @"objectClass=%@", objectClass); - - obj = AUTORELEASE([[objectClass allocWithZone:zone] - initWithEditingContext: editingContext - classDescription: self - globalID: globalID]); - } - - - + { + obj = AUTORELEASE([[objectClass allocWithZone:zone] + initWithEditingContext: editingContext + classDescription: self + globalID: globalID]); + } + return obj; } diff --git a/EOAdaptors/PostgreSQLAdaptor/PostgreSQLAdaptor.m b/EOAdaptors/PostgreSQLAdaptor/PostgreSQLAdaptor.m index e8e50d8..dab58a3 100644 --- a/EOAdaptors/PostgreSQLAdaptor/PostgreSQLAdaptor.m +++ b/EOAdaptors/PostgreSQLAdaptor/PostgreSQLAdaptor.m @@ -87,7 +87,8 @@ postgresClientVersion() static int version = 0; if (version == 0) { - NSString *versionString = [NSString stringWithCString: PG_VERSION]; + NSString *versionString = [NSString stringWithCString:PG_VERSION + encoding:NSASCIIStringEncoding]; version = [versionString parsedFirstVersionSubstring]; } return version; diff --git a/EOControl/EOCustomObject.h b/EOControl/EOCustomObject.h index 76a7f21..0582979 100644 --- a/EOControl/EOCustomObject.h +++ b/EOControl/EOCustomObject.h @@ -39,7 +39,7 @@ @class EOEditingContext; -@interface EOCustomObject : NSObject +@interface EOCustomObject : NSObject { } @@ -119,6 +119,9 @@ - (NSString *)eoShallowDescription; - (NSString *)eoDescription; +- (void)encodeWithCoder:(NSCoder *)aCoder; +- (id)initWithCoder:(NSCoder *)aDecoder; + @end #endif // __EOCustomObject_h__ diff --git a/EOControl/EOCustomObject.m b/EOControl/EOCustomObject.m index 4fb88b7..39345f7 100644 --- a/EOControl/EOCustomObject.m +++ b/EOControl/EOCustomObject.m @@ -1057,7 +1057,17 @@ RCS_ID("$Id: EOGenericRecord.m 30111 2010-04-09 10:09:41Z ayers $") return ret; //TODO } -// ----------------------------------------------- +- (void)encodeWithCoder:(NSCoder *)aCoder +{ + [EOEditingContext encodeObject:self + withCoder:aCoder]; +} + +- (id)initWithCoder:(NSCoder *)aDecoder +{ + return [EOEditingContext initObject:self + withCoder:aDecoder]; +} @end