ヘッダーをスキップ

トランスフォーメーション・マッピングの作成

トランスフォーメーション・マッピングを作成するにはこの手順を使用します。

トランスフォーメーション・マッピングを作成するには、次のようにします。

  1. 「アプリケーション・ナビゲータ」で、マップされる属性を選択します。
  2. マッピング・ツールバーで「トランスフォーメーション・マッピング」ボタン「トランスフォーメーション・マッピング」ボタン。をクリックします。

    図7-5 「トランスフォーメーション・マッピング」タブ

    トランスフォーメーション・マッピングの「一般」タブ

  3. データベース行をオブジェクトに変換するメソッドを選択するには、「データベース行 -> Objectメソッド」ドロップダウン・リストを使用します。
    注意: メソッドにはパラメータ(DatabaseRow)またはパラメータ(DatabaseRow, Session)が必要です。
  4. トランスフォーメーション・メソッドのフィールドをディスクリプタに追加するには、「追加」をクリックします。
    トランスフォーメーション・メソッドを削除するには、メソッドを選択して「削除」をクリックします。
  5. ターゲット・オブジェクトの作成に過大な処理リソースが必要な場合に指定するには、「インダイレクションの使用」をオプションを選択します。これを選択すると、TopLinkではインダイレクションが使用されます。詳細は、「インダイレクションの使用」を参照してください。
  6. マッピングの詳細を指定した後、関連付けられているJavaクラスで属性フィールド・トランスフォーメーション・メソッドを作成します(例7-1を参照)。

次の項目を指定することもできます。

次のコード例は、トランスフォーメーション・マッピングに必要なメソッドを示しています。

// 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];
}