Verwenden Sie die Methode "create(DataObject)" zusammen mit einem asynchronen Adapter, um eine Entität zu erstellen.
Dieser Aufruftyp ist derselbe, wie der Aufruf "create person", außer, dass der Aufruf an einen Adapter weitergeleitet wird, der die Operation "create" asynchron ausführt. In diesem Beispiel wird gezeigt, wie Sie eine Entität "PersonAccount" für die Person "X" im Container "cn=users,dc=yourco,dc=com" erstellen.
try {
//create root dataobject from Virtual Member Manager Service.
DataObject root = service.createRootDataObject();
DataObject personAccount = SDOHelper.createEntityDataObject(root, null, DO_PERSON_ACCOUNT);
personAccount.set("uid", "personx");
personAccount.set("cn", "Person X");
personAccount.set("sn", "PersonXLastName");
DataObject contexts = root.createDataObject(DO_CONTEXTS);
contexts.set(PROP_KEY, VALUE_CONTEXT_REALM_KEY);
contexts.set(PROP_VALUE, "realmA");
root = service.create(root);
// Check the response for ResponseControl dataobject
// for incomplete async operation, we should receive a ticket.
String ticket = checkResponse(root);
if (ticket != null) {
// build the input DataGraph with RequestControl to check the status
root = service.createRootDataObject();
DataObject reqCtrl = SDOHelper.createControlDataObject(root, null, DO_REQUEST_CONTROL);
reqCtrl.setString(PROP_TICKET, ticket);
// wait for the completion of the async operation
DataObject retRoot = service.get(root);
while (checkResponse(retRoot) != null) {
Thread.sleep(200);
retRoot = service.get(root);
}
}
}
catch(WIMException e) {
e.printStackTrace();
}
// returns ticket if the operation is not complete
private static String checkResponse(DataObject root) {
DataObject rspCtrl = null;
String ticket = null;
List controls = root.getList(Service.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 (DO_RESPONSE_CONTROL.equals(type)) {
rspCtrl = control;
break;
}
}
}
if (rspCtrl != null) {
boolean complete = rspCtrl.getBoolean(Service.PROP_COMPLETE);
if (!complete) {
ticket = rspCtrl.getString(Service.PROP_TICKET);
}
}
return ticket;
}
<?xml version="1.0" encoding="UTF-8"?>
<sdo:datagraph xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:="http://www.w3.org/XML/1998/namespace"
xmlns:sdo="commonj.sdo"
xmlns:wim="http://www.ibm.com/websphere/wim">
<wim:Root>
<wim:contexts>
<wim:key>realm</wim:key>
<wim:value>realmA</wim:value>
</contexts>
<wim:entities xsi:type="wim:PersonAccount">
<wim:uid>personx</wim:uid>
<wim:cn>Person X</wim:cn>
<wim:sn>PersonXLastName</wim:sn>
</wim:entities>
</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:controls xsi:type="wim:ResponseControl" complete="false"
ticket="AsyncLDAP1:1113940307424:-1278154994"/>
</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:controls xsi:type="wim:RequestControl"
ticket="AsyncLDAP1:1113940307424:-1278154994"/>
</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:controls xsi:type="wim:ResponseControl" complete="false"
ticket="AsyncLDAP1:1113940307424:-1278154994"/>
</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 repositoryId="AsyncLDAP1"
uniqueName="uid=personx,cn=users,dc=yourco,dc=com"/>
</wim:entities>
<wim:controls xsi:type="wim:ResponseControl" complete="true"/>
</wim:Root>
</sdo:datagraph>