]> err.no Git - sope/blob - sope-gdl1/GDLAccess/EOGenericRecord.m
fixed bug in GDL adaptor lookup
[sope] / sope-gdl1 / GDLAccess / EOGenericRecord.m
1 /* 
2    EOGenericRecord.m
3
4    Copyright (C) 1996 Free Software Foundation, Inc.
5
6    Author: Mircea Oancea <mircea@jupiter.elcom.pub.ro>
7    Date: 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
27 #include <stdio.h>
28 #import <Foundation/NSDictionary.h>
29 #import <Foundation/NSMapTable.h>
30 #import <Foundation/NSArray.h>
31 #import "common.h"
32 #import "EOEntity.h"
33 #import "EOGenericRecord.h"
34 #import "EODatabase.h"
35 #import <GDLAccess/EOFault.h>
36 #import <EOControl/EOClassDescription.h>
37
38 @interface EOClassDescription(ClassDesc)
39 /* TODO: check, whether this can be removed */
40 + (NSClassDescription *)classDescriptionForEntityName:(NSString *)_entityName;
41 @end
42
43 @implementation EOGenericRecord(EOAccess)
44
45 - (id)initWithPrimaryKey:(NSDictionary *)_key entity:(EOEntity *)_entity {
46   /* TODO: is this method ever used? Maybe remove */
47   EOClassDescription *cd;
48   NSEnumerator *e;
49   NSString     *key;
50   
51   if (_entity == nil) {
52     AUTORELEASE(self);
53     NSLog(@"WARNING: tried to create generic record with <nil> entity !");
54     return nil;
55   }
56   
57   cd = (id)[EOClassDescription classDescriptionForEntityName:[_entity name]];
58 #if DEBUG
59   NSAssert1(cd, @"did not find class description for entity %@", _entity);
60 #endif
61   
62   self = [self initWithEditingContext:nil
63                classDescription:cd
64                globalID:nil];
65   
66   e = [_key keyEnumerator];
67
68   while ((key = [e nextObject]))
69     [self setObject:[_key objectForKey:key] forKey:key];
70   
71   return self;
72 }
73
74 - (void)_letDatabasesForget {
75   [EODatabase forgetObject:self];
76 }
77
78 /* model */
79
80 - (EOEntity *)entity {
81   return [(EOEntityClassDescription *)[self classDescription] entity];
82 }
83
84 @end /* EOGenericRecord(EOAccess) */