Examples: deleteDocument method

This agent subtracts a second document collection from a first collection.

Note: It is recommended that you use subtract to do this.

import lotus.domino.*;
public class JavaAgent extends AgentBase {
  public void NotesMain() {
    try {
      Session session = getSession();
      AgentContext agentContext = session.getAgentContext();
      // (Your code goes here) 
      Database db = agentContext.getCurrentDatabase();
      if (db.isFTIndexed()) db.updateFTIndex(false);
      else db.updateFTIndex(true);
      DocumentCollection dc1 = db.getAllDocuments();
      DocumentCollection dc2 = db.getAllDocuments();
      dc1.FTSearch("blue");
      dc2.FTSearch("red");
      Document tmpdoc;
      Document doc = dc2.getFirstDocument();
      while (doc != null) {
        // Make sure it's there before deleting
        if (dc1.getDocument(doc) != null)
          dc1.deleteDocument(doc);
        tmpdoc = dc2.getNextDocument(); 
        doc.recycle();
        doc = tmpdoc;
      }
      doc = dc1.getFirstDocument();
      while (doc != null) {
        System.out.println(doc.getItemValueString("Subject"));
        tmpdoc = dc1.getNextDocument(); 
        doc.recycle();
        doc = tmpdoc;
      }
    } catch(NotesException e) {
      System.out.println(e.id + " " + e.text);
      e.printStackTrace();
    }
  }
}