]> err.no Git - scalable-opengroupware.org/blob - Misc/dbd/DDatabaseManager.m
e9950288cf19699bbe71c1df8af6d167cf8a56b5
[scalable-opengroupware.org] / Misc / dbd / DDatabaseManager.m
1 // $Id$
2
3 #include <NGObjWeb/SoComponent.h>
4
5 @class EOAdaptorChannel;
6
7 @interface DDatabaseManager : SoComponent
8 {
9   EOAdaptorChannel *channel;
10   NSArray *databaseNames;
11   id item;
12 }
13
14 @end
15
16 #include "DSoHost.h"
17 #include "DSoDatabaseManager.h"
18 #include "common.h"
19
20 @interface EOAdaptorChannel(ModelFetching)
21 - (NSArray *)describeDatabaseNames;
22 @end
23
24 @implementation DDatabaseManager
25
26 - (void)dealloc {
27   if ([self->channel isOpen])
28     [self->channel closeChannel];
29   [self->channel release];
30   
31   [self->databaseNames release];
32   [self->item          release];
33   [super dealloc];
34 }
35
36 /* notifications */
37
38 - (void)sleep {
39   if ([self->channel isOpen])
40     [self->channel closeChannel];
41   
42   [super sleep];
43 }
44
45 /* DB things */
46
47 - (EOAdaptor *)adaptor {
48   return [[(DSoDatabaseManager *)[self clientObject] 
49                                  host] adaptorInContext:[self context]];
50 }
51
52 - (EOAdaptorChannel *)channel {
53   EOAdaptorContext *ctx;
54   
55   if (self->channel)
56     return self->channel;
57
58   ctx = [[self adaptor] createAdaptorContext];
59   self->channel = [[ctx createAdaptorChannel] retain];
60   if (![self->channel openChannel]) {
61     [self->channel release];
62     self->channel = nil;
63   }
64
65   return self->channel;
66 }
67
68 /* accessors */
69
70 - (void)setItem:(id)_item {
71   ASSIGN(self->item, _item);
72 }
73 - (id)item {
74   return self->item;
75 }
76
77 - (NSArray *)databaseNames {
78   if (self->databaseNames == nil)
79     self->databaseNames = [[[self channel] describeDatabaseNames] copy];
80   return self->databaseNames;
81 }
82
83 - (NSString *)dbLink {
84   // this suxx, a) we need to write code, b) we need to attach the / manually
85   return [[self item] stringByAppendingString:@"/"];
86 }
87
88 @end /* DDatabaseManager */