You are currently browsing legacy 3.0 version of documentation. Click here to switch to the newest 4.2 version.

We can help you with migration to the latest RavenDB

Contact Us Now
see on GitHub

Listeners: What are delete listeners and how to work with them?

IDocumentDeleteListener interface which needs to be implemented if a user wants to add a custom logic or an action when a delete operation is executed. The interface contains only one method that is invoked before the delete request is sent to the server:

public interface IDocumentDeleteListener {

  /**
   * Invoked before the delete request is sent to the server.
   * @param key The key.
   * @param entityInstance The entity instance.
   * @param metadata The metadata.
   */
  public void beforeDelete(String key, Object entityInstance, RavenJObject metadata);
}

Example

To prevent anyone from deleting documents we can create preventDeleteListener with can be implemented as follows:

public static class PreventDeleteListener implements IDocumentDeleteListener {
  @Override
  public void beforeDelete(String key, Object entityInstance, RavenJObject metadata) {
    throw new NotImplementedException();
  }
}