4 Copyright (C) 1996 Free Software Foundation, Inc.
6 Author: Ovidiu Predescu <ovidiu@bx.logicnet.ro>
9 This file is part of the GNUstep Database Library.
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.
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.
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.
27 #ifndef __EOEntity_h__
28 #define __EOEntity_h__
30 #import <Foundation/NSString.h>
32 @class EOModel, EOAttribute, EORelationship;
33 @class EOSQLQualifier, EOExpressionArray;
34 @class NSMutableDictionary;
36 @interface EOEntity : NSObject
40 NSString *externalName;
41 NSString *externalQuery;
42 NSDictionary *userDictionary;
43 NSArray *primaryKeyAttributeNames; /* sorted array of names */
44 NSArray *attributesNamesUsedForInsert;
45 NSArray *classPropertyNames;
47 /* Garbage collectable objects */
48 EOModel *model; /* non-retained */
49 EOSQLQualifier *qualifier;
51 NSMutableDictionary *attributesByName;
52 NSArray *relationships;
53 NSMutableDictionary *relationshipsByName; // name/EORelationship
54 NSArray *primaryKeyAttributes;
55 NSArray *classProperties; // EOAttribute/EORelationship
56 NSArray *attributesUsedForLocking;
58 /* Cached properties */
59 NSArray *attributesUsedForInsert; // cache from classProperties
60 NSArray *attributesUsedForFetch; // cache from classProperties
61 NSArray *relationsUsedForFetch; // cache from classProperties
65 BOOL createsMutableObjects:1;
66 BOOL isPropertiesCacheValid:1;
70 /* Initializing instances */
71 - (id)initWithName:(NSString *)name;
73 /* Accessing the name */
75 - (BOOL)setName:(NSString *)name;
76 + (BOOL)isValidName:(NSString *)name;
78 /* Accessing the model */
79 - (void)setModel:(EOModel *)model;
84 /* Getting the qualifier */
85 - (EOSQLQualifier *)qualifier;
87 /* Accessing attributes */
88 - (BOOL)addAttribute:(EOAttribute *)attribute;
89 - (void)removeAttributeNamed:(NSString *)name;
90 - (EOAttribute *)attributeNamed:(NSString *)attributeName;
91 - (NSArray *)attributes;
93 /* Accessing relationships */
94 - (BOOL)addRelationship:(EORelationship *)relationship;
95 - (void)removeRelationshipNamed:(NSString *)name;
96 - (EORelationship *)relationshipNamed:(NSString *)relationshipName;
97 - (NSArray *)relationships;
99 /* Accessing primary key attributes */
100 - (BOOL)setPrimaryKeyAttributes:(NSArray *)keys;
101 - (NSArray *)primaryKeyAttributes;
102 - (NSArray *)primaryKeyAttributeNames;
103 - (BOOL)isValidPrimaryKeyAttribute:(EOAttribute *)anAttribute;
105 /* Getting primary keys and snapshot for row */
106 - (NSDictionary *)primaryKeyForRow:(NSDictionary *)row;
107 - (NSDictionary *)snapshotForRow:(NSDictionary *)aRow;
109 /* Getting attributes used for fetch/insert/update operations */
110 - (NSArray *)attributesUsedForInsert;
111 - (NSArray *)attributesUsedForFetch;
112 - (NSArray *)relationsUsedForFetch;
113 - (NSArray *)attributesNamesUsedForInsert;
115 /* Accessing class properties */
116 - (BOOL)setClassProperties:(NSArray *)properties;
117 - (NSArray *)classProperties;
118 - (NSArray *)classPropertyNames;
119 - (BOOL)isValidClassProperty:(id)aProp;
120 - (id)propertyNamed:(NSString *)name;
121 - (NSArray *)relationshipsNamed:(NSString *)_relationshipPath;
123 /* Accessing locking attributes */
124 - (BOOL)setAttributesUsedForLocking:(NSArray *)attributes;
125 - (NSArray *)attributesUsedForLocking;
126 - (BOOL)isValidAttributeUsedForLocking:(EOAttribute *)anAttribute;
128 /* Accessing the enterprise object class */
129 - (void)setClassName:(NSString *)name;
130 - (NSString *)className;
132 /* Accessing external information */
133 - (void)setExternalName:(NSString *)name;
134 - (NSString *)externalName;
136 /* Accessing the external query */
137 - (void)setExternalQuery:(NSString *)query;
138 - (NSString *)externalQuery;
140 /* Accessing read-only status */
141 - (void)setReadOnly:(BOOL)flag;
144 /* Accessing the user dictionary */
145 - (void)setUserDictionary:(NSDictionary *)dictionary;
146 - (NSDictionary *)userDictionary;
148 - (BOOL)referencesProperty:property;
153 @interface EOEntity (EOEntityPrivate)
155 + (EOEntity *)entityFromPropertyList:(id)propertyList model:(EOModel *)model;
156 - (void)replaceStringsWithObjects;
159 - (void)setCreateMutableObjects:(BOOL)flag;
160 - (BOOL)createsMutableObjects;
162 - (void)validatePropertiesCache;
163 - (void)invalidatePropertiesCache;
167 @interface EOEntity(ValuesConversion)
169 - (NSDictionary *)convertValuesToModel:(NSDictionary *)aRow;
171 @end /* EOAttribute (ValuesConversion) */
173 @class EOGlobalID, EOFetchSpecification;
175 @interface EOEntity(EOF2Additions)
177 - (BOOL)isAbstractEntity;
181 - (EOGlobalID *)globalIDForRow:(NSDictionary *)_row;
182 - (BOOL)isPrimaryKeyValidInObject:(id)_object;
184 /* refs to other models */
186 - (NSArray *)externalModelsReferenced;
190 - (EOFetchSpecification *)fetchSpecificationNamed:(NSString *)_name;
191 - (NSArray *)fetchSpecificationNames;
195 - (void)beautifyName;
199 @class NSMutableDictionary;
201 @interface EOEntity(PropertyListCoding)
203 - (void)encodeIntoPropertyList:(NSMutableDictionary *)_plist;
207 #import <EOControl/EOClassDescription.h>
209 @interface EOEntityClassDescription : EOClassDescription
214 - (id)initWithEntity:(EOEntity *)_entity;
215 - (EOEntity *)entity;
219 #endif /* __EOEntity_h__ */