]> err.no Git - sope/blob - sope-gdl1/GDLAccess/EOAdaptorChannel+Attributes.m
fixed bug in GDL adaptor lookup
[sope] / sope-gdl1 / GDLAccess / EOAdaptorChannel+Attributes.m
1 /* 
2    EOAdaptorChannel.m
3
4    Copyright (C) 1996 Free Software Foundation, Inc.
5
6    Author: Ovidiu Predescu <ovidiu@bx.logicnet.ro>
7    Date: October 1996
8
9    This file is part of the GNUstep Database Library.
10
11    This library is free software; you can redistribute it and/or
12    modify it under the terms of the GNU Library General Public
13    License as published by the Free Software Foundation; either
14    version 2 of the License, or (at your option) any later version.
15
16    This library is distributed in the hope that it will be useful,
17    but WITHOUT ANY WARRANTY; without even the implied warranty of
18    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19    Library General Public License for more details.
20
21    You should have received a copy of the GNU Library General Public
22    License along with this library; see the file COPYING.LIB.
23    If not, write to the Free Software Foundation,
24    59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 */
26 // $Id: EOAdaptorChannel+Attributes.m 1 2004-08-20 10:38:46Z znek $
27
28 #import "common.h"
29 #import "EOAdaptorChannel+Attributes.h"
30 #import "EOAdaptorContext.h"
31 #import "EOEntity.h"
32 #import "EOAdaptor.h"
33 #import "EOModel.h"
34
35 @implementation EOAdaptorChannel(Attributes)
36
37 - (EOEntity *)_entityForTableName:(NSString *)_tableName {
38   EOModel  *model  = nil;
39   EOEntity *entity = nil;
40   
41   if (_tableName == nil || [_tableName length] == 0)
42     return nil;
43
44   model = [[self->adaptorContext adaptor] model];
45
46   if ((entity = [model entityNamed:_tableName]) == nil) {
47     NSEnumerator *enumerator = nil;
48     enumerator = [[model entities] objectEnumerator];
49     while ((entity = [enumerator nextObject])) {
50       if ([[entity externalName] isEqualToString:_tableName])
51         break;
52     }
53   }
54   if (entity == nil) {
55     model = [self describeModelWithTableNames:
56                   [NSArray arrayWithObject:_tableName]];
57
58     if ((entity = [model entityNamed:_tableName]) == nil) {
59       NSEnumerator *enumerator = nil;
60       enumerator = [[model entities] objectEnumerator];
61       while ((entity = [enumerator nextObject])) {
62         if ([[entity externalName] isEqualToString:_tableName])
63           break;
64       }
65     }
66   }
67   return entity;
68 }
69
70 - (NSArray *)attributesForTableName:(NSString *)_tableName {
71   return [[self _entityForTableName:_tableName] attributes];
72 }
73
74 - (NSArray *)primaryKeyAttributesForTableName:(NSString *)_tableName {
75   return [[self _entityForTableName:_tableName] primaryKeyAttributes];  
76 }
77
78 @end /* EOAdaptorChannel(Attributes) */