構造マッピングはStructureMapping
クラスのインスタンスです。このマッピングをそれぞれの親クラスの属性に関連付ける必要があります。TopLinkでは配列マッピングに次の要素が必要です。
setAttributeName( )
メッセージを送信して設定されます。 setFieldName( )
メッセージを送信して設定されます。 setReferenceClass( )
メッセージを送信して設定されます。直接ではなくユーザー定義メソッドによって属性にアクセスする場合は、オプションの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, 2006, Oracle. All rights reserved.