Monotone-Parent: 54ac2dbf42dee286f64da8b9b3c4567570b00258
Monotone-Revision: dbc58efbc938f11a813baa01021a534ed90f70b8 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2012-08-13T17:48:18 Monotone-Branch: ca.inverse.sogomaint-2.0.2
parent
5557c01b99
commit
57afca1c74
|
@ -1,5 +1,10 @@
|
||||||
2012-08-13 Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
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
|
* SoObjects/SOGo/NSString+Utilities.m
|
||||||
(-stringByReplacingPrefix:withPrefix:): new self-explicit method.
|
(-stringByReplacingPrefix:withPrefix:): new self-explicit method.
|
||||||
|
|
||||||
|
|
|
@ -73,10 +73,12 @@ typedef enum {
|
||||||
/* automatically set from actions */
|
/* automatically set from actions */
|
||||||
- (BOOL) deleted;
|
- (BOOL) deleted;
|
||||||
|
|
||||||
|
- (void) changePathTo: (NSString *) newPath;
|
||||||
|
|
||||||
/* db helpers */
|
/* db helpers */
|
||||||
- (EOAdaptor *) tableChannelAdaptor;
|
- (EOAdaptor *) tableChannelAdaptor;
|
||||||
- (NSArray *) performSQLQuery: (NSString *) sql;
|
- (NSArray *) performSQLQuery: (NSString *) sql;
|
||||||
|
- (BOOL) performBatchSQLQueries: (NSArray *) queries;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
|
@ -260,6 +260,33 @@ static EOAttribute *textColumn = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* actions */
|
/* 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
|
- (EOAdaptor *) tableChannelAdaptor
|
||||||
{
|
{
|
||||||
GCSChannelManager *cm;
|
GCSChannelManager *cm;
|
||||||
|
@ -307,6 +334,38 @@ static EOAttribute *textColumn = nil;
|
||||||
return records;
|
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
|
- (NSDictionary *) lookupRecord: (NSString *) path
|
||||||
newerThanVersion: (NSInteger) startVersion
|
newerThanVersion: (NSInteger) startVersion
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue