home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2J (Developer) / os42jdev.iso / NextDeveloper / OpenStepConversion / 3.3Headers / eoaccess / EOAttribute.h < prev    next >
Encoding:
Text File  |  1994-11-19  |  7.5 KB  |  209 lines

  1. // EOAttribute.h
  2. // Copyright (c) 1994, NeXT Computer, Inc. All rights reserved. 
  3.  
  4. #import    "EOExpressionArray.h"
  5.  
  6. #import <foundation/NSArray.h>
  7. #import <foundation/NSData.h>
  8. #import <foundation/NSDictionary.h>
  9. #import <foundation/NSObject.h>
  10. #import <foundation/NSString.h>
  11. #import <foundation/NSDate.h>
  12.  
  13. @class EOEntity;
  14.  
  15.  
  16. // An EOAttribute represents a column, field or property in a database, and
  17. // associates an internal name with an external name or expression by which
  18. // the property is known to the database.  An EOAttribute also maintains type
  19. // information required for binding to the instance variables of objects.
  20. //
  21. // FLATTENED AND DERIVED ATTRIBUTES
  22. //
  23. // An attribute may be flattened by setting its external name to a model
  24. // path. For example, if a Book entity has the relationship toAuthor and
  25. // the Author entity has the attribute name, you can assign the author's
  26. // name as an attribute of your Book EOEntity by creating an EOAttribute
  27. // with an external name of "toAuthor.name".
  28. //
  29. // A derived attribute is an attribute that doesn't correspond to a single
  30. // column or field in the database. A derived attribute is usually created by
  31. // simply modifying a non-derived attribute; for example, by adding a certain
  32. // amount or appending a string. Examples of derived attribute external
  33. // names are: "commision / 2", "salary + overtime".
  34.  
  35.  
  36. @interface EOAttribute:NSObject
  37. {
  38.     NSString *_name;
  39.     EOEntity *_entity;
  40.     NSString *_columnName;
  41.     EOExpressionArray *_definitionArray;
  42.     NSString *_externalType;
  43.     NSString *_valueType;
  44.     const char *_valueClassName;
  45.     NSString *_selectFormat;
  46.     NSString *_updateFormat;
  47.     NSString *_insertFormat;
  48.     NSString *_calendarFormat;
  49.     NSTimeZone *_serverTimeZone;
  50.     NSTimeZone *_clientTimeZone;
  51.     NSDictionary *_userDictionary;
  52.     id _realSourceAttribute;
  53.     struct {
  54.     unsigned int isReadOnly:1;
  55.     unsigned int extraRefCount:31;
  56.     } _flags;
  57. }
  58.  
  59. + (BOOL)isValidName:(NSString *)name;
  60.     // Returns YES if name is a legal attribute name and NO otherwise.
  61.     
  62. - initWithName:(NSString *)name;
  63.     // Initializes a newly allocated EOAttribute with name as its internal
  64.     // name.  The EOAttribute needs to have more information set before it's
  65.     // usable.  Returns self.
  66.  
  67. - (NSString *)name;
  68.     // Returns the internal name of the attribute.
  69.  
  70. - (EOEntity *)entity;
  71.     // Returns the entity that owns the attribute.
  72.  
  73. - (NSString *)externalType;
  74.     // Returns the attribute's type as understood by the database.
  75.  
  76. // The following two methods are closely related. Only one can be set
  77. // at any given time. Invoking either of these methods causes the other
  78. // value to be set to nil.
  79. - (NSString *)columnName;
  80.     // Returns the name of the column in the database that corresponds to this
  81.     // attribute.
  82.  
  83. - (NSString *)definition;
  84.     // Returns the definition of this attribute. The definition is used to
  85.     // describe flattened and derived attributes. The DBMS specific language
  86.     // generator will make extensive use of this value.
  87.  
  88. - (BOOL)isFlattened;
  89.     // Returns YES if the attribute is flattened, NO otherwise.
  90.  
  91. - (BOOL)isDerived;
  92.     // Returns YES if the attribute doesn't correspond exactly to one column
  93.     // in a table (for example, "attrName + 1"), NO otherwise.
  94.  
  95. - (BOOL)isReadOnly;
  96.     // Returns YES if the value of the attribute can't be modified, NO if
  97.     // it can.
  98.  
  99. - (const char *)valueClassName;
  100.     // Returns the name of the class for custom-value types. If a column
  101.     // from the database is to be represented by an NXImage, for example,
  102.     // this returns "NXImage".
  103.  
  104. - (NSString *)valueType;
  105.     // A format for custom-value types, such as "TIFF" or "RTF".
  106.  
  107. - (NSString *)insertFormat;
  108. - (NSString *)updateFormat;
  109. - (NSString *)selectFormat;
  110.     // These methods return format strings for building expressions of the
  111.     // appropriate type to contain the value of the attribute.
  112.  
  113. - (NSDictionary *)userDictionary;
  114.     // Returns a dictionary of user data. You can use this to store any
  115.     // auxiliary information.
  116.  
  117. - (BOOL)referencesProperty:property;
  118.     // Returns YES if property is used in the attribute's external name,
  119.     // NO otherwise.
  120.  
  121. @end
  122.  
  123.  
  124. @interface EOAttribute(EOAttributeEditing)
  125.  
  126. - (BOOL)setName:(NSString *)name;
  127.     // Sets the attribute's name.  Returns YES if successful, NO if name is
  128.     // already in use by another attribute or relationship of the same entity.
  129.  
  130. - (BOOL)setReadOnly:(BOOL)yn;
  131.     // Sets whether the value of the attribute can be modified.
  132.  
  133. // The following two methods are closely related. Only one can be set
  134. // at any given time.  Invoking either of these methods causes the other
  135. // value to be set to nil.
  136. - (void)setColumnName:(NSString *)columnName;
  137.     // Sets the name to a string which is the actual name of a column in
  138.     // database.  This method will cause the definition value of this 
  139.     // attribute to be set to nil.
  140.  
  141. - (void)setDefinition:(NSString *)definition;
  142.     // Sets the definition of the attribute. This method will cause the value
  143.     // for columnName to be set to nil. The attribute's entity must have
  144.     // been set either by adding the attribute to an entity or by explicitly
  145.     // invoking the attributes setEntity: method. This method will not
  146.     // function correctly if the attribute's entity has not been set.
  147.  
  148. - (void)setEntity:(EOEntity *)entity;
  149.     // Sets the entity of the attribute. If the attribute is currently owned
  150.     // by a different entity, this method will remove the attribute from that
  151.     // entity. This method does not cause the attribute to be added to the new
  152.     // entity. EOEntity's addAttribute: method invokes this method.
  153.  
  154. - (BOOL)setExternalType:(NSString *)type;
  155.     // Sets the type as recognized by the database server.
  156.  
  157. - (void)setValueType:(NSString *)type;
  158.     // Sets the format for custom-value types, such as "TIFF" or "RTF".
  159.  
  160. - (void)setValueClassName:(const char *)name;
  161.     // Sets the class name for values of this attribute. If values are
  162.     // instances of NXImage, you would send:
  163.     //     [myAttribute setValueClassName:"NXImage"];
  164.  
  165.  
  166. // The strings supplied to the three following methods are used to generate
  167. // the attribute's expression value for insert, update and select statements.
  168. // In the select string, %a is replaced by the attribute's external name; in
  169. // the insert and update strings, %v is replaced by its value.
  170.  
  171.  
  172. - (void)setInsertFormat:(NSString *)string;
  173.     // Supplies a string used to format the value in insert expressions.
  174.  
  175. - (void)setUpdateFormat:(NSString *)string;
  176.     // Supplies a string used to format the value in update expressions.
  177.  
  178. - (void)setSelectFormat:(NSString *)string;
  179.     // Supplies a string used to format the value in select expressions.
  180.  
  181. - (void)setUserDictionary:(NSDictionary *)dictionary;
  182.     // Sets the dictionary of auxiliary data, which your application can use
  183.     // for whatever it needs.
  184.  
  185. @end
  186.  
  187.  
  188. @interface EOAttribute (NSDateSupport)
  189. + (NSString *)defaultCalendarFormat;
  190.     // Returns a default date format. Can be used when the EOAttribute does
  191.     // not have a dateFormat of it's own.
  192.     
  193. - (void)setCalendarFormat: (NSString *)format;
  194. - (NSString *)calendarFormat;
  195.     // Set/return the format that will be used when the NSDate object is
  196.     // initialized.
  197.  
  198. - (void)setServerTimeZone: (NSTimeZone *)tz;
  199. - (NSTimeZone *)serverTimeZone;
  200.     // Set/return the implicit time zone of the dates provided by the database
  201.     // server.
  202.  
  203. - (void)setClientTimeZone: (NSTimeZone *)tz;
  204. - (NSTimeZone *)clientTimeZone;
  205.     // Set/return the time zone that will be used when the date is told to
  206.     // represent itself.
  207.  
  208. @end
  209.