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.