構造マッピングは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メソッドのプロパティ
Copyright © 1997, 2004, Oracle. All rights reserved.