- (EOAdaptorChannel *)acquireOpenChannelForURL:(NSURL *)_url;
- (void)releaseChannel:(EOAdaptorChannel *)_channel;
+/* checking for tables */
+
+- (BOOL)canConnect:(NSURL *)_url;
+
@end
#endif /* __OGoContentStore_OCSChannelManager_H__ */
[_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 {
#import <Foundation/NSObject.h>
-@class NSString, NSURL, NSNumber;
+@class NSString, NSURL, NSNumber, NSArray;
@class EOAdaptorChannel;
@class OCSFolderManager, OCSFolderType, OCSChannelManager;
- (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__ */
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 {
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;
}
- (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 {
// $Id$
-#include <OGoContentStore/OCSFolderManager.h>
-#include "common.h"
+#import <Foundation/NSObject.h>
@class NSUserDefaults;
@class OCSFolderManager;
@end
+#include <OGoContentStore/OCSFolder.h>
+#include <OGoContentStore/OCSFolderManager.h>
+#include "common.h"
+
@implementation Tool
- (id)init {
/* operation */
- (int)runOnPath:(NSString *)_path {
- NSArray *subfolders;
- unsigned i, count;
+ NSArray *subfolders;
+ unsigned i, count;
+ OCSFolder *folder;
[self logWithFormat:@"ls path: '%@'", _path];
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;
}