Monotone-Parent: 54ac2dbf42dee286f64da8b9b3c4567570b00258

Monotone-Revision: dbc58efbc938f11a813baa01021a534ed90f70b8

Monotone-Author: wsourdeau@inverse.ca
Monotone-Date: 2012-08-13T17:48:18
Monotone-Branch: ca.inverse.sogo
maint-2.0.2
Wolfgang Sourdeau 2012-08-13 17:48:18 +00:00
parent 5557c01b99
commit 57afca1c74
3 changed files with 67 additions and 1 deletions

View File

@ -1,5 +1,10 @@
2012-08-13 Wolfgang Sourdeau <wsourdeau@inverse.ca>
* OpenChange/SOGoMAPIDBObject.m (-performBatchSQLQueries:) new
method to perform void queries under a transaction.
(-changePathTo:) new method that updates the references for the
object record in the dbfs table.
* SoObjects/SOGo/NSString+Utilities.m
(-stringByReplacingPrefix:withPrefix:): new self-explicit method.

View File

@ -73,10 +73,12 @@ typedef enum {
/* automatically set from actions */
- (BOOL) deleted;
- (void) changePathTo: (NSString *) newPath;
/* db helpers */
- (EOAdaptor *) tableChannelAdaptor;
- (NSArray *) performSQLQuery: (NSString *) sql;
- (BOOL) performBatchSQLQueries: (NSArray *) queries;
@end

View File

@ -260,6 +260,33 @@ static EOAttribute *textColumn = nil;
}
/* actions */
- (void) changePathTo: (NSString *) newPath
{
NSMutableString *sql;
NSString *oldPath, *newParentPath;
NSRange slashRange;
oldPath = [self path];
slashRange = [newPath rangeOfString: @"/"
options: NSBackwardsSearch];
if (slashRange.location != NSNotFound)
newParentPath = [newPath substringToIndex: slashRange.location];
else
newParentPath = NULL;
sql = [NSMutableString stringWithFormat: @"UPDATE %@"
@" SET c_path = '%@'",
[self tableName],
newPath];
if (newParentPath)
[sql appendFormat: @", c_parent_path = '%@'", newParentPath];
else
[sql appendString: @", c_parent_path = NULL"];
[sql appendFormat: @" WHERE c_path = '%@'", oldPath];
[self performBatchSQLQueries: [NSArray arrayWithObject: sql]];
}
- (EOAdaptor *) tableChannelAdaptor
{
GCSChannelManager *cm;
@ -307,6 +334,38 @@ static EOAttribute *textColumn = nil;
return records;
}
- (BOOL) performBatchSQLQueries: (NSArray *) queries
{
GCSChannelManager *cm;
EOAdaptorChannel *channel;
EOAdaptorContext *dbContext;
NSException *error;
NSUInteger count, max;
NSString *sql;
cm = [GCSChannelManager defaultChannelManager];
channel = [cm acquireOpenChannelForURL: [self tableUrl]];
dbContext = [channel adaptorContext];
[dbContext beginTransaction];
error = nil;
max = [queries count];
for (count = 0; error == nil && count < max; count++)
{
sql = [queries objectAtIndex: count];
error = [channel evaluateExpressionX: sql];
if (error)
[dbContext rollbackTransaction];
}
if (!error)
[dbContext commitTransaction];
[cm releaseChannel: channel];
return (error == nil);
}
- (NSDictionary *) lookupRecord: (NSString *) path
newerThanVersion: (NSInteger) startVersion
{