ヘッダーをスキップ

Javaの構造マッピングの実装

構造マッピングはStructureMappingクラスのインスタンスです。このマッピングをそれぞれの親クラスの属性に関連付ける必要があります。TopLinkでは配列マッピングに次の要素が必要です。

直接ではなくユーザー定義メソッドによって属性にアクセスする場合は、オプションのsetGetMethodName( )およびsetSetMethodName( )メッセージを使用してください。詳細は、「直接アクセスとメソッド・アクセスの指定」を参照してください。

ターゲット(子)・クラス・ディスクリプタを次のように変更する必要があります。

表8-3に、すべての構造マッピング・プロパティのサマリーを示します。

例8-3 構造マッピングの例

次に、Employeeソース・クラスの構造マッピングを作成、およびディスクリプタに登録するコードの例を示します。

// Create a new mapping and register it with the source descriptor.
StructureMapping structureMapping = new StructureMapping();
structureMapping.setAttributeName("address");
structureMapping.setReferenceClass(Address.class);
structureMapping.setFieldName("address");
descriptor.addMapping(structureMapping);

次に、Address集約ターゲット・クラス・ディスクリプタを作成するコードの例を示します。集約ターゲット・ディスクリプタは、親へのマッピングや、表または主キー情報を必要としません。

// Create a descriptor for the aggregate class. The table name and primary key are not specified in the aggregate descriptor.
ObjectRelationalDescriptor descriptor = new ObjectRelationalDescriptor ();
descriptor.setJavaClass(Address.class);
descriptor.setStructureName("ADDRESS_T");
descriptor.descriptorIsAggregate();
// Define the field ordering
descriptor.addFieldOrdering("STREET");
descriptor.addFieldOrdering("CITY");
...
// Define the attribute mappings or relationship mappings.
...

リファレンス

次の表に、すべての構造マッピング・プロパティのサマリーを示します。「メソッド名」列で引数は太字で示されていますがメソッドは太字ではありません。

表8-3 StructureMappingメソッドのプロパティ

プロパティ デフォルト メソッド名
マップされる属性 * 適用しない setAttributeName(String name)
親クラスの設定 * 適用しない setReferenceClass(Class aClass)
マップされるフィールド * 適用しない setFieldName(String fieldName)
メソッド・アクセス 直接アクセス setGetMethodName(String name)setSetMethodName(String name)
読取り専用 読取り/書込み readWrite()readOnly()setIsReadOnly(boolean readOnly)
 * 必須プロパティ