home *** CD-ROM | disk | FTP | other *** search
- // EOAttribute.h
- // Copyright (c) 1994, NeXT Computer, Inc. All rights reserved.
-
- #import "EOExpressionArray.h"
-
- #import <foundation/NSArray.h>
- #import <foundation/NSData.h>
- #import <foundation/NSDictionary.h>
- #import <foundation/NSObject.h>
- #import <foundation/NSString.h>
- #import <foundation/NSDate.h>
-
- @class EOEntity;
-
-
- // An EOAttribute represents a column, field or property in a database, and
- // associates an internal name with an external name or expression by which
- // the property is known to the database. An EOAttribute also maintains type
- // information required for binding to the instance variables of objects.
- //
- // FLATTENED AND DERIVED ATTRIBUTES
- //
- // An attribute may be flattened by setting its external name to a model
- // path. For example, if a Book entity has the relationship toAuthor and
- // the Author entity has the attribute name, you can assign the author's
- // name as an attribute of your Book EOEntity by creating an EOAttribute
- // with an external name of "toAuthor.name".
- //
- // A derived attribute is an attribute that doesn't correspond to a single
- // column or field in the database. A derived attribute is usually created by
- // simply modifying a non-derived attribute; for example, by adding a certain
- // amount or appending a string. Examples of derived attribute external
- // names are: "commision / 2", "salary + overtime".
-
-
- @interface EOAttribute:NSObject
- {
- NSString *_name;
- EOEntity *_entity;
- NSString *_columnName;
- EOExpressionArray *_definitionArray;
- NSString *_externalType;
- NSString *_valueType;
- const char *_valueClassName;
- NSString *_selectFormat;
- NSString *_updateFormat;
- NSString *_insertFormat;
- NSString *_calendarFormat;
- NSTimeZone *_serverTimeZone;
- NSTimeZone *_clientTimeZone;
- NSDictionary *_userDictionary;
- id _realSourceAttribute;
- struct {
- unsigned int isReadOnly:1;
- unsigned int extraRefCount:31;
- } _flags;
- }
-
- + (BOOL)isValidName:(NSString *)name;
- // Returns YES if name is a legal attribute name and NO otherwise.
-
- - initWithName:(NSString *)name;
- // Initializes a newly allocated EOAttribute with name as its internal
- // name. The EOAttribute needs to have more information set before it's
- // usable. Returns self.
-
- - (NSString *)name;
- // Returns the internal name of the attribute.
-
- - (EOEntity *)entity;
- // Returns the entity that owns the attribute.
-
- - (NSString *)externalType;
- // Returns the attribute's type as understood by the database.
-
- // The following two methods are closely related. Only one can be set
- // at any given time. Invoking either of these methods causes the other
- // value to be set to nil.
- - (NSString *)columnName;
- // Returns the name of the column in the database that corresponds to this
- // attribute.
-
- - (NSString *)definition;
- // Returns the definition of this attribute. The definition is used to
- // describe flattened and derived attributes. The DBMS specific language
- // generator will make extensive use of this value.
-
- - (BOOL)isFlattened;
- // Returns YES if the attribute is flattened, NO otherwise.
-
- - (BOOL)isDerived;
- // Returns YES if the attribute doesn't correspond exactly to one column
- // in a table (for example, "attrName + 1"), NO otherwise.
-
- - (BOOL)isReadOnly;
- // Returns YES if the value of the attribute can't be modified, NO if
- // it can.
-
- - (const char *)valueClassName;
- // Returns the name of the class for custom-value types. If a column
- // from the database is to be represented by an NXImage, for example,
- // this returns "NXImage".
-
- - (NSString *)valueType;
- // A format for custom-value types, such as "TIFF" or "RTF".
-
- - (NSString *)insertFormat;
- - (NSString *)updateFormat;
- - (NSString *)selectFormat;
- // These methods return format strings for building expressions of the
- // appropriate type to contain the value of the attribute.
-
- - (NSDictionary *)userDictionary;
- // Returns a dictionary of user data. You can use this to store any
- // auxiliary information.
-
- - (BOOL)referencesProperty:property;
- // Returns YES if property is used in the attribute's external name,
- // NO otherwise.
-
- @end
-
-
- @interface EOAttribute(EOAttributeEditing)
-
- - (BOOL)setName:(NSString *)name;
- // Sets the attribute's name. Returns YES if successful, NO if name is
- // already in use by another attribute or relationship of the same entity.
-
- - (BOOL)setReadOnly:(BOOL)yn;
- // Sets whether the value of the attribute can be modified.
-
- // The following two methods are closely related. Only one can be set
- // at any given time. Invoking either of these methods causes the other
- // value to be set to nil.
- - (void)setColumnName:(NSString *)columnName;
- // Sets the name to a string which is the actual name of a column in
- // database. This method will cause the definition value of this
- // attribute to be set to nil.
-
- - (void)setDefinition:(NSString *)definition;
- // Sets the definition of the attribute. This method will cause the value
- // for columnName to be set to nil. The attribute's entity must have
- // been set either by adding the attribute to an entity or by explicitly
- // invoking the attributes setEntity: method. This method will not
- // function correctly if the attribute's entity has not been set.
-
- - (void)setEntity:(EOEntity *)entity;
- // Sets the entity of the attribute. If the attribute is currently owned
- // by a different entity, this method will remove the attribute from that
- // entity. This method does not cause the attribute to be added to the new
- // entity. EOEntity's addAttribute: method invokes this method.
-
- - (BOOL)setExternalType:(NSString *)type;
- // Sets the type as recognized by the database server.
-
- - (void)setValueType:(NSString *)type;
- // Sets the format for custom-value types, such as "TIFF" or "RTF".
-
- - (void)setValueClassName:(const char *)name;
- // Sets the class name for values of this attribute. If values are
- // instances of NXImage, you would send:
- // [myAttribute setValueClassName:"NXImage"];
-
-
- // The strings supplied to the three following methods are used to generate
- // the attribute's expression value for insert, update and select statements.
- // In the select string, %a is replaced by the attribute's external name; in
- // the insert and update strings, %v is replaced by its value.
-
-
- - (void)setInsertFormat:(NSString *)string;
- // Supplies a string used to format the value in insert expressions.
-
- - (void)setUpdateFormat:(NSString *)string;
- // Supplies a string used to format the value in update expressions.
-
- - (void)setSelectFormat:(NSString *)string;
- // Supplies a string used to format the value in select expressions.
-
- - (void)setUserDictionary:(NSDictionary *)dictionary;
- // Sets the dictionary of auxiliary data, which your application can use
- // for whatever it needs.
-
- @end
-
-
- @interface EOAttribute (NSDateSupport)
- + (NSString *)defaultCalendarFormat;
- // Returns a default date format. Can be used when the EOAttribute does
- // not have a dateFormat of it's own.
-
- - (void)setCalendarFormat: (NSString *)format;
- - (NSString *)calendarFormat;
- // Set/return the format that will be used when the NSDate object is
- // initialized.
-
- - (void)setServerTimeZone: (NSTimeZone *)tz;
- - (NSTimeZone *)serverTimeZone;
- // Set/return the implicit time zone of the dates provided by the database
- // server.
-
- - (void)setClientTimeZone: (NSTimeZone *)tz;
- - (NSTimeZone *)clientTimeZone;
- // Set/return the time zone that will be used when the date is told to
- // represent itself.
-
- @end
-