Creating Transformation Mappings

Use this procedure to create transformation mappings.

To create a transformation mapping:

  1. In the Application Navigator select the attribute to be mapped.
  2. Click the Transformation Mapping button Transformation Mapping button. from the Mapping toolbar.

    Figure 7-5 Transformation Mapping Tab

    This figure shows the General tab for a transformation mapping.

  3. Use the Database Row --> Object Method drop-down list to select a method to convert the database row into an object.
    Note: The method must have the parameter (DatabaseRow) or parameters (DatabaseRow, Session).
  4. Click Add to add field transformation methods to the descriptor.
    To remove a transformation method, select the method and click Remove.
  5. Select the Use indirection option to specify if the creation of the target object requires extensive computational resources. If selected, TopLink uses indirection objects. See "Working with Indirection" for more information.
  6. After specifying the details of the mapping, create the attribute field transformation methods in the associated Java class (see Example 7-1).

You can also specify:

The following code example illustrates the methods required for a transformation mapping:

// Get method for the normalHours attribute since method access indicated
access public Time[] getNormalHours()
{
    return normalHours;
}
// Set method for the normalHours attribute since method access indicated
access public void setNormalHours(Time[] theNormalHours)
{
    normalHours = theNormalHours;
}
// Create attribute transformation method to read from the database row
//** Builds the normalHours Vector. IMPORTANT: This method builds the value but does not set it. The mapping will set it using method or direct access as defined in the descriptor. */
public Time[] getNormalHoursFromRow(DatabaseRow row)
{
    Time[] hours = new Time[2];
    hours[0] = (Time)row.get("START_TIME");
    hours[1] = (Time)row.get("END_TIME");
    return hours;
}
// Define a field transformation method to write out the start time. Return the first element of the normalHours attribute.
public java.sql.Time getStartTime()
{
    return getNormalHours()[0];
}
// Define a field transformation method to write out the end time. Return the last element of the normalHours attribute.
public java.sql.Time getEndTime()
{
    return getNormalHours()[1];
}

 

Copyright © 1997, 2004, Oracle. All rights reserved.