拡張プロパティーの値に基づく検索のためのサンプル・コード

このサンプル・コード・スニペットおよびデータ・グラフは、拡張プロパティーの値に基づいて検索を実行するために使用します。

以下のサンプル・コード・スニペットおよびデータ・グラフは、検索ベースを使用して、拡張プロパティー age の値を検索基準としてエンティティーを検索する方法を示します。

前提条件

プログラミングの前提条件」トピックで説明されている情報を参照済みであること、またトピックの手順を実行済みであることを確認してください。そのトピックでは、プロパティー・データ型の有効な構文もリストされています。

異なる検索ベースでデータが取り込まれた拡張プロパティーを持つエンティティーが必要です。拡張プロパティーの作成方法を示すサンプル・コードについては、以下のトピックを参照してください。

サンプル・コード

次のコード・スニペットをアプリケーション・コードに追加し、変数 を実際に使用する値に置き換えます。

private static void searchWithSearchBase() 
{
    try 
    {
        //Search Person B
        DataObject root = SDOHelper.createRootDataObject();
        DataObject searchCtrl = SDOHelper.createControlDataObject(root, null, 
                SchemaConstants.DO_SEARCH_CONTROL);
        searchCtrl.getList(SchemaConstants.PROP_PROPERTIES).add("uid");
        searchCtrl.getList(SchemaConstants.PROP_PROPERTIES).add("sn");
        searchCtrl.getList(SchemaConstants.PROP_PROPERTIES).add("cn");
        searchCtrl.getList(SchemaConstants.PROP_PROPERTIES).add("age");
        /**
         * You can add search bases to the search as shown here:
         * o=defaultWIMFileBasedRealm for default file repository search
         * or
         * dc=yourco,dc=com for the LDAP repository search.
         * If no search base is provided, the search runs across all the base entries configured.
         */
        searchCtrl.getList(SchemaConstants.PROP_SEARCH_BASES).add("o=defaultWIMFileBasedRealm");
        searchCtrl.setString(SchemaConstants.PROP_SEARCH_EXPRESSION, 
                "@xsi:type='PersonAccount' and age > 2");
        root = service.search(root);
        System.out.println("Output data graph" +  printDO(root));
        printIdentifiers(root);
    }
    catch (Exception e) 
    {
        e.printStackTrace();
    }
}

エンティティーが、指定された検索ベース (デフォルトのファイル・リポジトリー検索の場合は o=defaultWIMFileBasedRealm、LDAP リポジトリー検索の場合は dc=yourco,dc=com など) に属することを確認することによって、検索結果を検証することができます。

出力データ・グラフ

検索ベースを使用して、拡張プロパティーの値に基づいてエンティティーを検索する場合の出力データ・グラフ:

<?xml version="1.0" encoding="UTF-8"?>
<sdo:datagraph xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:sdo="commonj.sdo" xmlns:wim="http://www.ibm.com/websphere/wim">
  <wim:Root>
    <wim:entities xsi:type="wim:PersonAccount">
      <wim:identifier externalName="uid=personb,o=defaultWIMFileBasedRealm" 
          repositoryId="InternalFileRepository"
          uniqueId="9e27cd3b-6300-4264-a4ac-768dd1092d11" 
          uniqueName="uid=personb,o=defaultWIMFileBasedRealm"/>
      <wim:uid>personb</wim:uid>
      <wim:cn>Person B</wim:cn>
      <wim:sn>PersonBLastName</wim:sn>
    </wim:entities>
  </wim:Root>
</sdo:datagraph>


利用条件 | フィードバック