From cee703c4562d49d899727cdfd9717df798ec778d Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Thu, 19 Nov 2009 19:57:26 +0000 Subject: [PATCH] Monotone-Parent: f240bfe4674e163be4ece6a56adc0840ccdf87e9 Monotone-Revision: b7751a69b5bfafc16aaf3506b97e9c0d3aeeab69 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2009-11-19T19:57:26 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 3 + SoObjects/SOGo/SOGoUserDefaults.m | 100 +++++++++++++++++------------- 2 files changed, 60 insertions(+), 43 deletions(-) diff --git a/ChangeLog b/ChangeLog index 678b00e96..7876057af 100644 --- a/ChangeLog +++ b/ChangeLog @@ -17,6 +17,9 @@ (-jsonRepresentation): we now handle the cache data from here, as it made more sense and reduces the code size in SOGoUser.m. (-fetchProfile): now a void method. + (-storeJSONProfileInDB:): new method that handles the DB portion + of primaryStoreProfile, providing a corollary to + fetchJSONProfileFromDB. * SoObjects/SOGo/SOGoCache.m (+initialize): the memcached host can now be configured using the "SOGoMemCachedHost" user default. The diff --git a/SoObjects/SOGo/SOGoUserDefaults.m b/SoObjects/SOGo/SOGoUserDefaults.m index 909e8f371..30634cde4 100644 --- a/SoObjects/SOGo/SOGoUserDefaults.m +++ b/SoObjects/SOGo/SOGoUserDefaults.m @@ -99,7 +99,7 @@ static NSString *uidColumnName = @"c_uid"; /* operation */ -- (NSString *) _fetchJSONProfileFromDB +- (NSString *) fetchJSONProfileFromDB { GCSChannelManager *cm; EOAdaptorChannel *channel; @@ -197,7 +197,7 @@ static NSString *uidColumnName = @"c_uid"; } else { - jsonValue = [self _fetchJSONProfileFromDB]; + jsonValue = [self fetchJSONProfileFromDB]; if ([jsonValue length]) { defFlags.isNew = NO; @@ -292,69 +292,83 @@ static NSString *uidColumnName = @"c_uid"; return sql; } -- (BOOL) primaryStoreProfile +- (BOOL) storeJSONProfileInDB: (NSString *) jsonRepresentation { GCSChannelManager *cm; EOAdaptorChannel *channel; NSException *ex; - NSString *sql, *jsonRepresentation; - SOGoCache *cache; + NSString *sql; BOOL rc; rc = NO; - jsonRepresentation = [values jsonStringValue]; - if (jsonRepresentation) + sql = ((defFlags.isNew) + ? [self generateSQLForInsert: jsonRepresentation] + : [self generateSQLForUpdate: jsonRepresentation]); + cm = [GCSChannelManager defaultChannelManager]; + channel = [cm acquireOpenChannelForURL: [self tableURL]]; + if (channel) { - sql = ((defFlags.isNew) - ? [self generateSQLForInsert: jsonRepresentation] - : [self generateSQLForUpdate: jsonRepresentation]); - cm = [GCSChannelManager defaultChannelManager]; - channel = [cm acquireOpenChannelForURL: [self tableURL]]; - if (channel) + if ([[channel adaptorContext] beginTransaction]) { - if ([[channel adaptorContext] beginTransaction]) + defFlags.ready = YES; + ex = [channel evaluateExpressionX:sql]; + if (ex) { - defFlags.ready = YES; - ex = [channel evaluateExpressionX:sql]; - if (ex) - { - [self errorWithFormat: @"could not run SQL '%@': %@", sql, ex]; - [[channel adaptorContext] rollbackTransaction]; - } - else - { - if ([[channel adaptorContext] commitTransaction]) - { - cache = [SOGoCache sharedCache]; - if ([fieldName isEqualToString: @"c_defaults"]) - [cache setUserDefaults: jsonRepresentation - forLogin: uid]; - else - [cache setUserSettings: jsonRepresentation - forLogin: uid]; - } - defFlags.modified = NO; - defFlags.isNew = NO; - } - [cm releaseChannel: channel]; + [self errorWithFormat: @"could not run SQL '%@': %@", sql, ex]; + [[channel adaptorContext] rollbackTransaction]; } else { - defFlags.ready = NO; - [cm releaseChannel: channel immediately: YES]; + rc = YES; + defFlags.modified = NO; + defFlags.isNew = NO; } + [cm releaseChannel: channel]; } else { defFlags.ready = NO; - [self errorWithFormat: @"failed to acquire channel for URL: %@", - [self tableURL]]; + [cm releaseChannel: channel immediately: YES]; } } else - [self errorWithFormat: @"Unable to convert (%@) to a JSON string for" - @" type: %@ and login: %@", values, fieldName, uid]; + { + defFlags.ready = NO; + [self errorWithFormat: @"failed to acquire channel for URL: %@", + [self tableURL]]; + } + + return rc; +} + +- (BOOL) primaryStoreProfile +{ + NSString *jsonRepresentation; + SOGoCache *cache; + BOOL rc; + + jsonRepresentation = [values jsonStringValue]; + if (jsonRepresentation) + { + rc = [self storeJSONProfileInDB: jsonRepresentation]; + if (rc) + { + cache = [SOGoCache sharedCache]; + if ([fieldName isEqualToString: @"c_defaults"]) + [cache setUserDefaults: jsonRepresentation + forLogin: uid]; + else + [cache setUserSettings: jsonRepresentation + forLogin: uid]; + } + } + else + { + [self errorWithFormat: @"Unable to convert (%@) to a JSON string for" + @" type: %@ and login: %@", values, fieldName, uid]; + rc = NO; + } return rc; }