Use the sample code snippet and data graph to perform a search based on the value of an extended property.
The following sample code snippet and data graph show how to use a search base to search for entities with the value of an extended property age as the search criteria.
Ensure that you have read the information and completed the steps described in the topic, Programming prerequisites, which also lists the valid syntax for property data types.
You must have entities with extended properties populated in different search bases. For sample code on how to create extended properties, see the following topics
Add the following code snippet to your application code and replace the variables with the actual values that you want to use.
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();
}
}
You can validate the search results by verifying that the entities belong to the search base specified, such as o=defaultWIMFileBasedRealm for a default file repository search or dc=yourco,dc=com for the LDAP repository search.
Output data graph for using a search base to search for entities based on the value of an extended property:
<?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>