setExternalType
and externalType
methods. The class type used by the application is accessed with the valueClassName
method. You can map database types to a set of standard value classes, which includes:
The handling of dates assumes by default that both the database server and the client application are running in the same, local, time zone. You can alter the server time zone with the setServerTimeZone
method. If you alter the server time zone, the adaptor automatically converts dates as they pass into and out of the server.
Working with Custom Data Types
When you create a new model, EOModeler maps each attribute in your model to one of the primitive data types the adaptor knows how to manipulate: String, Number, java.math.BigDecimal, NSData, and NSDate. For example, suppose you have a photo
attribute that's stored in the database as a LONG RAW. When you create a new model, this attribute is mapped to NSData. However, NSData is just an object wrapper for binary data-for instance, it doesn't have any methods for operating on images, which would limit what you'd be able to do with the image in your application. This is a case in which you'd probably choose to use a custom data type, such as com.apple.yellow.application.NSImage.
For a custom data type to be usable in Enterprise Objects Framework, it must supply methods for importing and exporting itself as one of the primitive types so that it can be read from and written to the database. Specifically, to use a custom data type you need to do the following:
setValueClassName
.
setValueFactoryMethodName
.
setFactoryMethodArgumentType
.
setAdaptorValueConversionMethodName
; this enables the data to be stored in the database.
Instead of setting the class information programmatically, you can use the Attributes Inspector in EOModeler, which is more common. For more information, see the chapter "Advanced Modeling Techniques" in the Enterprise Objects Framework Developer's Guide.
Fetching Custom Values
Custom values are created during fetching in EOAdaptorChannel's fetchRow
method. This method fetchesdata in the external (server) type and converts it to a value object, applying the custom value factory method (valueFactoryMethod
) to convert a value into the custom class if necessary. Once the value is converted, the EOAdaptorChannel puts it into the dictionary for the row being fetched.
Converting Custom Values
Custom values are converted back to binary or character data in EOAdaptorChannel's evaluateExpression
method. For each value in the EOSQLExpression to be evaluated, the EOAdaptorChannel sends the appropriate EOAttribute an adaptorValueByConvertingAttributeValue
message to convert it. If the value is any of the standard value classes, it's returned unchanged. If the value is of a custom class, though, it's converted by applying the conversion method (adaptorValueConversionMethod
) specified in the EOAttribute.