From: helge Date: Tue, 29 Jun 2004 14:59:00 +0000 (+0000) Subject: git-svn-id: http://svn.opengroupware.org/SOGo/trunk@75 d1b88da0-ebda-0310-925b-ed51d8... X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=647fecc41b4c50e8dc9e96a7cb30f349162ec565;p=scalable-opengroupware.org git-svn-id: http://svn.opengroupware.org/SOGo/trunk@75 d1b88da0-ebda-0310-925b-ed51d893ca5b --- diff --git a/OGoContentStore/EOAdaptorChannel+OCS.h b/OGoContentStore/EOAdaptorChannel+OCS.h new file mode 100644 index 00000000..10c9eab1 --- /dev/null +++ b/OGoContentStore/EOAdaptorChannel+OCS.h @@ -0,0 +1,34 @@ +/* + Copyright (C) 2004 SKYRIX Software AG + + This file is part of OpenGroupware.org. + + OGo is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + OGo is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with OGo; see the file COPYING. If not, write to the + Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. +*/ +// $Id$ + +#ifndef __OGoContentStore_EOAdaptorChannel_OCS_H__ +#define __OGoContentStore_EOAdaptorChannel_OCS_H__ + +#include + +@interface EOAdaptorChannel(OCS) + +- (BOOL)tableExistsWithName:(NSString *)_tableName; + +@end + +#endif /* __OGoContentStore_EOAdaptorChannel_OCS_H__ */ diff --git a/OGoContentStore/EOAdaptorChannel+OCS.m b/OGoContentStore/EOAdaptorChannel+OCS.m new file mode 100644 index 00000000..9050e423 --- /dev/null +++ b/OGoContentStore/EOAdaptorChannel+OCS.m @@ -0,0 +1,51 @@ +/* + Copyright (C) 2004 SKYRIX Software AG + + This file is part of OpenGroupware.org. + + OGo is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + OGo is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with OGo; see the file COPYING. If not, write to the + Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. +*/ +// $Id$ + +#include "EOAdaptorChannel+OCS.h" +#include "common.h" + +@implementation EOAdaptorChannel(OCS) + +- (BOOL)tableExistsWithName:(NSString *)_tableName { + NSException *ex; + NSString *sql; + BOOL didOpen; + + didOpen = NO; + if (![self isOpen]) { + if (![self openChannel]) + return NO; + didOpen = YES; + } + + sql = @"SELECT COUNT(*) FROM "; + sql = [sql stringByAppendingString:_tableName]; + sql = [sql stringByAppendingString:@" WHERE 1 = 2"]; + + ex = [[[self evaluateExpressionX:sql] retain] autorelease]; + [self cancelFetch]; + + if (didOpen) [self closeChannel]; + return ex != nil ? NO : YES; +} + +@end /* EOAdaptorChannel(OCS) */ diff --git a/OGoContentStore/GNUmakefile b/OGoContentStore/GNUmakefile index c1fef708..e79f9b01 100644 --- a/OGoContentStore/GNUmakefile +++ b/OGoContentStore/GNUmakefile @@ -1,12 +1,14 @@ # $Id$ include $(GNUSTEP_MAKEFILES)/common.make +include ./Version LIBRARY_NAME = libOGoContentStore TOOL_NAME = ocs_ls libOGoContentStore_HEADER_FILES += \ NSURL+OCS.h \ + EOAdaptorChannel+OCS.h \ \ OCSContext.h \ OCSFieldInfo.h \ @@ -17,6 +19,7 @@ libOGoContentStore_HEADER_FILES += \ libOGoContentStore_OBJC_FILES += \ NSURL+OCS.m \ + EOAdaptorChannel+OCS.m \ \ OCSContext.m \ OCSFieldInfo.m \ diff --git a/OGoContentStore/OCSChannelManager.m b/OGoContentStore/OCSChannelManager.m index d7a09d09..2bc60053 100644 --- a/OGoContentStore/OCSChannelManager.m +++ b/OGoContentStore/OCSChannelManager.m @@ -34,6 +34,17 @@ (eg missing release due to an exception) */ +@interface OCSChannelHandle : NSObject +{ +@public + EOAdaptorChannel *channel; + NSDate *creationTime; + NSDate *lastReleaseTime; + NSDate *lastAcquireTime; +} + +@end + @implementation OCSChannelManager static BOOL debugOn = YES; @@ -212,3 +223,40 @@ static BOOL debugOn = YES; } @end /* OCSChannelManager */ + +@implementation OCSChannelHandle + +- (void)dealloc { + [self->channel release]; + [self->creationTime release]; + [self->lastReleaseTime release]; + [self->lastAcquireTime release]; + [super dealloc]; +} + +/* accessors */ + +- (EOAdaptorChannel *)channel { + return self->channel; +} + +/* description */ + +- (NSString *)description { + NSMutableString *ms; + + ms = [NSMutableString stringWithCapacity:256]; + [ms appendFormat:@"<0x%08X[%@]:", self, NSStringFromClass([self class])]; + + [ms appendFormat:@" channel=0x%08X", self->channel]; + if (self->creationTime) [ms appendFormat:@" created=%@", self->creationTime]; + if (self->lastReleaseTime) + [ms appendFormat:@" last-released=%@", self->lastReleaseTime]; + if (self->lastAcquireTime) + [ms appendFormat:@" last-acquired=%@", self->lastAcquireTime]; + + [ms appendString:@">"]; + return ms; +} + +@end /* OCSChannelHandle */ diff --git a/OGoContentStore/OCSFolder.h b/OGoContentStore/OCSFolder.h index e1ff59fc..c26e2a8d 100644 --- a/OGoContentStore/OCSFolder.h +++ b/OGoContentStore/OCSFolder.h @@ -26,6 +26,7 @@ #import @class NSString, NSURL, NSNumber; +@class EOAdaptorChannel; @class OCSFolderManager, OCSFolderType, OCSChannelManager; @interface OCSFolder : NSObject @@ -57,6 +58,15 @@ - (OCSFolderManager *)folderManager; - (OCSChannelManager *)channelManager; +- (NSString *)storeTableName; +- (NSString *)quickTableName; + +/* channels */ + +- (EOAdaptorChannel *)acquireStoreChannel; +- (EOAdaptorChannel *)acquireQuickChannel; +- (void)releaseChannel:(EOAdaptorChannel *)_channel; + @end #endif /* __OGoContentStore_OCSFolder_H__ */ diff --git a/OGoContentStore/OCSFolder.m b/OGoContentStore/OCSFolder.m index 0995f860..795ff5dc 100644 --- a/OGoContentStore/OCSFolder.m +++ b/OGoContentStore/OCSFolder.m @@ -23,25 +23,36 @@ #include "OCSFolder.h" #include "OCSFolderManager.h" #include "OCSFolderType.h" +#include "OCSChannelManager.h" +#include "NSURL+OCS.h" +#include "EOAdaptorChannel+OCS.h" #include "common.h" @implementation OCSFolder +static BOOL debugOn = YES; + ++ (void)initialize { + NSUserDefaults *ud = [NSUserDefaults standardUserDefaults]; + + debugOn = [ud boolForKey:@"OCSFolderDebugEnabled"]; +} + - (id)initWithPath:(NSString *)_path primaryKey:(id)_folderId folderTypeName:(NSString *)_ftname folderType:(OCSFolderType *)_ftype location:(NSURL *)_loc quickLocation:(NSURL *)_qloc folderManager:(OCSFolderManager *)_fm { if ((self = [super init])) { - self->folderManager = [_fm retain]; - self->folderInfo = [_ftype retain]; + self->folderManager = [_fm retain]; + self->folderInfo = [_ftype retain]; - self->folderId = [_folderId copy]; - self->folderName = [[_path lastPathComponent] copy]; - self->path = [_path copy]; - self->location = [_loc retain]; - self->quickLocation = [_qloc retain]; - self->folderTypeName = [_ftname copy]; + self->folderId = [_folderId copy]; + self->folderName = [[_path lastPathComponent] copy]; + self->path = [_path copy]; + self->location = [_loc retain]; + self->quickLocation = [_qloc retain]; + self->folderTypeName = [_ftname copy]; } return self; } @@ -53,14 +64,14 @@ } - (void)dealloc { - [self->folderManager release]; - [self->folderInfo release]; - [self->folderId release]; - [self->folderName release]; - [self->path release]; - [self->location release]; - [self->quickLocation release]; - [self->folderTypeName release]; + [self->folderManager release]; + [self->folderInfo release]; + [self->folderId release]; + [self->folderName release]; + [self->path release]; + [self->location release]; + [self->quickLocation release]; + [self->folderTypeName release]; [super dealloc]; } @@ -80,12 +91,14 @@ - (NSURL *)location { return self->location; } +- (NSURL *)quickLocation { + return self->quickLocation; +} - (NSString *)folderTypeName { return self->folderTypeName; } - - (OCSFolderManager *)folderManager { return self->folderManager; } @@ -93,6 +106,27 @@ return [[self folderManager] channelManager]; } +- (NSString *)storeTableName { + return [[self location] ocsTableName]; +} +- (NSString *)quickTableName { + return [[self quickLocation] ocsTableName]; +} + +/* channels */ + +- (EOAdaptorChannel *)acquireStoreChannel { + return [[self channelManager] acquireOpenChannelForURL:[self location]]; +} +- (EOAdaptorChannel *)acquireQuickChannel { + return [[self channelManager] acquireOpenChannelForURL:[self quickLocation]]; +} + +- (void)releaseChannel:(EOAdaptorChannel *)_channel { + [[self channelManager] releaseChannel:_channel]; + if (debugOn) [self debugWithFormat:@"released channel: %@", _channel]; +} + /* description */ - (NSString *)description { diff --git a/OGoContentStore/OCSFolderManager.m b/OGoContentStore/OCSFolderManager.m index d11ca83c..842eb330 100644 --- a/OGoContentStore/OCSFolderManager.m +++ b/OGoContentStore/OCSFolderManager.m @@ -25,6 +25,7 @@ #include "OCSFolderType.h" #include "OCSFolder.h" #include "NSURL+OCS.h" +#include "EOAdaptorChannel+OCS.h" #include "common.h" #include @@ -145,8 +146,7 @@ static const char *OCSPathColumnPattern = "c_path%i"; - (BOOL)canConnect { EOAdaptorChannel *channel; - NSString *sql; - NSException *ex; + BOOL result; /* check whether we can open a connection */ @@ -158,17 +158,10 @@ static const char *OCSPathColumnPattern = "c_path%i"; /* check whether table exists */ - sql = @"SELECT COUNT(*) FROM "; - sql = [sql stringByAppendingString:[self folderInfoTableName]]; - sql = [sql stringByAppendingString:@" WHERE 1 = 2"]; + result = [channel tableExistsWithName:[self folderInfoTableName]]; + [self releaseChannel:channel]; channel = nil; - ex = [[[channel evaluateExpressionX:sql] retain] autorelease]; - [channel cancelFetch]; - [self releaseChannel:channel]; - - if (debugOn && ex != nil) [self debugWithFormat:@" folder-eval: %@", ex]; - - return ex != nil ? NO : YES; + return result; } - (NSArray *)performSQL:(NSString *)_sql { diff --git a/OGoContentStore/Version b/OGoContentStore/Version new file mode 100644 index 00000000..7d481ef6 --- /dev/null +++ b/OGoContentStore/Version @@ -0,0 +1,5 @@ +# $Id: Version,v 1.201 2004/06/29 13:45:54 helge Exp $ + +MAJOR_VERSION=0 +MINOR_VERSION=9 +SUBMINOR_VERSION:=0