From: helge Date: Tue, 29 Jun 2004 15:46:08 +0000 (+0000) Subject: git-svn-id: http://svn.opengroupware.org/SOGo/trunk@76 d1b88da0-ebda-0310-925b-ed51d8... X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c71d7c5deda6420fa379ff6130c710fd984a95fc;p=scalable-opengroupware.org git-svn-id: http://svn.opengroupware.org/SOGo/trunk@76 d1b88da0-ebda-0310-925b-ed51d893ca5b --- diff --git a/OGoContentStore/OCSChannelManager.h b/OGoContentStore/OCSChannelManager.h index acfde2dd..c95ccc99 100644 --- a/OGoContentStore/OCSChannelManager.h +++ b/OGoContentStore/OCSChannelManager.h @@ -46,6 +46,10 @@ - (EOAdaptorChannel *)acquireOpenChannelForURL:(NSURL *)_url; - (void)releaseChannel:(EOAdaptorChannel *)_channel; +/* checking for tables */ + +- (BOOL)canConnect:(NSURL *)_url; + @end #endif /* __OGoContentStore_OCSChannelManager_H__ */ diff --git a/OGoContentStore/OCSChannelManager.m b/OGoContentStore/OCSChannelManager.m index 2bc60053..881f9c30 100644 --- a/OGoContentStore/OCSChannelManager.m +++ b/OGoContentStore/OCSChannelManager.m @@ -202,6 +202,37 @@ static BOOL debugOn = YES; [_channel release]; } +/* checking for tables */ + +- (BOOL)canConnect:(NSURL *)_url { + /* + this can check for DB connect as well as for table URLs (whether a table + exists) + */ + EOAdaptorChannel *channel; + NSString *table; + BOOL result; + + if ((channel = [self acquireOpenChannelForURL:_url]) == nil) { + if (debugOn) [self debugWithFormat:@"could not acquire channel: %@", _url]; + return NO; + } + if (debugOn) [self debugWithFormat:@"acquired channel: %@", channel]; + result = YES; /* could open channel */ + + /* check whether table exists */ + + table = [_url ocsTableName]; + if ([table length] > 0) + result = [channel tableExistsWithName:table]; + + /* release channel */ + + [self releaseChannel:channel]; channel = nil; + + return result; +} + /* debugging */ - (BOOL)isDebuggingEnabled { diff --git a/OGoContentStore/OCSFolder.h b/OGoContentStore/OCSFolder.h index c26e2a8d..cf9dbc84 100644 --- a/OGoContentStore/OCSFolder.h +++ b/OGoContentStore/OCSFolder.h @@ -25,7 +25,7 @@ #import -@class NSString, NSURL, NSNumber; +@class NSString, NSURL, NSNumber, NSArray; @class EOAdaptorChannel; @class OCSFolderManager, OCSFolderType, OCSChannelManager; @@ -61,12 +61,20 @@ - (NSString *)storeTableName; - (NSString *)quickTableName; -/* channels */ +/* connection */ - (EOAdaptorChannel *)acquireStoreChannel; - (EOAdaptorChannel *)acquireQuickChannel; - (void)releaseChannel:(EOAdaptorChannel *)_channel; +- (BOOL)canConnectStore; +- (BOOL)canConnectQuick; + +/* operations */ + +- (NSArray *)subFolderNames; +- (NSArray *)allSubFolderNames; + @end #endif /* __OGoContentStore_OCSFolder_H__ */ diff --git a/OGoContentStore/OCSFolder.m b/OGoContentStore/OCSFolder.m index 795ff5dc..2bde8671 100644 --- a/OGoContentStore/OCSFolder.m +++ b/OGoContentStore/OCSFolder.m @@ -127,6 +127,24 @@ static BOOL debugOn = YES; if (debugOn) [self debugWithFormat:@"released channel: %@", _channel]; } +- (BOOL)canConnectStore { + return [[self channelManager] canConnect:[self location]]; +} +- (BOOL)canConnectQuick { + return [[self channelManager] canConnect:[self quickLocation]]; +} + +/* operations */ + +- (NSArray *)subFolderNames { + return [[self folderManager] listSubFoldersAtPath:[self path] + recursive:NO]; +} +- (NSArray *)allSubFolderNames { + return [[self folderManager] listSubFoldersAtPath:[self path] + recursive:YES]; +} + /* description */ - (NSString *)description { @@ -144,7 +162,7 @@ static BOOL debugOn = YES; if ((tmp = [self path])) [ms appendFormat:@" path=%@", tmp]; if ((tmp = [self folderTypeName])) [ms appendFormat:@" type=%@", tmp]; if ((tmp = [self location])) - [ms appendFormat:@" db=%@", [tmp absoluteString]]; + [ms appendFormat:@" loc=%@", [tmp absoluteString]]; [ms appendString:@">"]; return ms; diff --git a/OGoContentStore/OCSFolderManager.m b/OGoContentStore/OCSFolderManager.m index 842eb330..560544f4 100644 --- a/OGoContentStore/OCSFolderManager.m +++ b/OGoContentStore/OCSFolderManager.m @@ -145,23 +145,7 @@ static const char *OCSPathColumnPattern = "c_path%i"; } - (BOOL)canConnect { - EOAdaptorChannel *channel; - BOOL result; - - /* check whether we can open a connection */ - - if ((channel = [self acquireOpenChannel]) == nil) { - if (debugOn) [self debugWithFormat:@"could not acquire channel!"]; - return NO; - } - if (debugOn) [self debugWithFormat:@"acquired channel: %@", channel]; - - /* check whether table exists */ - - result = [channel tableExistsWithName:[self folderInfoTableName]]; - [self releaseChannel:channel]; channel = nil; - - return result; + return [[self channelManager] canConnect:[self folderInfoLocation]]; } - (NSArray *)performSQL:(NSString *)_sql { diff --git a/OGoContentStore/ocs_ls.m b/OGoContentStore/ocs_ls.m index dba6ac37..47706d29 100644 --- a/OGoContentStore/ocs_ls.m +++ b/OGoContentStore/ocs_ls.m @@ -1,7 +1,6 @@ // $Id$ -#include -#include "common.h" +#import @class NSUserDefaults; @class OCSFolderManager; @@ -16,6 +15,10 @@ @end +#include +#include +#include "common.h" + @implementation Tool - (id)init { @@ -34,8 +37,9 @@ /* operation */ - (int)runOnPath:(NSString *)_path { - NSArray *subfolders; - unsigned i, count; + NSArray *subfolders; + unsigned i, count; + OCSFolder *folder; [self logWithFormat:@"ls path: '%@'", _path]; @@ -55,8 +59,12 @@ for (i = 0, count = [subfolders count]; i < count; i++) { printf("%s\n", [[subfolders objectAtIndex:i] cString]); } + + folder = [self->folderManager folderAtPath:_path]; - NSLog(@"folder: %@", [self->folderManager folderAtPath:_path]); + NSLog(@"folder: %@", folder); + NSLog(@" can%s connect store.", [folder canConnectStore] ? "" : "not"); + NSLog(@" can%s connect quick.", [folder canConnectQuick] ? "" : "not"); return 0; } diff --git a/OGoContentStore/sql/folderinfo.psql b/OGoContentStore/sql/folderinfo-create.psql similarity index 100% rename from OGoContentStore/sql/folderinfo.psql rename to OGoContentStore/sql/folderinfo-create.psql