Class DeleteRequest

All Implemented Interfaces:
ProtocolOp, ReadOnlyDeleteRequest, ReadOnlyLDAPRequest, Serializable

This class implements the processing necessary to perform an LDAPv3 delete operation, which removes an entry from the directory. A delete request contains the DN of the entry to remove. It may also include a set of controls to send to the server. DeleteRequest objects are mutable and therefore can be altered and re-used for multiple requests. Note, however, that DeleteRequest objects are not threadsafe and therefore a single DeleteRequest object instance should not be used to process multiple requests at the same time.

Example

The following example demonstrates the process for performing a delete operation:
 DeleteRequest deleteRequest =
      new DeleteRequest("cn=entry to delete,dc=example,dc=com");
 LDAPResult deleteResult;
 try
 {
   deleteResult = connection.delete(deleteRequest);
   // If we get here, the delete was successful.
 }
 catch (LDAPException le)
 {
   // The delete operation failed.
   deleteResult = le.toLDAPResult();
   ResultCode resultCode = le.getResultCode();
   String errorMessageFromServer = le.getDiagnosticMessage();
 }
 
See Also:
  • Constructor Details

    • DeleteRequest

      Creates a new delete request with the provided DN.
      Parameters:
      dn - The DN of the entry to delete. It must not be null.
    • DeleteRequest

      public DeleteRequest(@NotNull String dn, @Nullable Control[] controls)
      Creates a new delete request with the provided DN.
      Parameters:
      dn - The DN of the entry to delete. It must not be null.
      controls - The set of controls to include in the request.
    • DeleteRequest

      Creates a new delete request with the provided DN.
      Parameters:
      dn - The DN of the entry to delete. It must not be null.
    • DeleteRequest

      public DeleteRequest(@NotNull DN dn, @Nullable Control[] controls)
      Creates a new delete request with the provided DN.
      Parameters:
      dn - The DN of the entry to delete. It must not be null.
      controls - The set of controls to include in the request.
  • Method Details

    • getDN

      @NotNull public String getDN()
      Retrieves the DN of the entry to delete.
      Specified by:
      getDN in interface ReadOnlyDeleteRequest
      Returns:
      The DN of the entry to delete.
    • setDN

      public void setDN(@NotNull String dn)
      Specifies the DN of the entry to delete.
      Parameters:
      dn - The DN of the entry to delete. It must not be null.
    • setDN

      public void setDN(@NotNull DN dn)
      Specifies the DN of the entry to delete.
      Parameters:
      dn - The DN of the entry to delete. It must not be null.
    • getProtocolOpType

      public byte getProtocolOpType()
      Retrieves the BER type for this protocol op.
      Specified by:
      getProtocolOpType in interface ProtocolOp
      Returns:
      The BER type for this protocol op.
    • writeTo

      public void writeTo(@NotNull ASN1Buffer buffer)
      Writes an ASN.1-encoded representation of this LDAP protocol op to the provided ASN.1 buffer. This method is intended for internal use only and should not be used by third-party code.
      Specified by:
      writeTo in interface ProtocolOp
      Parameters:
      buffer - The ASN.1 buffer to which the encoded representation should be written.
    • encodeProtocolOp

      Encodes the delete request protocol op to an ASN.1 element.
      Specified by:
      encodeProtocolOp in interface ProtocolOp
      Returns:
      The ASN.1 element with the encoded delete request protocol op.
    • process

      @NotNull protected LDAPResult process(@NotNull LDAPConnection connection, int depth) throws LDAPException
      Sends this delete request to the directory server over the provided connection and returns the associated response.
      Specified by:
      process in class LDAPRequest
      Parameters:
      connection - The connection to use to communicate with the directory server.
      depth - The current referral depth for this request. It should always be one for the initial request, and should only be incremented when following referrals.
      Returns:
      An LDAP result object that provides information about the result of the delete processing.
      Throws:
      LDAPException - If a problem occurs while sending the request or reading the response.
    • responseReceived

      Throws:
      LDAPException
    • getLastMessageID

      public int getLastMessageID()
      Retrieves the message ID for the last LDAP message sent using this request.
      Specified by:
      getLastMessageID in class LDAPRequest
      Returns:
      The message ID for the last LDAP message sent using this request, or -1 if it no LDAP messages have yet been sent using this request.
    • getOperationType

      Retrieves the type of operation that is represented by this request.
      Specified by:
      getOperationType in class LDAPRequest
      Returns:
      The type of operation that is represented by this request.
    • duplicate

      Creates a new instance of this LDAP request that may be modified without impacting this request.
      Specified by:
      duplicate in interface ReadOnlyDeleteRequest
      Specified by:
      duplicate in interface ReadOnlyLDAPRequest
      Returns:
      A new instance of this LDAP request that may be modified without impacting this request.
    • duplicate

      Creates a new instance of this LDAP request that may be modified without impacting this request. The provided controls will be used for the new request instead of duplicating the controls from this request.
      Specified by:
      duplicate in interface ReadOnlyDeleteRequest
      Specified by:
      duplicate in interface ReadOnlyLDAPRequest
      Parameters:
      controls - The set of controls to include in the duplicate request.
      Returns:
      A new instance of this LDAP request that may be modified without impacting this request.
    • toLDIFChangeRecord

      Retrieves an LDIF delete change record with the contents of this delete request.
      Specified by:
      toLDIFChangeRecord in interface ReadOnlyDeleteRequest
      Returns:
      An LDIF delete change record with the contents of this delete request.
    • toLDIF

      @NotNull public String[] toLDIF()
      Retrieves a string array whose lines contain an LDIF representation of the corresponding delete change record.
      Specified by:
      toLDIF in interface ReadOnlyDeleteRequest
      Returns:
      A string array whose lines contain an LDIF representation of the corresponding delete change record.
    • toLDIFString

      Retrieves an LDIF string representation of this delete request.
      Specified by:
      toLDIFString in interface ReadOnlyDeleteRequest
      Returns:
      An LDIF string representation of this delete request.
    • toString

      public void toString(@NotNull StringBuilder buffer)
      Appends a string representation of this request to the provided buffer.
      Specified by:
      toString in interface ProtocolOp
      Specified by:
      toString in interface ReadOnlyLDAPRequest
      Specified by:
      toString in class LDAPRequest
      Parameters:
      buffer - The buffer to which to append a string representation of this request.
    • toCode

      public void toCode(@NotNull List<String> lineList, @NotNull String requestID, int indentSpaces, boolean includeProcessing)
      Appends a number of lines comprising the Java source code that can be used to recreate this request to the given list.
      Specified by:
      toCode in interface ReadOnlyLDAPRequest
      Parameters:
      lineList - The list to which the source code lines should be added.
      requestID - The name that should be used as an identifier for the request. If this is null or empty, then a generic ID will be used.
      indentSpaces - The number of spaces that should be used to indent the generated code. It must not be negative.
      includeProcessing - Indicates whether the generated code should include code required to actually process the request and handle the result (if true), or just to generate the request (if false).