LDAP: The MultiUpdateExtendedRequest


The UnboundID Directory Server supports an extended request called the MultiUpdateExtendedRequest. This extended request packages multiple updates in a single request and provides control over the behavior of the server when errors arise during the processing of the extended request. Examine the following code sample:

// exception handling is not shown
Entry first = LDAPTestUtils.generateUserEntry("first","ou=people," +
        "dc=example,dc=com","first","last","password");

Entry second = LDAPTestUtils.generateUserEntry("second","ou=people," +
        "dc=example,dc=com","first","last","password");

final String[] dc = {
  "dn: dc=example,dc=com",
  "objectClass: top",
  "objectClass: extensibleObject",
  "objectClass: domain",
  "dc: example",
};

final String[] people = {
  "dn: ou=people,dc=example,dc=com",
  "objectClass: top",
  "objectClass: organizationalUnit",
  "ou: people",
};

final MultiUpdateErrorBehavior errorBehavior =
  MultiUpdateErrorBehavior.CONTINUE_ON_ERROR;
final MultiUpdateExtendedRequest req =
  new MultiUpdateExtendedRequest(errorBehavior,
           new AddRequest(dc),
           new AddRequest(people),
           new AddRequest(first),
           new AddRequest(second));
MultiUpdateExtendedResult result = (MultiUpdateExtendedResult)
  ldapConnection.processExtendedOperation(req);
if(result.getResultCode().equals(ResultCode.SUCCESS)) {
  switch(result.getChangesApplied()) {
  case NONE:
    // There were no changes applied.
    break;
  case ALL:
    // All parts of the update succeeded.
    break;
  case PARTIAL:
    // At least one update succeeded, and at least one failed.
    break;
  }
}

The code sample above attempts to create two entries and the superiors of those entries:

  • dc=example,dc=com
  • ou=people,dc=example,dc=com
  • cn=first,ou=people,dc=example,dc=com
  • cn=second,ou=people,dc=example,dc=com

The error behavior is set to CONTINUE_ON_ERROR which causes the requests to continue when any of them fails. This acts like the –continueOnError flag to ldapmodify, or -c in the legacy OpenLDAP ldapmodify tool.

About Terry Gardner

Terry Gardner was a leading directory services architect with experience with many large scale directory services installations and messaging server installations, and was a Subject Matter Expert in the field of Directory Services and Solaris (operating system) performance. Mr. Gardner also participated in the open-source software community. Mr. Gardner passed away in December, 2013.
This entry was posted in Java, LDAP, UnboundID, UnboundID LDAP SDK and tagged , . Bookmark the permalink.

Leave a comment