]> err.no Git - scalable-opengroupware.org/blob - Misc/dbd/DTable.m
bdd78a955c4821d11990c026cab09807861d0d1e
[scalable-opengroupware.org] / Misc / dbd / DTable.m
1 // $Id$
2
3 #include <NGObjWeb/SoComponent.h>
4
5 @class EOAdaptorChannel;
6
7 @interface DTable : SoComponent
8 {
9   EOAdaptorChannel *channel;
10   NSArray *attributes;
11   NSArray *columnNames;
12   id item;
13 }
14
15 @end
16
17 #include "DSoTable.h"
18 #include "common.h"
19
20 @implementation DTable
21
22 - (void)dealloc {
23   if ([self->channel isOpen])
24     [self->channel closeChannel];
25   [self->channel release];
26   
27   [self->attributes  release];
28   [self->columnNames release];
29   [self->item        release];
30   [super dealloc];
31 }
32
33 /* notifications */
34
35 - (void)sleep {
36   if ([self->channel isOpen])
37     [self->channel closeChannel];
38   
39   [super sleep];
40 }
41
42 /* DB things */
43
44 - (EOAdaptor *)adaptor {
45   return [(DSoTable *)[self clientObject] adaptorInContext:[self context]];
46 }
47
48 - (EOAdaptorChannel *)channel {
49   EOAdaptorContext *ctx;
50   
51   if (self->channel)
52     return self->channel;
53
54   ctx = [[self adaptor] createAdaptorContext];
55   self->channel = [[ctx createAdaptorChannel] retain];
56   if (![self->channel openChannel]) {
57     [self->channel release];
58     self->channel = nil;
59   }
60
61   return self->channel;
62 }
63
64 - (EOModel *)_describeModel {
65   NSArray *tableNames;
66   
67   tableNames = [NSArray arrayWithObject:[[self clientObject] tableName]];
68   return [[self channel] describeModelWithTableNames:tableNames];
69 }
70
71 /* accessors */
72
73 - (void)setItem:(id)_item {
74   ASSIGN(self->item, _item);
75 }
76 - (id)item {
77   return self->item;
78 }
79
80 - (NSArray *)attributes {
81   EOModel *model;
82
83   if (self->attributes)
84     return self->attributes;
85   
86   model            = [self _describeModel];
87   self->attributes = [[[[model entities] lastObject] attributes] retain];
88   return self->attributes;
89 }
90 - (NSArray *)columnNames {
91   if (self->columnNames)
92     return self->columnNames;
93   
94   self->columnNames = [[[self attributes] valueForKey:@"columnName"] copy];
95   return self->columnNames;
96 }
97
98 - (NSString *)columnLink {
99   return [[[self item] columnName] stringByAppendingString:@"/"];
100 }
101 - (NSString *)itemSlashLink {
102   // this suxx, a) we need to write code, b) we need to attach the / manually
103   return [[self item] stringByAppendingString:@"/"];
104 }
105
106 @end /* DTable */