JAVA/CORBA CLASSES


Examples: getModifiedDocuments method
This agent gets all modified data documents in the current database since the last time the agent ran. A profile document saves the database end time for each getModifiedDocuments operation.

import lotus.domino.*;
import java.util.Vector;

public class JavaAgent extends AgentBase {

 public void NotesMain() {

   try {
     Session session = getSession();
     AgentContext agentContext = session.getAgentContext();

     // (Your code goes here)
     Database db = agentContext.getCurrentDatabase();
     
     // Check UntilTime in profile document
     Document profile = db.getProfileDocument("Profile", null);
     DateTime untilTime = null;
     DocumentCollection dc = null;
     if (profile.hasItem("UntilTime")) {
       // Start processing from UntilTime
       Vector untilTimeVector =
         profile.getItemValueDateTimeArray("UntilTime");
       untilTime = (DateTime)untilTimeVector.firstElement();
       dc = db.getModifiedDocuments(
         untilTime, Database.DBMOD_DOC_DATA);
     }
     else {
       // First time through get all documents
       dc = db.getModifiedDocuments(
         null, Database.DBMOD_DOC_DATA);
     }
     
     if (dc.getCount() > 0) {
       // Display LastModified and Subject from each document
       Document doc = dc.getFirstDocument();
       while(doc != null) {
         System.out.println(
           doc.getLastModified() + " " +
           doc.getItemValueString("Subject"));
         doc = dc.getNextDocument(doc);
       }
     }
     else {
       // If nothing modified since last time
       if (profile.hasItem("UntilTime"))
         System.out.println("No documents modified since " +
           untilTime.getLocalTime());
       else
         System.out.println("No documents modified since beginning");
     }
     
     // Write UntilTime back to profile document
     profile.replaceItemValue("UntilTime", dc.getUntilTime());
     profile.save(true, true, true);

   } catch(Exception e) {
     e.printStackTrace();
   }
 }
}

See Also