ヘッダーをスキップ

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

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

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

  1. 構造ウィンドウで、マップされる属性を選択します。
  2. 必要な情報を入力してマッピングを完了します。
  3. データベース行をオブジェクトに変換するメソッドを選択するには、「データベース行 -> Objectメソッド」ドロップダウン・リストを使用します。
    注意: メソッドにはパラメータ(DatabaseRow)またはパラメータ(DatabaseRow, Session)が必要です。
  4. トランスフォーメーション・メソッドのフィールドをディスクリプタに追加するには、「追加」をクリックします。
    変換メソッドを削除するには、メソッドを選択し、「削除」をクリックします。

関連トピック

CMP EJBマッピングについて

 

CMP直接マッピングの使用

 

トランスフォーメーション・マッピングの使用
共通マッピング・プロパティの使用
ディスクリプタの修正によるトランスフォーメーション・マッピングの拡張機能の指定

例6-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];
}

ディスクリプタの修正によるトランスフォーメーション・マッピングの拡張機能の指定

TopLinkでは、トランスフォーメーション・マッピングで属性を指定する必要はありません。

フィールドは、計算された値からマップされ、この値は論理的属性にマップしません。これは事実上、書込み専用マッピングを構成します。TopLinkマッピング・エディタでは、その他の情報が指定される前にすべてのマッピングが属性と関連付けられています。このため、書込み専用マッピングを使用する場合は、ディスクリプタを修正してビルドする必要があります。マッピング自体には属性名、getメソッド、setメソッドまたは属性メソッドはありません。修正メソッドでは、TransformationMappingのインスタンスを作成し、書き込まれる各フィールドに対するaddFieldTransformation()メッセージを送信します。

例6-2 ディスクリプタの修正例

次のコード例は、書込み専用トランスフォーメーション・マッピングの作成とそのマッピングのディスクリプタへの追加を示しています。

public static void addToDescriptor(Descriptor descriptor) {
// Create a Transformation mapping and add it to the descriptor.
TransformationMapping transMapping = new transMapping.addFieldTransformation("WRITE_DATE", "descriptor.addMapping(transMapping);
}

次の例は、主キーの継承インジケータ・フィールドの使用による一方向トランスフォーメーション・マッピングの作成方法を示しています。主キーの他の部分も含めてクラスを通常どおりマップし、型フィールドを介して継承をマップします。

クラスの修正メソッドを作成します。

public void addToDescriptor(Descriptor descriptor) {
    TransformationMapping keyMapping = new TransformationMapping();
    keyMapping.addFieldTranslation("PROJECT.PROJ_TYPE",
        "getType");descriptor.addMapping(keyMapping);}   

型の値を返すようにクラスのgetTypeメソッドを定義します。

Project>>public abstract String getType();
LargeProject>>public String getType() { return "L"; }
SmallProject>>public String getType() { return "S"; }


関連トピック

CMP EJBマッピングについて

 

CMP直接マッピングの使用

 

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