PATH |
Inherits from: Object
Implements: EOPropertyListEncodingEOSQLExpression.SQLValue
Package: com.webobjects.eoaccess
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. The property an EOAttribute represents may be a meaningful value, such as a salary or a name, or it may be an arbitrary value used for identification but with no real-world applicability (ID numbers and foreign keys for relationships fall into this category). An EOAttribute also maintains type information for binding values to the instance variables of objects.
EOAttributes are also used to represent arguments for EOStoredProcedures.
You usually define attributes in your EOModel with the EOModeler application, which is documented in Enterprise Objects Framework Tools and Techniques. Your code probably won't need to programmatically interact with EOAttribute unless you're working at the adaptor level. See "Creating Attributes" (page 103) for information on creating your own attribute objects.
Fore detailed discussion of using attribute objects to map database data types to Java objects, see "Mapping from Database to Objects" (page 105) and "Working with Custom Data Types" (page 105). EOAttributes can also alter the way values are selected, inserted, and updated in the database by defining special format strings; see "SQL Statement Formats" (page 107) for more information.
EOAttribute defines the following int
constants as possible return values for the EOAttribute method adaptorValueType. The return value indicates the data type that will be fetched from the database for the receiving attribute.
EOAttribute defines the additional int
constants to be used by factoryMethodArgumentType and setFactoryMethodArgumentType to specify the type of argument that should be passed to the attribute's "factory method". For more information, see "Working with Custom Data Types" (page 105).
EOAttribute also defines int
constants to represent parameter direction for EOAttributes that represent arguments to a stored procedure. For more information, see the parameterDirection method description.
EOPropertyListEncoding awakeWithPropertyListencodeIntoPropertyList
ConstructorsEOAttributeAccessing the entityentityparentAccessing the namesetNamenamebeautifyNameAccessing date informationserverTimeZonesetServerTimeZoneAccessing external definitionssetColumnNamecolumnNamesetDefinitiondefinitionsetExternalTypeexternalTypeAccessing value type informationsetValueClassNamevalueClassNamesetValueTypevalueTypesetAllowsNullallowsNullsetPrecisionprecisionsetScalescalesetWidthwidthvalidateValueConverting to adaptor value typesadaptorValueByConvertingAttributeValueadaptorValueTypeWorking with custom value typessetValueFactoryMethodNamevalueFactoryMethodvalueFactoryMethodNamesetFactoryMethodArgumentTypefactoryMethodArgumentTypesetAdaptorValueConversionMethodNameadaptorValueConversionMethodadaptorValueConversionMethodNameAccessing attribute characteristicssetReadOnlyisReadOnlyisDerivedisFlattenedAccessing SQL statement formatssetReadFormatreadFormatsetWriteFormatwriteFormatAccessing the user dictionarysetUserInfouserInfoWorking with stored proceduressetParameterDirectionparameterDirectionstoredProcedureWorking with prototypesoverridesPrototypeDefinitionForKeyprototypeprototypeNamesetPrototype
public EOAttribute()
Description forthcoming.
public EOAttribute( NSDictionary, Object)
Description forthcoming.
protected EOAttribute( EOEntity, String)
Description forthcoming.
public Object adaptorValueByConvertingAttributeValue(Object value)
Ensures that value is either a String, Number, NSData, or NSDate, converting it if necessary. If value needs to be converted, adaptorValueByConvertingAttributeValue uses the adaptor conversion method to convert value to one of these four primitive types.
See Also: adaptorValueConversionMethod, adaptorValueType
public NSSelector adaptorValueConversionMethod()
Returns the method used to convert a custom class into one of the primitive types that the adaptor knows how to manipulate: String, Number, NSData, or NSDate. The return value of this method is derived from the attribute's adaptor value conversion method name. If that name doesn't map to a valid selector in the Java run-time, null
is returned.
See Also: adaptorValueByConvertingAttributeValue, adaptorValueConversionMethodName
public String 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: String, Number, NSData, or NSDate.
See Also: adaptorValueByConvertingAttributeValue
public int adaptorValueType()
Returns a constant that indicates the data type that will be fetched from the database. Currently, this method returns one of the following values:
Constant | Description |
AdaptorNumberType |
A number value |
AdaptorCharactersType |
A string of characters |
AdaptorBytesType |
Raw bytes |
AdaptorDateType |
A date |
See Also: factoryMethodArgumentType
public boolean allowsNull()
Returns true
to indicate that the attribute can have a null
value, false
otherwise. 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.
See Also: setAllowsNull
public void awakeWithPropertyList(NSDictionary list)
Description forthcoming.
public void beautifyName()
Makes the attribute name conform to a standard convention. Names that conform to this style are all lower-case except for the initial letter of each embedded word other than the first, which is upper case. Thus, "NAME" becomes "name", and "FIRST_NAME" becomes "firstName". This method is used in reverse-engineering an EOModel.
See Also: nameForExternalName (EOEntity), beautifyNames (EOModel)
public String className()
Description forthcoming.
public String columnName()
Returns the name of the column in the database that corresponds to this attribute, or null
if the attribute isn't simple (that is, if it's derived or flattened). An adaptor uses this name to identify the column corresponding to the attribute. Your application should never need to use this name. Note that columnName and definition are mutually exclusive; if one returns a value, the other returns null
.
See Also: externalType
public String definition()
Returns a derived or flattened attribute's definition, or null
if the attribute is simple. An attribute's definition is either a value expression defining a derived attribute, such as "salary * 12", or a data path for a flattened attribute, such as "toAuthor.name". Note that columnName and definition are mutually exclusive; if one returns a value, the other returns null
.
See Also: externalType, setDefinition
public void encodeIntoPropertyList(NSMutableDictionary list)
Description forthcoming.
public EOEntity entity()
Returns the entity that owns the attribute, or null
if this attribute is acting as an argument for a stored procedure.
See Also: storedProcedure
public String externalType()
Returns the attribute's type as understood by the database; for example, a Sybase "varchar" or an Oracle "NUMBER".
See Also: columnName, setExternalType
public int factoryMethodArgumentType()
Returns the type of argument that should be passed to the "factory method"-which is invoked by the attribute to create an attribute value for a custom class. This method returns one of the following values:
Constant | Argument Type |
FactoryMethodArgumentIsData |
NSData |
FactoryMethodArgumentIsString |
String |
FactoryMethodArgumentIsBytes |
raw bytes |
See Also: valueFactoryMethod, setFactoryMethodArgumentType
public boolean isDerived()
Returns false
if the attribute corresponds exactly to one column in the table associated with its entity, and true
if it doesn't. For example, an attribute with a definition of "otherAttributeName + 1" is derived.
Note that flattened attributes are also considered as derived attributes.
See Also: isFlattened, definition
public boolean isFlattened()
Returns true
if the attribute is flattened, false
otherwise. A flattened attribute is one that's accessed through an entity's relationships but belongs to another entity.
Note that flattened attributes are also considered to be derived attributes.
See Also: isDerived, definition
public boolean isReadOnly()
Returns true
if the value of the attribute can't be modified, false
if it can.
See Also: setReadOnly
public String name()
Returns the attribute's name.
See Also: columnName, definition, setName
public Object newValueForBytes( byte[] bytes, int length)
Description forthcoming.
public Object newValueForBytesString( byte[] bytes, int length)
Description forthcoming.
public boolean overridesPrototypeDefinitionForKey(String key)
Returns false
if the requested key gets its value from the prototype attribute. If the attribute has an override, then this method returns true
. Valid values for key include "columnName," "valueClass," and so on.
See Also: prototype
public int parameterDirection()
Returns the parameter direction for attributes that are arguments to a stored procedure. This method returns one of the following values:
Constant | Description |
Void |
No parameters |
InParameter |
Input only parameters |
OutParameter |
Output only parameters |
InOutParameter |
Bidirectional parameters (input and output) |
See Also: storedProcedure, storedProcedureForOperation (EOEntity), setParameterDirection
public Object parent()
Returns the attribute's parent, which is either an EOEntity or an EOStoredProcedure. Use this method when you need to find the model for an attribute.
public int precision()
Returns the precision of the database representation for attributes with a value class of Number or java.math.BigDecimal.
See Also: scale
public EOAttribute prototype()
Returns the prototype attribute that is used to define default settings for the receiver.
See Also: overridesPrototypeDefinitionForKey
public String prototypeName()
Returns the name of the prototype attribute of the receiver.
See Also: prototype
public String readFormat()
Returns a format string of the appropriate type that can be used when building an expression that contains the value of the attribute.
See Also: setReadFormat, writeFormat
public String relationshipPath()
Description forthcoming.
public int scale()
Returns the scale of the database representation for attributes with a value class of Number or java.math.BigDecimal. The returned value can be negative.
public java.util.TimeZone serverTimeZone()
Returns the time zone assumed for NSDates in the database server, or the local time zone if one hasn't been set. An EOAdaptorChannel automatically converts dates between the time zones used by the server and the client when fetching and saving values. Applies only to attributes that represent dates.
See Also: setServerTimeZone
public void setAdaptorValueConversionMethodName(String conversionMethodName)
Sets to conversionMethodName the name of the method used to convert a custom class into one of the primitive types that the adaptor knows how to manipulate: String, Number, NSData, or NSDate
See Also: adaptorValueConversionMethodName
public void setClassName(String className)
Description forthcoming.
public void setAllowsNull(boolean allowsNull)
Sets according to allowsNull whether or not the attribute can have a null
value. If the attribute maps directly to a column in the database, it also controls whether the database column can have a null value.
See Also: allowsNull
public void setColumnName(String columnName)
Sets to columnName the name of the attribute used in communication with the database server. An adaptor uses this name to identify the column corresponding to the attribute; this name must match the name of a column in the database table corresponding to the attribute's entity.
This method makes a derived or flattened attribute simple; the definition is released and the column name takes its place for use with the server.
Note: setColumnName and setDefinition 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 null . |
See Also: columnName
public void setDefinition(String definition)
Sets to definition the attribute's definition as recognized by the database server. definition should be either a value expression defining a derived attribute, such as "salary * 12", or a data path for a flattened attribute, such as "toAuthor.name".
Prior to invoking this method, 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.
This method converts a simple attribute into a derived or flattened attribute; the columnName is removed and the definition takes its place for use with the server.
Note: setColumnName and setDefinition 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 null . |
See Also: definition
public void setExternalType(String typeName)
Sets to typeName the type used for the attribute in the database adaptor; for example, a Sybase "varchar" or an Oracle7 "NUMBER". Each adaptor defines the set of types that can be supplied to setExternalType. The external type you specify for a given attribute must correspond to the type used in the database server.
See Also: setDefinition, externalType
public void setFactoryMethodArgumentType(int argumentType)
Sets the type of argument that should be passed to the "factory method"-which is invoked by the receiver to create a value for a custom class. Factory methods can accept Strings, NSDatas, or raw bytes; specify an argumentType as FactoryMethodArgumentIsString, FactoryMethodArgumentIsData, or FactoryMethodArgumentIsBytes as appropriate.
See Also: setValueFactoryMethodName, factoryMethodArgumentType
public void setName(String name)
Sets the attribute's name to name. Throws an exception if name is already in use by another attribute or relationship of the same entity, or if name is not a valid attribute name.
See Also: name
public void setParameterDirection(int parameterDirection)
Sets the parameter direction for attributes that are arguments to a stored procedure. parameterDirection should be one of the following values:
See Also: setStoredProcedure (EOEntity), parameterDirection
public void setPrecision(int precision)
Sets to precision the precision of the database representation for attributes with a value class of Number or java.math.BigDecimal.
public void setPrototype(EOAttribute prototype)
Sets the prototype attribute. This overrides any existing settings in the attribute.
See Also: prototype
public void setReadFormat(String aString)
Sets the format string that's used to format the attribute's value for SELECT statements. In aString, %P is replaced by the attribute's external name.
The read format string is used whenever the attribute is referenced in a select list or qualifier.
See Also: setWriteFormat, readFormat
public void setReadOnly(boolean flag)
Sets whether the value of the attribute can be modified according to flag. Throws an exception if flag is false
and the argument is derived but not flattened.
See Also: isDerived, isFlattened, isReadOnly
public void setScale(int scale)
Sets to scale the scale of the database representation for attributes with a value class of Number or java.math.BigDecimal. scale can be negative.
See Also: setPrecision, scale
public void setServerTimeZone(java.util.TimeZone aTimeZone)
Sets to aTimeZone the time zone used for NSDates in the database server. If aTimeZone is null
then the local time zone is used. An EOAdaptorChannel automatically converts dates between the time zones used by the server and the client when fetching and saving values. Applies only to attributes that represent dates.
See Also: serverTimeZone
public void setUserInfo(NSDictionary dictionary)
Sets to dictionary the dictionary of auxiliary data, which your application can use for whatever it needs. dictionary can only contain property list data types (that is, NSDictionary, NSArray, NSData, and String).
See Also: userInfo
public void setValueClassName(String name)
Sets the class name for values of this attribute to name. When an EOAdaptorChannel fetches data for the attribute, it's presented to the application as an instance of this class.
The class need not exist in the run-time system when this message is sent, but it must exist when an adaptor channel performs a fetch; if the class isn't present the result depends on the adaptor. See your adaptor's documentation for information on how absent value classes are handled.
See Also: setValueType, valueClassName
public void setValueFactoryMethodName(String factoryMethodName)
Sets the "factory method"-which is invoked by the attribute to create an attribute value for a custom class-to factoryMethodName. The factory method should be a static method returning an object of your custom value class. Use setFactoryMethodArgumentTypeto specify the type of argument that is to be passed to your factory method.
See Also: valueFactoryMethodName
public void setValueType(String typeName)
Sets to typeName the conversion character (such as "i" or "d") for the data type a Number attribute is converted to and from in your application. Value types are scalars such as int, float, and double. Each adaptor supports a different set of conversion characters for numeric types. However, in most (if not all) cases it's safe to supply a value of "i" (int) or "d" (double).
See Also: setValueClassName, valueType
public void setWidth(int length)
Sets to length the maximum amount of bytes the attribute's value may contain. Adaptors may use this information to allocate space for fetch buffers.
See Also: width
public void setWriteFormat(String string)
Sets the format string that's used to format the attribute's value for INSERT or UPDATE expressions. In string, %P is replaced by the attribute's value.
See Also: setReadFormat, writeFormat
public EOStoredProcedure storedProcedure()
Returns the stored procedure for which this attribute is an argument. If this attribute isn't an argument to a stored procedure but instead is owned by an entity, this method returns null
.
See Also: entity
public String toString()
Description forthcoming.
public NSDictionary userInfo()
Returns a dictionary of user data. Your application can use this to store any auxiliary information it needs.
See Also: setUserInfo
public Object validateValue(Object value) throws NSValidation.ValidationException
Validates value by converting it to the attribute's value type and by testing other attribute validation constraints (such as allowsNull, width, and so on). If, during the validation process, any coercion was performed, the converted value is returned.
See Also: adaptorValueByConvertingAttributeValue, allowsNull, valueType, valueClassName, width
public String valueClassName()
Returns the name of the class for custom value types. When data is fetched for the attribute, it's presented to the application as an instance of this class.
This class must be present in the run-time system when an EOAdaptorChannel fetches data for the attribute; if the class isn't present the result depends on the adaptor. See your adaptor's documentation for information on how absent value classes are handled.
See Also: valueType, setValueClassName
public NSSelector valueFactoryMethod()
Returns the factory method that's invoked by the attribute when creating an attribute value that's of a custom class. The value returned from this method is derived from the attribute's valueFactoryMethodName. If that name doesn't map to a valid method in the Java run-time, this method returns null
.
public String valueFactoryMethodName()
Returns the name of the factory method that's used for creating a custom class value.
See Also: valueFactoryMethod, setValueFactoryMethodName
public String valueForSQLExpression(EOSQLExpression expression)
Conformance to EOSQLExpression.SQLValue.
public String valueType()
Returns the conversion character (such as "i" or "d") for the data type a Number attribute is converted to and from in your application. Value types are scalars such as int, float, and double.
See Also: valueClassName, setValueType
public int width()
Returns the maximum length (in bytes) for values that are mapped to this attribute. Returns zero for numeric and date types.
See Also: setWidth
public String writeFormat()
Returns the format string that's used to format the attribute's value for INSERT or UPDATE expressions. In the returned string, %P is replaced by the attribute's value.
See Also: readFormat, setWriteFormat
© 2001 Apple Computer, Inc. (Last Published April 13, 2001)