From 3bba6ca6338c50e3ce1c83417d0112cc00e92189 Mon Sep 17 00:00:00 2001 From: helge Date: Thu, 17 Jun 2004 01:23:37 +0000 Subject: [PATCH] git-svn-id: http://svn.opengroupware.org/SOGo/trunk@46 d1b88da0-ebda-0310-925b-ed51d893ca5b --- dbd/DDatabase.m | 82 +++++++++++++++++++++++++++++++++++++ dbd/DDatabase.wox | 17 ++++++++ dbd/DDatabaseManager.m | 88 ++++++++++++++++++++++++++++++++++++++++ dbd/DDatabaseManager.wox | 19 +++++++++ dbd/DHostView.m | 6 ++- dbd/DSoDatabase.h | 4 ++ dbd/DSoDatabase.m | 27 ++++++++++++ dbd/DSoDatabaseManager.m | 5 ++- dbd/DSoObject.m | 11 +++++ dbd/DSoTable.h | 7 ++++ dbd/DSoTable.m | 17 ++++++++ dbd/GNUmakefile | 2 + dbd/README | 18 ++++++++ dbd/product.plist | 4 ++ 14 files changed, 304 insertions(+), 3 deletions(-) create mode 100644 dbd/DDatabase.m create mode 100644 dbd/DDatabase.wox create mode 100644 dbd/DDatabaseManager.m create mode 100644 dbd/DDatabaseManager.wox diff --git a/dbd/DDatabase.m b/dbd/DDatabase.m new file mode 100644 index 00000000..f184b3a1 --- /dev/null +++ b/dbd/DDatabase.m @@ -0,0 +1,82 @@ +// $Id$ + +#include + +@class EOAdaptorChannel; + +@interface DDatabase : SoComponent +{ + EOAdaptorChannel *channel; + NSArray *tableNames; + id item; +} + +@end + +#include "DSoDatabase.h" +#include "common.h" + +@implementation DDatabase + +- (void)dealloc { + if ([self->channel isOpen]) + [self->channel closeChannel]; + [self->channel release]; + + [self->tableNames release]; + [self->item release]; + [super dealloc]; +} + +/* notifications */ + +- (void)sleep { + if ([self->channel isOpen]) + [self->channel closeChannel]; + + [super sleep]; +} + +/* DB things */ + +- (EOAdaptor *)adaptor { + return [(DSoDatabase *)[self clientObject] adaptorInContext:[self context]]; +} + +- (EOAdaptorChannel *)channel { + EOAdaptorContext *ctx; + + if (self->channel) + return self->channel; + + ctx = [[self adaptor] createAdaptorContext]; + self->channel = [[ctx createAdaptorChannel] retain]; + if (![self->channel openChannel]) { + [self->channel release]; + self->channel = nil; + } + + return self->channel; +} + +/* accessors */ + +- (void)setItem:(id)_item { + ASSIGN(self->item, _item); +} +- (id)item { + return self->item; +} + +- (NSArray *)tableNames { + if (self->tableNames == nil) + self->tableNames = [[[self channel] describeTableNames] copy]; + return self->tableNames; +} + +- (NSString *)tabLink { + // this suxx, a) we need to write code, b) we need to attach the / manually + return [[self item] stringByAppendingString:@"/"]; +} + +@end /* DDatabase */ diff --git a/dbd/DDatabase.wox b/dbd/DDatabase.wox new file mode 100644 index 00000000..9a2a405f --- /dev/null +++ b/dbd/DDatabase.wox @@ -0,0 +1,17 @@ + + + +Host:
+Port:
+DB:
+ +

Tables

+ +
  • +
    + +
    diff --git a/dbd/DDatabaseManager.m b/dbd/DDatabaseManager.m new file mode 100644 index 00000000..e9950288 --- /dev/null +++ b/dbd/DDatabaseManager.m @@ -0,0 +1,88 @@ +// $Id$ + +#include + +@class EOAdaptorChannel; + +@interface DDatabaseManager : SoComponent +{ + EOAdaptorChannel *channel; + NSArray *databaseNames; + id item; +} + +@end + +#include "DSoHost.h" +#include "DSoDatabaseManager.h" +#include "common.h" + +@interface EOAdaptorChannel(ModelFetching) +- (NSArray *)describeDatabaseNames; +@end + +@implementation DDatabaseManager + +- (void)dealloc { + if ([self->channel isOpen]) + [self->channel closeChannel]; + [self->channel release]; + + [self->databaseNames release]; + [self->item release]; + [super dealloc]; +} + +/* notifications */ + +- (void)sleep { + if ([self->channel isOpen]) + [self->channel closeChannel]; + + [super sleep]; +} + +/* DB things */ + +- (EOAdaptor *)adaptor { + return [[(DSoDatabaseManager *)[self clientObject] + host] adaptorInContext:[self context]]; +} + +- (EOAdaptorChannel *)channel { + EOAdaptorContext *ctx; + + if (self->channel) + return self->channel; + + ctx = [[self adaptor] createAdaptorContext]; + self->channel = [[ctx createAdaptorChannel] retain]; + if (![self->channel openChannel]) { + [self->channel release]; + self->channel = nil; + } + + return self->channel; +} + +/* accessors */ + +- (void)setItem:(id)_item { + ASSIGN(self->item, _item); +} +- (id)item { + return self->item; +} + +- (NSArray *)databaseNames { + if (self->databaseNames == nil) + self->databaseNames = [[[self channel] describeDatabaseNames] copy]; + return self->databaseNames; +} + +- (NSString *)dbLink { + // this suxx, a) we need to write code, b) we need to attach the / manually + return [[self item] stringByAppendingString:@"/"]; +} + +@end /* DDatabaseManager */ diff --git a/dbd/DDatabaseManager.wox b/dbd/DDatabaseManager.wox new file mode 100644 index 00000000..16362b3d --- /dev/null +++ b/dbd/DDatabaseManager.wox @@ -0,0 +1,19 @@ + + + +Host:
    +Port:
    + +

    Databases

    + +
  • +
    + +
    +Users + +
    diff --git a/dbd/DHostView.m b/dbd/DHostView.m index 37698adf..ed6f1d9c 100644 --- a/dbd/DHostView.m +++ b/dbd/DHostView.m @@ -92,10 +92,12 @@ // Note: it suxx that we need to write code for that ... - (NSString *)dbLink { - return [@"Databases/" stringByAppendingString:[self item]]; + return [[@"Databases/" stringByAppendingString:[self item]] + stringByAppendingString:@"/"]; } - (NSString *)userLink { - return [@"Users/" stringByAppendingString:[self item]]; + return [[@"Users/" stringByAppendingString:[self item]] + stringByAppendingString:@"/"]; } @end /* DHostView */ diff --git a/dbd/DSoDatabase.h b/dbd/DSoDatabase.h index e7402e8f..48fc63bd 100644 --- a/dbd/DSoDatabase.h +++ b/dbd/DSoDatabase.h @@ -35,6 +35,10 @@ - (id)initWithHostName:(NSString *)_hostname port:(int)_port databaseName:(NSString *)_dbname; +/* support */ + +- (EOAdaptor *)adaptorInContext:(WOContext *)_ctx; + @end #endif /* __dbd_DSoDatabase_H__ */ diff --git a/dbd/DSoDatabase.m b/dbd/DSoDatabase.m index 8e82fa1c..0663657d 100644 --- a/dbd/DSoDatabase.m +++ b/dbd/DSoDatabase.m @@ -21,9 +21,13 @@ // $Id$ #include "DSoDatabase.h" +#include "DSoTable.h" #include "DSoAuthenticator.h" #include "common.h" +// TODO: PG databases do have an owner! +// TODO: PG databases have an ACL + @implementation DSoDatabase - (id)initWithHostName:(NSString *)_hostname port:(int)_port @@ -56,6 +60,13 @@ return self->databaseName; } +/* support */ + +- (EOAdaptor *)adaptorInContext:(WOContext *)_ctx { + return [self adaptorForHostName:[self hostName] port:[self port] + databaseName:[self databaseName] inContext:_ctx]; +} + /* authentication */ - (id)authenticatorInContext:(id)_ctx { @@ -63,4 +74,20 @@ port:[self port] databaseName:[self databaseName]]; } +/* name lookup */ + +- (id)lookupName:(NSString *)_key inContext:(id)_ctx acquire:(BOOL)_flag { + id obj; + + /* + Note: acquire:NO - otherwise acquired stuff will override the stuff + below! + */ + if ((obj = [super lookupName:_key inContext:_ctx acquire:NO])) + return obj; + + obj = [[DSoTable alloc] initWithName:_key inContainer:self]; + return [obj autorelease]; +} + @end /* DSoDatabase */ diff --git a/dbd/DSoDatabaseManager.m b/dbd/DSoDatabaseManager.m index ca789558..1529ba00 100644 --- a/dbd/DSoDatabaseManager.m +++ b/dbd/DSoDatabaseManager.m @@ -53,10 +53,13 @@ - (id)lookupName:(NSString *)_key inContext:(id)_ctx acquire:(BOOL)_flag { id obj; + /* + Note: acquire:NO - otherwise acquired stuff will override the stuff + below! + */ if ((obj = [super lookupName:_key inContext:_ctx acquire:NO])) return obj; - // TODO: create DSoDatabase object obj = [[DSoDatabase alloc] initWithHostName:[self->host hostName] port:[self->host port] databaseName:_key]; diff --git a/dbd/DSoObject.m b/dbd/DSoObject.m index f71d6d99..e6ea9297 100644 --- a/dbd/DSoObject.m +++ b/dbd/DSoObject.m @@ -100,4 +100,15 @@ } #endif +/* OSX hack */ + +- (id)valueForUndefinedKey:(NSString *)_key { + [self debugWithFormat:@"queried undefined key: '%@'", _key]; + return nil; +} + +- (BOOL)isCollection { + return YES; +} + @end /* DSoObject */ diff --git a/dbd/DSoTable.h b/dbd/DSoTable.h index 1ac86c03..7bfac922 100644 --- a/dbd/DSoTable.h +++ b/dbd/DSoTable.h @@ -25,10 +25,17 @@ #include "DSoObject.h" +@class NSString; +@class DSoDatabase; + @interface DSoTable : DSoObject { + DSoDatabase *database; + NSString *tableName; } +- (id)initWithName:(NSString *)_name inContainer:(id)_container; + @end #endif /* __dbd_DSoTable_H__ */ diff --git a/dbd/DSoTable.m b/dbd/DSoTable.m index d72fa3fc..99fabeb8 100644 --- a/dbd/DSoTable.m +++ b/dbd/DSoTable.m @@ -21,12 +21,29 @@ // $Id$ #include "DSoTable.h" +#include "DSoDatabase.h" #include "common.h" @implementation DSoTable +- (id)initWithName:(NSString *)_name inContainer:(id)_container { + if ((self = [super init])) { + self->tableName = [_name copy]; + self->database = [_container retain]; + } + return self; +} + - (void)dealloc { + [self->database release]; + [self->tableName release]; [super dealloc]; } +/* support */ + +- (EOAdaptor *)adaptorInContext:(WOContext *)_ctx { + return [self->database adaptorInContext:_ctx]; +} + @end /* DSoTable */ diff --git a/dbd/GNUmakefile b/dbd/GNUmakefile index a47d4d8a..8520dc67 100644 --- a/dbd/GNUmakefile +++ b/dbd/GNUmakefile @@ -22,6 +22,7 @@ dbd_OBJC_FILES += \ \ DHostView.m \ DDatabaseManager.m \ + DDatabase.m \ dbd_RESOURCE_FILES += \ Version \ @@ -32,6 +33,7 @@ dbd_RESOURCE_FILES += \ \ DHostView.wox \ DDatabaseManager.wox \ + DDatabase.wox \ dbd_WEBSERVER_RESOURCE_FILES += diff --git a/dbd/README b/dbd/README index 4e85a139..63ac658e 100644 --- a/dbd/README +++ b/dbd/README @@ -26,6 +26,11 @@ Class Hierarchy Tricks used =========== +- *always* remember that SOPE objects which are looked up in the traversal + process are conceptually *UI* objects, not datamodel objects (though this + might be done for simplistic applications) + - the idea is: the URL is UI + - small hack in MainPage.m to make a redirect to a "valid" WO URL if the request-handler-key is missing - should be made by SOPE itself? @@ -72,6 +77,8 @@ Tricks used - in theory SOPE should make a redirect to the default method, not sure why this isn't happening - ZideStore always makes such a redirect? + - maybe any folderish object when being at the end of a traversal stack + should check that? - acquisition - if you override -lookupName:inContext:acquire:, you should probably @@ -81,3 +88,14 @@ Tricks used - note that acquisition is also done on the traversal path! if the lookup returns nil on an URL path being traversed, URL acquisition will occure (except on non-acquisition protocols like WebDAV) + +- baseURL + - calculation of base URL requires you to either override -baseURLInContext: + or implement -container and -nameInContainer + +- enabling WebDAV + - implemented -isCollection in DSoObject + - per default the baseURL is broken - you need to ensure that it returns + a proper value, see above + - if the baseURL doesn't match the requested WebDAV URL, we run into + problems, maybe need to fix something in the SOPE WebDAV layer here diff --git a/dbd/product.plist b/dbd/product.plist index 3ff18ae9..fa259229 100644 --- a/dbd/product.plist +++ b/dbd/product.plist @@ -57,6 +57,10 @@ DSoDatabase = { superclass = "DSoObject"; methods = { + "index" = { + protectedBy = "View"; + pageName = "DDatabase"; + }; }; }; DSoDatabaseManager = { -- 2.39.5