Oracle TopLink Developer's Guide
10g Release 3 (10.1.3) B13593-01 |
|
![]() Previous |
![]() Next |
An object type converter is used to match a fixed number of data source data values to Java object values. It can be used when the values in the data source and in Java differ.
For more information about the object type converter, see "Object Type Converter".
Table 35-12 summarizes which mappings support this option.
Table 35-12 Mapping Support for Object Type Converter
Mapping | Using TopLink Workbench
|
Using Java
|
---|---|---|
|
|
|
|
|
|
Object-Relational Array Mapping |
![]() |
|
|
|
|
|
|
|
EIS Composite Direct Collection Mapping |
|
|
|
|
|
|
|
|
XML Composite Direct Collection Mapping |
|
|
To add an object type converter to a direct mapping, use this procedure:
Select the mapping in the Navigator. Its properties appear in the Editor.
Click the Converter tab. The Converter tab appears.
Figure 35-12 Converter Tab, Object Type Converter
Use the following fields on the mapping's Converter tab to specify the object type converter options:
Field | Description |
---|---|
Data Type | Select the Java type of the data in the data source. |
Attribute Type | Select the Java type of the attribute in the Java class. |
Conversion Values | Click Add to add a new conversion value. Click Edit to modify an existing conversion value. Click Remove to delete an existing conversion value.
Use to specify the selected value as the default value. If TopLink retrieves a value from the database that is not mapped as a valid Conversion Value, the default value will be used. |
Data Value | Specify the value of the attribute in the data source. |
Attribute Value | Specify the value of the attribute in the Java class |
Default Attribute Value | Specify whether or not to use the selected value as the default value. If TopLink retrieves a value from the database that is not mapped as a valid Conversion Value, the default value will be used. |
You can set an oracle.toplink.converters.ObjectTypeConverter
on any instance of oracle.toplink.mappings.foundation.AbstractCompositeDirectCollectionMapping
using AbstractCompositeDirectCollectionMapping
method setValueConverter
as Example 35-13 shows.
Example 35-13 Configuring an ObjectTypeConverter in Java
// Create ObjectTypeConverter instance ObjectTypeConverter objectTypeConvter = new ObjectTypeConverter(); objectTypeConverter.addConversionValue("F", "Female"); // Set ObjectTypeConverter on ArrayMapping ArrayMapping arrayMapping = new ArrayMapping(); arrayMapping.setValueConverter(objectTypeConverter); arrayMapping.setAttributeName("responsibilities"); arrayMapping.setStructureName("Responsibilities_t"); arrayMapping.setFieldName("RESPONSIBILITIES"); orDescriptor.addMapping(arrayMapping);
Configure the ObjectTypeConverter
instance using the following API:
addConversionValue(java.lang.Object fieldValue, java.lang.Object attributeValue)
–to associate data-type values to object-type values
addToAttributeOnlyConversionValue(java.lang.Object fieldValue, java.lang.Object attributeValue)
–to add one-way conversion values
setDefaultAttributeValue(java.lang.Object defaultAttributeValue)
–to set the default value