home *** CD-ROM | disk | FTP | other *** search
- // EOAttribute.h
- // Copyright (c) 1994, NeXT Software, Inc. All rights reserved.
-
- #import <EOControl/EOControl.h>
- #import <EOAccess/EOPropertyListEncoding.h>
-
- @class EOExpressionArray;
- @class EOEntity;
- @class EOStoredProcedure;
-
- // 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.
- // EOAttributes are also used to represent arguments for EOStoredProcedures.
- //
- // 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".
-
- typedef enum {
- EOFactoryMethodArgumentIsNSData = 0,
- EOFactoryMethodArgumentIsNSString,
- EOFactoryMethodArgumentIsBytes
- } EOFactoryMethodArgumentType;
-
- typedef enum {
- EOAdaptorNumberType,
- EOAdaptorCharactersType,
- EOAdaptorBytesType,
- EOAdaptorDateType
- } EOAdaptorValueType;
-
- typedef enum {
- EOVoid = 0,
- EOInParameter,
- EOOutParameter,
- EOInOutParameter,
- } EOParameterDirection;
-
-
- @interface EOAttribute : NSObject <EOPropertyListEncoding>
- {
- NSString *_name;
- id _parent;
- NSString *_columnName;
- EOExpressionArray *_definitionArray;
- NSString *_externalType;
- NSString *_valueType;
- NSString *_valueClassName;
- NSString *_readFormat;
- NSString *_writeFormat;
- NSTimeZone *_serverTimeZone;
- unsigned int _width;
- unsigned short _precision;
- short _scale;
- Class _valueClass;
- EOFactoryMethodArgumentType _argumentType;
- NSString *_valueFactoryMethodName;
- NSString *_adaptorValueConversionMethodName;
- SEL _valueFactoryMethod;
- SEL _adaptorValueConversionMethod;
- struct {
- unsigned int allowsNull:1;
- unsigned int isReadOnly:1;
- unsigned int isParentAnEOEntity:1;
- unsigned int extraRefCount:29;
- } _flags;
-
- NSDictionary *_sourceToDestinationKeyMap;
- EOParameterDirection _parameterDirection;
- NSDictionary *_userInfo;
- }
-
- - (NSString *)name;
- // Returns the internal name of the attribute.
-
- - (EOEntity *)entity;
- // Returns the entity that owns the attribute.
- // If this attribute is acting as an argument for a stored procedure,
- // this will return nil.
-
- - (EOStoredProcedure *)storedProcedure;
- // Returns the store procedure for which this attribute is an
- // argument. If this is an attribute in an entity, this method
- // will return nil;
-
- - (id)parent;
- // Returns an EOEntity or EOStoredProcedure.
- // Should be used when you need to find the model for an attribute.
- // [[attribute parent] model]
-
- - (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.
-
- - (NSString *)valueClassName;
- // Returns the name of the class for custom-value types. If a column
- // from the database is to be represented by an NSImage, for example,
- // this returns "NSImage".
-
- - (NSString *)valueType;
- // A format for custom-value types, such as "TIFF" or "RTF".
-
- - (unsigned)width;
- // the maximum length in bytes for values mapped to this attribute.
- // Returns zero for number and date types
-
- - (unsigned)precision;
- // For attributes with a value class of NSNumber or NSDecimalNumber,
- // the precision of the database representation
-
- - (int)scale;
- // For attributes with a value class of NSNumber or NSDecimalNumber, the
- // scale of the database representation (can be negative).
-
- - (BOOL)allowsNull;
-
- - (NSString *)writeFormat;
- - (NSString *)readFormat;
- // These methods return format strings for building expressions of the
- // appropriate type to contain the value of the attribute.
-
- - (EOParameterDirection)parameterDirection;
- // For Attributes that are stored procedure arguments
-
- - (NSDictionary *)userInfo;
- // Returns a dictionary of user data. You can use this to store any
- // auxiliary information.
- @end
-
-
- @interface EOAttribute(EOAttributeEditing)
-
- - (NSException *)validateName:(NSString *)name;
-
- - (void)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.
-
- - (void)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 by adding the attribute to an entity. This method will not
- // function correctly if the attribute's entity has not been set.
-
- - (void)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:(NSString *)name;
- // Sets the class name for values of this attribute. If values are
- // instances of NSImage, you would send:
- // [myAttribute setValueClassName:@"NSImage"];
-
- - (void)setWidth:(unsigned)length;
- // This field indicates the maximum amount of bytes the value may contain.
- // Adaptors may use this information to allocate space for fetch buffers.
-
- - (void)setPrecision:(unsigned)precision;
- // For attributes with a value class of NSNumber or NSDecimalNumber, sets
- // the precision of the database representation.
- // Will raise if called for attributes that have a value class other than
- // NSNumber or NSDecimalNumber.
-
- - (void)setScale:(int)scale;
- // For attributes with a value class of NSDecimalNumber, the scale
- // of the database representation (can be negative).
- // Will raise if called for attributes that have a value class other than
- // NSNumber or NSDecimalNumber.
-
- - (void)setAllowsNull:(BOOL)allowsNull;
- // The field indicates whether or not the attribute can have a nil value.
- // if the attribute maps directly to a column in the database it also
- // is used to determine whether the database column can have a NULL value.
-
- // The strings supplied to the two following methods are used to generate
- // the attribute's expression value for insert, update and select statements.
- // In the read format string, %P is replaced by the attribute's external name; in
- // the write format string, %V is replaced by its value. The read format string
- // is used whenever the attribute is referenced in a select list or qualifier.
- // The write format string is is used whenever a value is used in an insert or
- // update statement.
-
- - (void)setWriteFormat:(NSString *)string;
- // Supplies a string used to format the value in update expressions.
-
- - (void)setReadFormat:(NSString *)string;
- // Supplies a string used to format the value in select expressions.
-
- - (void)setParameterDirection:(EOParameterDirection)parameterDirection;
- // Set the direction for Stored Procedure Arguments
-
- - (void)setUserInfo:(NSDictionary *)dictionary;
- // Sets the dictionary of auxiliary data, which your application can use
- // for whatever it needs.
-
- @end
-
- @interface EOAttribute(EOModelBeautifier)
- - (void)beautifyName;
- // Make the name conform to the Next naming style
- // NAME -> name, FIRST_NAME -> firstName
- @end
-
- @interface EOAttribute (NSCalendarDateSupport)
- - (NSTimeZone *)serverTimeZone;
- // Set/return the implicit time zone of the dates provided by the database
- // server.
- @end
-
- @interface EOAttribute(NSCalendarDateSupportEditing)
- - (void)setServerTimeZone: (NSTimeZone *)tz;
- @end
-
-
- // This category is designed for use by adaptors. Clients of the model should not need
- // to use these methods.
- @interface EOAttribute (EOAttributeValueCreation)
-
- - (id)newValueForBytes:(const void *)bytes length:(int)length;
- // Called by the adaptor during value creation while fetching from the database.
- // This method will generate an NSData or custom class value.
- // For efficiency reasons, the caller is responsible for releasing the return value.
-
- - (id)newValueForBytes:(const void *)bytes length:(int)length encoding:(NSStringEncoding)encoding;
- // Called by the adaptor during value creation while fetching from the database.
- // This method will generate an NSString or custom class value.
- // For efficiency reasons, the caller is responsible for releasing the return value.
-
- - (NSCalendarDate *)newDateForYear:(int)year month:(unsigned)month day:(unsigned)day hour:(unsigned)hour minute:(unsigned)minute second:(unsigned)second millisecond:(unsigned)millisecond timezone:(NSTimeZone *)timezone zone:(NSZone *)zone;
- // Used by AdaptorChannel subclasses to create a calendar date object
- // to return in an adaptor row.
- // For efficiency reasons, the caller is responsible for releasing the return value.
-
- - (NSString *)valueFactoryMethodName;
- // Returns the name of the of the factory method used for creating a custom class value.
-
- - (SEL)valueFactoryMethod;
- // Returns the factory method invoked by the attribute when creating an
- // attribute value that is of a custom classs. This return value of this method is
- // derived from the attribute's valueFactoryMethodName. If that name does not map
- // to a valid selector in the Obj-C runtime, nil is returned.
-
- - (id)adaptorValueByConvertingAttributeValue:(id)value;
- // Checks the type of value to make sure it is one of the following primitive
- // adaptor types. If value is different, the method returned by the
- // primitiveValueMethod on this attribute is invoked to convert the type into
- // one of the following: NSString, NSData, NSNumber, or NSDate.
-
- - (NSString *)adaptorValueConversionMethodName;
- // Returns the name of the method used to convert a custom class into one of the
- // primitive types that the adaptor knows how to manipulate.
-
- - (SEL)adaptorValueConversionMethod;
- // Returns the method used to convert a custom class into one of the primitive
- // types that the adaptor knows how to manipulate. This return value of this
- // method is derived from the attribute's adaptorValueConversionMethodName. If
- // that name does not map to a valid selector in the Obj-C runtime, nil is returned.
-
- - (EOAdaptorValueType)adaptorValueType;
- // Returns a value indicating which type should be fetched from the database.
-
- - (EOFactoryMethodArgumentType)factoryMethodArgumentType;
- // The valueFactoryMethod can be one of three arguments: NSData, NSString,
- // or raw bytes. This enum indicates the type of argument that should
- // be passed to the valueFactoryMethod.
- @end
-
- @interface EOAttribute(EOAttributeValueCreationEditing)
- - (void)setValueFactoryMethodName:(NSString *)factoryMethodName;
- // Sets the value factory method name. This should be a class method that
- // returns an autoreleased object.
-
- - (void)setAdaptorValueConversionMethodName:(NSString *)conversionMethodName;
- // Sets the adaptorValueConversionMethod. This method should return a an
- // autoreleased object.
-
- - (void)setFactoryMethodArgumentType:(EOFactoryMethodArgumentType)argumentType;
- // Sets the factoryMethodArgumentType;
- @end
-
- @interface EOAttribute(EOAttributeValueMapping)
- - (NSException *)validateValue:(id *)valueP;
- // Attempts to convert value to type specified in attribute and tests other
- // attribute validation constraints (e.g. allowsNull, width, etc).
- // Returns nil on success, exception otherwise.
- // If any coercion was performed, the converted value is assigned to *valueP.
- @end
-
- @interface NSObject (EOCustomClassArchiving)
- + objectWithArchiveData:(NSData *)data;
- // This is the default value factory method when creating custom values.
- - (NSData *)archiveData;
- // This is the default value conversion method when saving default values.
- @end
-