このサンプル・コード・スニペットおよびデータ・グラフは、プロパティー拡張リポジトリーでスキーマを拡張するために使用します。
以下のサンプル・コード・スニペットおよびデータ・グラフは、プロパティー age を PersonAccount エンティティー・タイプに追加し、extensionPropertySchema データ・オブジェクトを使用してプロパティー拡張リポジトリー内のスキーマを拡張する方法を示します。extensionPropertySchema を使用するためには、プロパティー拡張リポジトリーを構成しておく必要があります。詳しくは、WebSphere Application Server インフォメーション・センターの「フェデレーテッド・リポジトリー構成におけるプロパティー拡張リポジトリーの構成」を参照してください。
「プログラミングの前提条件」トピック (propertySchema および extensionPropertySchema データ・オブジェクトについての情報が記載され、プロパティーのデータ型についての有効な構文がリストされている「プロパティー・スキーマの拡張」セクションを含む) で説明されている情報を参照済みであること、またトピックの手順を実行済みであることを確認してください。
次のコード・スニペットをアプリケーション・コードに追加し、変数 を実際に使用する値に置き換えます。
// Get a root data object. The rest of the object tree would be built under it
DataObject root = SDOHelper.createRootDataObject();
// Create a new "schema" object under root
// This object will contain the details of the schema modifications that need to be made
DataObject schema = root.createDataObject(SchemaConstants.DO_SCHEMA);
// Create a property schema data object under the schema object created earlier
// Note: To ensure that the property is also added into the extension repository
// use the Extension Property Schema instead of the simple Property Schema
DataObject propertySchema = schema.createDataObject(SchemaConstants.DO_EXTENSION_PROPERTY_SCHEMA);
// Set the value for the property name
propertySchema.setString(SchemaConstants.PROP_PROPERTY_NAME, "age");
// Set the namespace for the property
// As here we are defining the property in the default namespace,
// we do not need to define the namespace prefix
// Note: Adding of property in default namespace is only possible when the VMM is using "dynamicModel"
propertySchema.setString(SchemaConstants.PROP_NS_URI, SchemaConstants.WIM_NS_URI);
// Specify if the property is multi-valued (if it is multi-valued, its type must be List)
propertySchema.setBoolean(SchemaConstants.PROP_MULTI_VALUED, false);
// Specify the data type of the property
// Data types can be simple like boolean, int, float, double, String
// or special like Address, Person, Group, etc.
propertySchema.setString(SchemaConstants.PROP_DATA_TYPE, SchemaConstants.DATA_TYPE_INT);
// Get the list of entity types to which this property needs to be added and
// add the applicable entity type names (here "PersonAccount") to the list fetched previously
propertySchema.getList(SchemaConstants.PROP_APPLICABLE_ENTITY_TYPE_NAMES).add(Service.DO_PERSON_ACCOUNT);
// Invoke the create schema
root = service.createSchema(root);
wsadmin コマンド deleteIdMgrPropertyExtensionEntityData を使用して、プロパティー拡張リポジトリーからプロパティー・データを削除することができます。このコマンドの使用について詳しくは、WebSphere Application Server インフォメーション・センターの「AdminTask オブジェクトの IdMgrDBSetup コマンド・グループ」トピックを参照してください。
プロパティーを追加するための入力データ・グラフ:
<?xml version="1.0" encoding="UTF-8"?>
<sdo:datagraph xmlns:sdo="commonj.sdo"
xmlns:wim="http://www.ibm.com/websphere/wim">
<wim:Root>
<wim:schema>
<wim:extensionPropertySchema nsURI="http://www.ibm.com/websphere/wim" dataType="Int"
multiValued="false" propertyName="age">
<wim:applicableEntityTypeNames>PersonAccount</wim:applicableEntityTypeNames>
</wim:extensionPropertySchema>
</wim:schema>
</wim:Root>
</sdo:datagraph>
プロパティーを追加した後の出力データ・グラフ:
<?xml version="1.0" encoding="UTF-8"?>
<sdo:datagraph xmlns:sdo="commonj.sdo"
xmlns:wim="http://www.ibm.com/websphere/wim">
<wim:Root>
<wim:schema>
<wim:extensionPropertySchema nsURI="http://www.ibm.com/websphere/wim" dataType="Int"
multiValued="false" propertyName="age">
<wim:applicableEntityTypeNames>PersonAccount</wim:applicableEntityTypeNames>
</wim:extensionPropertySchema>
</wim:schema>
</wim:Root>
</sdo:datagraph>