获取实体的祖代

使用 get(DataObject) 方法和 AncestorControl 显示实体的祖代。

关于此任务

这是 SalesPerson1 的分层构造:
  • cn=users,dc=yourco,dc=com
    • o=Sales
      • ou=CA
        • uid=SalesPerson1
      • ou=US
      • ou=Europe

在此示例中,请求为显示 SalesPerson1 的祖代的所有级别。

要请求 SalesPerson1 的祖代的所有级别,请将此样本代码添加到应用程序代码,并使用要用于此请求的实际值替换变量
DataObject root = SDOHelper.createRootDataObject();
DataObject entity = SDOHelper.createEntityDataObject(root, null, DO_PERSON_ACCOUNT);
entity.createDataObject(DO_IDENTIFIER).setString(PROP_UNIQUE_NAME, 
               "uid=SalesPerson1,ou=CA,o=Sales,cn=users,dc=yourco,dc=com");			
DataObject ancesCtrl = SDOHelper.createControlDataObject(root, null, DO_ANCESTOR_CONTROL);
// 0 means all ancestors
ancesCtrl.setInt(PROP_LEVEL, 0); 
ancesCtrl.getList(PROP_PROPERTIES).add("uid");
ancesCtrl.getList(PROP_PROPERTIES).add("cn");
ancesCtrl.getList(PROP_PROPERTIES).add("o");
ancesCtrl.getList(PROP_PROPERTIES).add("ou");			
		
root = service.get(root);

输入和输出数据图样本

对于此特定示例,输入数据图为:
<?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 uniqueName="uid=SalesPerson1,ou=CA,o=Sales,cn=users,dc=yourco,dc=com"/>
    </wim:entities>
    <wim:controls xsi:type="wim:AncestorControl" level="0">
      <wim:properties>uid</wim:properties>
      <wim:properties>cn</wim:properties>
      <wim:properties>o</wim:properties>
      <wim:properties>ou</wim:properties>
    </wim:controls>
  </wim:Root>
</sdo:datagraph>
此示例的生成输出数据图为:
<?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=SalesPerson1,ou=CA,o=Sales,cn=users,dc=yourco,dc=com"
                      repositoryId="LDAP1" 
                      uniqueId="e7db8c0e-d2b3-43fe-be14-1475125606f4" 
                      uniqueName="uid=SalesPerson1,ou=CA,o=Sales,cn=users,dc=yourco,dc=com"/>
      <wim:parent xsi:type="wim:OrgContainer">
        <wim:identifier externalId="0dfcccf7-9fb9-4b25-a0f4-ff4b6b33068e" 
                        externalName="ou=CA,o=Sales,cn=users,dc=yourco,dc=com"
                        repositoryId="LDAP1" 
                        uniqueName="ou=CA,o=Sales,cn=users,dc=yourco,dc=com"/>
        <wim:parent xsi:type="wim:OrgContainer">
          <wim:identifier externalId="eab85abb-9d29-40f1-b502-36c051d3ee96" 
                          externalName="o=Sales,cn=users,dc=yourco,dc=com"
                          repositoryId="LDAP1" 
                          uniqueName="o=Sales,cn=users,dc=yourco,dc=com"/>
          <wim:parent xsi:type="wim:OrgContainer">
            <wim:identifier externalId="93fde597-b628-4952-90cc-d6b178a05235" 
                            externalName="cn=users,dc=yourco,dc=com"
                            repositoryId="LDAP1" 
                            uniqueName="cn=users,dc=yourco,dc=com"/>
            <wim:cn>users</wim:cn>
          </wim:parent>
          <wim:o>Sales</wim:o>
        </wim:parent>
        <wim:ou>CA</wim:ou>
      </wim:parent>
    </wim:entities>
  </wim:Root>
</sdo:datagraph>
CA、Sales、users 和 dc=yourco.dc=com 作为 SalesPerson1 的祖代返回。

另请参阅“用于在层次结构中创建实体以及获取后代和祖代的样本代码”主题。



使用条款 | 反馈