Posted By

tjg1959 on 10/03/13


Tagged

ldap


Versions (?)

LDAP Subtree Delete


 / Published in: Java
 

How to delete a base object and all of its' subordinates using the UnboundID LDAP SDK.

  1. /**
  2.   * Deletes the branch specified by {@code dnToDelete}. if any response
  3.   * controls are attached to the delete response, they are handled by
  4.   * the {@code controlHandlers}. The {@code responseTimeout} specifies
  5.   * the maximum time spent processing the delete.
  6.   *
  7.   * @param ldapConnection connection to the LDAP server.
  8.   * @param dnToDelete the branch to delete. {@code dnToDelete} is not permitted
  9.   * to be {@code null}.
  10.   * @param responseTimeout the maximum time spent processing the request in
  11.   * milliseconds.
  12.   * @param controlHandlers handles any response controls.
  13.   */
  14. public void deleteTree(LDAPConnection ldapConnection,
  15. DN dnToDelete,
  16. int responseTimeout,
  17. ControlHandler[] controlHandlers)
  18. {
  19.  
  20. ensureNotNull(ldapConnection,dnToDelete);
  21.  
  22. /*
  23.   * Construct a delete request and add the subtree delete request
  24.   * control to the request.
  25.   */
  26. final DeleteRequest deleteRequest = new DeleteRequest(dnToDelete);
  27. final SubtreeDeleteRequestControl control =
  28. new SubtreeDeleteRequestControl();
  29. deleteRequest.addControl(control);
  30. deleteRequest.setResponseTimeoutMillis(responseTimeout);
  31.  
  32. /*
  33.   * Delete the specified request, and handle any response controls
  34.   * that were included by the server in the response.
  35.   */
  36. LDAPResult ldapResult;
  37. try
  38. {
  39. ldapResult = ldapConnection.delete(deleteRequest);
  40. }
  41. catch(final LDAPException exception)
  42. {
  43. fireLdapExceptionListener(ldapConnection,exception);
  44. return;
  45. }
  46. if(controlHandlers != null)
  47. {
  48. for(final Control responseControl : ldapResult.getResponseControls())
  49. {
  50. for(final ControlHandler h : controlHandlers)
  51. {
  52. h.handleResponseControl(this,responseControl);
  53. }
  54. }
  55. }
  56. }

Report this snippet  

You need to login to post a comment.