获取实体的后代

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

关于此任务

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

在此示例中,请求为显示 OrgContainer 销售人员的所有子代。

要请求 OrgContainer 销售人员的后代,请将此样本代码添加到应用程序代码,并使用要用于此请求的实际值替换变量
DataObject root = SDOHelper.createRootDataObject();
DataObject entity = SDOHelper.createEntityDataObject(root, null, DO_ENTITY);
entity.createDataObject(DO_IDENTIFIER).setString(PROP_UNIQUE_NAME,
           "o=Sales,cn=users,dc=yourco,dc=com");			
DataObject descCtrl = SDOHelper.createControlDataObject(root, null, DO_DESCENDANT_CONTROL);
// 0 means all descendants
descCtrl.setInt(PROP_LEVEL, 0); 
descCtrl.getList(PROP_PROPERTIES).add("uid");
descCtrl.getList(PROP_PROPERTIES).add("cn");
descCtrl.getList(PROP_PROPERTIES).add("o");
descCtrl.getList(PROP_PROPERTIES).add("ou");
descCtrl.getList(PROP_PROPERTIES).add("manager");	
		
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>
      <wim:identifier uniqueName="o=Sales,cn=users,dc=yourco,dc=com"/>
    </wim:entities>
    <wim:controls xsi:type="wim:DescendantControl" level="0">
      <wim:properties>uid</wim:properties>
      <wim:properties>cn</wim:properties>
      <wim:properties>o</wim:properties>
      <wim:properties>ou</wim:properties>
      <wim:properties>manager</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:OrgContainer">
      <wim:identifier externalName="o=Sales,cn=users,dc=yourco,dc=com" 
                      repositoryId="LDAP1"
                      uniqueId="eab85abb-9d29-40f1-b502-36c051d3ee96" 
                      uniqueName="o=Sales,cn=users,dc=yourco,dc=com"/>
      <wim:children 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:ou>CA</wim:ou>
      </wim:children>
      <wim:children xsi:type="wim:PersonAccount">
        <wim:identifier externalId="e7db8c0e-d2b3-43fe-be14-1475125606f4" 
                        externalName="uid=SalesPerson1,ou=CA,o=Sales,cn=users,dc=yourco,dc=com"
                        repositoryId="LDAP1" 
                        uniqueName="uid=SalesPerson1,ou=CA,o=Sales,cn=users,dc=yourco,dc=com"/>
        <wim:uid>SalesPerson1</wim:uid>
        <wim:cn>Sales Person1</wim:cn>
        <wim:manager externalId="5e846c20-a1b4-4bfc-bce2-1f841d762f9a" 
                     externalName="uid=SalesManager,cn=users,dc=yourco,dc=com"
                     repositoryId="LDAP1" 
                     uniqueName="uid=SalesManager,cn=users,dc=yourco,dc=com"/>
      </wim:children>
      <wim:children xsi:type="wim:OrgContainer">
        <wim:identifier externalId="70dd624d-6eb0-4fdf-8338-3ae4090b1c6f" 
                        externalName="ou=US,o=Sales,cn=users,dc=yourco,dc=com"
                        repositoryId="LDAP1" 
                        uniqueName="ou=US,o=Sales,cn=users,dc=yourco,dc=com"/>
        <wim:ou>US</wim:ou>
      </wim:children>
      <wim:children xsi:type="wim:PersonAccount">
        <wim:identifier externalId="13ae346f-1e4c-40cd-8896-1c7f0b2b3079" 
                        externalName="uid=SalesPerson3,ou=US,o=Sales,cn=users,dc=yourco,dc=com"
                        repositoryId="LDAP1" 
                        uniqueName="uid=SalesPerson3,ou=US,o=Sales,cn=users,dc=yourco,dc=com"/>
        <wim:uid>SalesPerson3</wim:uid>
        <wim:cn>Sales Person3</wim:cn>
        <wim:manager externalId="5e846c20-a1b4-4bfc-bce2-1f841d762f9a" 
                     externalName="uid=SalesManager,cn=users,dc=yourco,dc=com"
                     repositoryId="LDAP1" 
                     uniqueName="uid=SalesManager,cn=users,dc=yourco,dc=com"/>
      </wim:children>
      <wim:children xsi:type="wim:PersonAccount">
        <wim:identifier externalId="a2d1be42-212e-44f0-8396-0bfc2d7d346d" 
                        externalName="uid=SalesPerson4,ou=US,o=Sales,cn=users,dc=yourco,dc=com"
                        repositoryId="LDAP1" 
                        uniqueName="uid=SalesPerson4,ou=US,o=Sales,cn=users,dc=yourco,dc=com"/>
        <wim:uid>SalesPerson4</wim:uid>
        <wim:cn>Sales Person4</wim:cn>
      </wim:children>
      <wim:children xsi:type="wim:PersonAccount">
        <wim:identifier externalId="a3f9e8a1-117a-4252-840f-6d0cb079a7fb" 
                        externalName="uid=SalesPerson2,ou=CA,o=Sales,cn=users,dc=yourco,dc=com"
                        repositoryId="LDAP1" 
                        uniqueName="uid=SalesPerson2,ou=CA,o=Sales,cn=users,dc=yourco,dc=com"/>
        <wim:uid>SalesPerson2</wim:uid>
        <wim:cn>Sales Person2</wim:cn>
        <wim:manager externalId="5e846c20-a1b4-4bfc-bce2-1f841d762f9a" 
                     externalName="uid=SalesManager,cn=users,dc=yourco,dc=com"
                     repositoryId="LDAP1" 
                     uniqueName="uid=SalesManager,cn=users,dc=yourco,dc=com"/>
      </wim:children>
    </wim:entities>
  </wim:Root>
</sdo:datagraph>
OrganizationUnit CA 及其子代 SalesPerson1 和 SalesPerson2、OrganizationUnit US 及其子代、SalesPerson3 和 SalesPerson4,以及 OrganizationUnit Europe 作为 OrgContainer 销售人员的后代返回。

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



使用条款 | 反馈