Express (Distributed operating systems), v8.0 > Secure applications and their environment > Authenticate users > Select a registry or repository > Manage realms in a federated repository > Virtual member manager > Develop with virtual member manager > Integrate virtual member manager into the application > Program tasks


Performing a paged search

Use the search(DataObject) method and PageControl DataObject to set the number of items returned at any one time during a search.


About this task

The page size is passed in from PageControl. A cookie used for subsequent call is returned from PageResponseControl. If you decide not to continue get the paged results, set the page size to 0 with the cookie. The virtual member manager server then cleans the remaining results.

To use the paged search function in a search, add the following sample code to the application code and replace the variables with the actual values that you want to use for this entity:

public static Map getControlMap(DataGraph dataGraph)
{
        Map ctrlMap = new HashMap();
        List controls = dataGraph.getRootObject().getDataObject(SchemaConstants.DO_ROOT).getList(
                SchemaConstants.DO_CONTROLS);
        if (controls != null) {
            for (int i = 0; i
< controls.size(); i++) {
                DataObject control = (DataObject) controls.get(i);
                String type = control.getType().getName();
                if (ctrlMap.get(type) == null) {
                    ctrlMap.put(type, control);
                }
            }
        }
        return ctrlMap;

DataObject root = SDOHelper.createRootDataObject();

  DataObject searchCtrl = root.createDataObject(DO_CONTROLS, WIM_NS_URI, DO_SEARCH_CONTROL);
  searchCtrl.getList(PROP_PROPERTIES).add("uid");
  searchCtrl.getList(PROP_PROPERTIES).add("sn");
  searchCtrl.setString(PROP_SEARCH_EXPRESSION, "//entities[@xsi:type='PersonAccount' and uid='SalesPerson*']");
  searchCtrl.getList(PROP_SEARCH_BASES).add("o=Sales,cn=users,dc=yourco,dc=com");
  DataObject pageCtrl = root.createDataObject(DO_CONTROLS, WIM_NS_URI, DO_PAGE_CONTROL);

  pageCtrl.setInt(PROP_SIZE, 2);
  boolean first = true;
  byte[] cookie = null;
  DataObject returnDO = null;
  int pageCount = 0;
  while (first || cookie != null) {
   first = false;
   pageCount++;
   if (cookie != null)
   {
    pageCtrl.setBytes(PROP_COOKIE, cookie);
    pageCtrl.setInt(PROP_SIZE, 3);
    searchCtrl.delete();
   }
   SDOUtils.printDataGraph(INPUT_DATAGRAPH, root);
   returnDO = service.search(root);
   SDOUtils.printDataGraph(OUTPUT_DATAGRAPH, returnDO);
   List entities = returnDO.getList(SchemaConstants.DO_ENTITIES );
   Map ctrlMap = getControlMap(returnDO);
   DataObject responseCtrl = (DataObject)ctrlMap.get(DO_PAGE_RESPONSE_CONTROL);
   if (responseCtrl != null) {
    cookie = responseCtrl.getBytes("cookie");
   } else {
    cookie = null;
   }
  }


Sample input and output data graphs

For this particular example the input data graph is:

<?xml version="1.0" encoding="UTF-8"?>
<sdo:datagraph xmlns:xsi="//www.w3.org/2001/XMLSchema-instance"
    xmlns:sdo="commonj.sdo"
    xmlns:wim="//www.ibm.com/websphere/wim">
<wim:Root>
<wim:controls xsi:type="wim:SearchControl"
                expression="//entities[@xsi:type='PersonAccount' and uid='SalesPerson*']">
<wim:properties>uid
</wim:properties>
<wim:properties>sn
</wim:properties>
<wim:searchBases>o=Sales,cn=users,dc=yourco,dc=com
</wim:searchBases>
</wim:controls>
<wim:controls xsi:type="wim:PageControl" size="2"/>
</wim:Root>
</sdo:datagraph> 
The resulting output data graph for the first call in this example is:
<?xml version="1.0" encoding="UTF-8"?>
<sdo:datagraph xmlns:xsi="//www.w3.org/2001/XMLSchema-instance"
               xmlns:sdo="commonj.sdo"
               xmlns:wim="//www.ibm.com/websphere/wim">
<wim:Root>
<wim:entities xsi:type="wim:PersonAccount">
<wim:identifier externalName="uid=SalesPerson3,ou=US,o=Sales,cn=users,dc=yourco,dc=com"
                      repositoryId="LDAP1"
                      uniqueId="13ae346f-1e4c-40cd-8896-1c7f0b2b3079"
                      uniqueName="uid=SalesPerson3,ou=US,o=Sales,cn=users,dc=yourco,dc=com"/>
<wim:uid>SalesPerson3
</wim:uid>
<wim:sn>SalesPerson3Sn
</wim:sn>
</wim:entities>
<wim:entities xsi:type="wim:PersonAccount">
<wim:identifier externalName="uid=SalesPerson2,ou=CA,o=Sales,cn=users,dc=yourco,dc=com"
                      repositoryId="LDAP1"
                      uniqueId="a3f9e8a1-117a-4252-840f-6d0cb079a7fb"
                      uniqueName="uid=SalesPerson2,ou=CA,o=Sales,cn=users,dc=yourco,dc=com"/>
<wim:uid>SalesPerson2
</wim:uid>
<wim:sn>SalesPerson2Sn
</wim:sn>
</wim:entities>
<wim:controls xsi:type="wim:PageResponseControl"
                  cookie="57494D53656172636843616368654E616D6574696D653A31313239353538343136383636"
        totalSize="4"/>
</wim:Root>
</sdo:datagraph> 

The input data graph for the second call in this example is:

<?xml version="1.0" encoding="UTF-8"?>
<sdo:datagraph xmlns:xsi="//www.w3.org/2001/XMLSchema-instance"
               xmlns:sdo="commonj.sdo"
               xmlns:wim="//www.ibm.com/websphere/wim">
<wim:Root>
<wim:controls xsi:type="wim:PageControl"
             cookie="57494D53656172636843616368654E616D6574696D653A31313239353538343136383636"
        size="3"/>
</wim:Root>
</sdo:datagraph> 
The resulting output data graph for the second call in this example is:
<?xml version="1.0" encoding="UTF-8"?>
<sdo:datagraph xmlns:xsi="//www.w3.org/2001/XMLSchema-instance"
               xmlns:sdo="commonj.sdo"
               xmlns:wim="//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:uid>SalesPerson1
</wim:uid>
<wim:sn>SalesPerson1Sn
</wim:sn>
</wim:entities>
<wim:entities xsi:type="wim:PersonAccount">
<wim:identifier externalName="uid=SalesPerson4,ou=US,o=Sales,cn=users,dc=yourco,dc=com"
                      repositoryId="LDAP1"
                      uniqueId="a2d1be42-212e-44f0-8396-0bfc2d7d346d"
                      uniqueName="uid=SalesPerson4,ou=US,o=Sales,cn=users,dc=yourco,dc=com"/>
<wim:uid>SalesPerson4
</wim:uid>
<wim:sn>SalesPerson4Sn
</wim:sn>
</wim:entities>
</wim:Root>
</sdo:datagraph> 

Also see the topic, Sample code for performing a paged search with sorted results.

Parent topic: Program tasks
PageControl DataObject
PageResponseControl DataObject


Related


search method

+

Search Tips   |   Advanced Search