]> err.no Git - scalable-opengroupware.org/commitdiff
git-svn-id: http://svn.opengroupware.org/SOGo/trunk@23 d1b88da0-ebda-0310-925b-ed51d8...
authorhelge <helge@d1b88da0-ebda-0310-925b-ed51d893ca5b>
Mon, 7 Jun 2004 15:09:14 +0000 (15:09 +0000)
committerhelge <helge@d1b88da0-ebda-0310-925b-ed51d893ca5b>
Mon, 7 Jun 2004 15:09:14 +0000 (15:09 +0000)
OGoContentStore/GNUmakefile
OGoContentStore/OCSChannelManager.h
OGoContentStore/OCSChannelManager.m
OGoContentStore/OCSContext.h
OGoContentStore/OCSFolderManager.h
OGoContentStore/OCSFolderManager.m
OGoContentStore/common.h

index 8d11000bc1653878fc2b2ee50aeb7a47c4219c1e..ef9bc9da6e381be69d381c4a2c3b9362b23fc67a 100644 (file)
@@ -5,6 +5,8 @@ include $(GNUSTEP_MAKEFILES)/common.make
 LIBRARY_NAME = libOGoContentStore
 
 libOGoContentStore_HEADER_FILES += \
+       NSURL+OCS.h             \
+       \
        OCSContext.h            \
        OCSFieldInfo.h          \
        OCSFolder.h             \
@@ -13,6 +15,8 @@ libOGoContentStore_HEADER_FILES += \
        OCSChannelManager.h     \
 
 libOGoContentStore_OBJC_FILES += \
+       NSURL+OCS.m             \
+       \
        OCSContext.m            \
        OCSFieldInfo.m          \
        OCSFolder.m             \
@@ -20,6 +24,8 @@ libOGoContentStore_OBJC_FILES += \
        OCSFolderType.m         \
        OCSChannelManager.m     \
 
+libOGoContentStore_LIBRARY_DEPENDS_UPON += -lGDLAccess
+
 -include GNUmakefile.preamble
 include $(GNUSTEP_MAKEFILES)/library.make
 -include GNUmakefile.postamble
index d733149fb318f6b712178ec2ddb86d3924dea8df..acfde2dd8b75ef83d0fe1dc2054e4f07e10250e4 100644 (file)
 
 #import <Foundation/NSObject.h>
 
+/*
+  OCSChannelManager
+
+  This object manages the connection pooling.
+*/
+
+@class NSURL, NSMutableDictionary;
+@class EOAdaptorChannel, EOAdaptor;
+
 @interface OCSChannelManager : NSObject
 {
+  NSMutableDictionary *urlToAdaptor;
 }
 
++ (id)defaultChannelManager;
+
+/* channels */
+
+- (EOAdaptorChannel *)acquireOpenChannelForURL:(NSURL *)_url;
+- (void)releaseChannel:(EOAdaptorChannel *)_channel;
+
 @end
 
 #endif /* __OGoContentStore_OCSChannelManager_H__ */
index 4152f1d09be8483973a1c66ebf774c285ccc3165..6bf6f064277dd8e38cc2822564cb7778eed2ce84 100644 (file)
 // $Id$
 
 #include "OCSChannelManager.h"
+#include "NSURL+OCS.h"
+#include <GDLAccess/EOAdaptor.h>
+#include <GDLAccess/EOAdaptorContext.h>
+#include <GDLAccess/EOAdaptorChannel.h>
 #include "common.h"
 
 @implementation OCSChannelManager
 
+static BOOL debugOn = YES;
+
++ (NSString *)adaptorNameForURLScheme:(NSString *)_scheme {
+  // TODO: map scheme to adaptors (eg 'postgresql://' to PostgreSQL72
+  return @"PostgreSQL72";
+}
+
++ (id)defaultChannelManager {
+  static OCSChannelManager *cm = nil;
+  if (cm == nil)
+    cm = [[self alloc] init];
+  return cm;
+}
+
+- (id)init {
+  if ((self = [super init])) {
+    self->urlToAdaptor = [[NSMutableDictionary alloc] initWithCapacity:4];
+  }
+  return self;
+}
+
 - (void)dealloc {
+  [self->urlToAdaptor release];
   [super dealloc];
 }
 
+/* DB key */
+
+- (NSString *)databaseKeyForURL:(NSURL *)_url {
+  /*
+    We need to build a proper key that omits passwords and URL path components
+    which are not required.
+  */
+  NSString *key;
+  
+  key = [NSString stringWithFormat:@"%@\n%@\n%@\n%@",
+                 [_url host], [_url port],
+                 [_url user], [_url ocsDatabaseName]];
+  return key;
+}
+
+/* adaptors */
+
+- (NSDictionary *)connectionDictionaryForURL:(NSURL *)_url {
+  [self debugWithFormat:@"build connection dictionary for URL: %@", _url];
+  return nil;
+}
+
+- (EOAdaptor *)adaptorForURL:(NSURL *)_url {
+  EOAdaptor    *adaptor;
+  NSString     *adaptorName;
+  NSString     *key;
+  NSDictionary *condict;
+  
+  if (_url == nil)
+    return nil;
+  if ((key = [self databaseKeyForURL:_url]) == nil)
+    return nil;
+  if ((adaptor = [self->urlToAdaptor objectForKey:key]) != nil) {
+    [self debugWithFormat:@"using cached adaptor: %@", adaptor];
+    return adaptor; /* cached :-) */
+  }
+  
+  [self debugWithFormat:@"creating new adaptor for URL: %@", _url];
+  
+  adaptorName = [[self class] adaptorNameForURLScheme:[_url scheme]];
+  if ([adaptorName length] == 0) {
+    [self logWithFormat:@"ERROR: cannot handle URL: %@", _url];
+    return nil;
+  }
+  
+  condict = [self connectionDictionaryForURL:_url];
+  
+  if ((adaptor = [EOAdaptor adaptorWithName:adaptorName]) == nil) {
+    [self logWithFormat:@"ERROR: did not find adaptor '%@' for URL: %@", 
+           adaptorName, _url];
+    return nil;
+  }
+  
+  [adaptor setConnectionDictionary:condict];
+  [self->urlToAdaptor setObject:adaptor forKey:key];
+  return adaptor;
+}
+
+/* channels */
+
+- (EOAdaptorChannel *)_createChannelForURL:(NSURL *)_url {
+  EOAdaptor        *adaptor;
+  EOAdaptorContext *adContext;
+  EOAdaptorChannel *adChannel;
+  
+  if ((adaptor = [self adaptorForURL:_url]) == nil)
+    return nil;
+  
+  if ((adContext = [adaptor createAdaptorContext]) == nil) {
+    [self logWithFormat:@"ERROR: could not create adaptor context!"];
+    return nil;
+  }
+  if ((adChannel = [adContext createAdaptorChannel]) == nil) {
+    [self logWithFormat:@"ERROR: could not create adaptor channel!"];
+    return nil;
+  }
+  return adChannel;
+}
+
+- (EOAdaptorChannel *)acquireOpenChannelForURL:(NSURL *)_url {
+  // TODO: naive implementation, add pooling!
+  EOAdaptorChannel *channel;
+  
+  if ((channel = [self _createChannelForURL:_url]) == nil)
+    return channel;
+  
+  if ([channel isOpen])
+    return [channel retain];
+  
+  if (![channel openChannel]) {
+    [self logWithFormat:@"could not open channel %@ for URL: %@",
+           channel, _url];
+    return nil;
+  }
+  
+  return [channel retain];
+}
+- (void)releaseChannel:(EOAdaptorChannel *)_channel {
+  // TODO: naive implementation, add pooling!
+  if ([_channel isOpen])
+    [_channel closeChannel];
+  
+  [_channel release];
+}
+
+/* debugging */
+
+- (BOOL)isDebuggingEnabled {
+  return debugOn;
+}
+
+/* description */
+
+- (NSString *)description {
+  NSMutableString *ms;
+
+  ms = [NSMutableString stringWithCapacity:256];
+  [ms appendFormat:@"<0x%08X[%@]:", self, NSStringFromClass([self class])];
+  
+  [ms appendFormat:@" #adaptors=%d", [self->urlToAdaptor count]];
+  
+  [ms appendString:@">"];
+  return ms;
+}
+
 @end /* OCSChannelManager */
index c40d05c5f1d959bbe5a6cd1d930e39b61e7f5fff..8caf34ca313b089026ec9f6566a1bc830e7be0ca 100644 (file)
 
 #import <Foundation/NSObject.h>
 
+/*
+  OCSContext
+  
+  Context passed to all operations.
+*/
+
 @interface OCSContext : NSObject
 {
 }
index 1af36e9aa3961a4968ee8a5ff733bac669d21649..ee7fed1d9233d4d3e9dd344644f4a4d237b24e7e 100644 (file)
 
 #import <Foundation/NSObject.h>
 
+/*
+  OCSFolderManager
+  
+  Objects of this class manage the "folder_info" table, they manage the
+  model and manage the tables required for a folder.
+*/
+
+@class NSURL;
+
 @interface OCSFolderManager : NSObject
 {
+  NSURL *folderInfoLocation;
 }
 
+- (id)initWithFolderInfoLocation:(NSURL *)_url;
+
+/* accessors */
+
+- (NSURL *)folderInfoLocation;
+
 @end
 
 #endif /* __OGoContentStore_OCSFolderManager_H__ */
index 5aefadaa6ba6b4a278cec6027dca620e36482d8c..e0637e88e34d861e6f6fe764c32cfbfd781c2a0f 100644 (file)
 
 @implementation OCSFolderManager
 
+- (id)initWithFolderInfoLocation:(NSURL *)_url {
+  if (_url == nil) {
+    [self logWithFormat:@"ERROR: missing folder info url!"];
+    [self release];
+    return nil;
+  }
+  if ((self = [super init])) {
+    self->folderInfoLocation = [_url retain];
+  }
+  return self;
+}
+
 - (void)dealloc {
+  [self->folderInfoLocation release];
   [super dealloc];
 }
 
+/* accessors */
+
+- (NSURL *)folderInfoLocation {
+  return self->folderInfoLocation;
+}
+
 @end /* OCSFolderManager */
index f723280b72e1d36dd492e585423f69a4482bf5be..edfa42861b3e74c056affabfa4e42c5ffff43143 100644 (file)
@@ -21,5 +21,6 @@
 // $Id$
 
 #import <Foundation/Foundation.h>
+#import <Foundation/NSURL.h>
 
 #include <NGExtensions/NGExtensions.h>