0
votes

I'm using the Domino Java API to query a database on a remote server. The server is processing the documents, and I'm trying to get their status. However, when I create the session, and run a query, even if I loop and check again every 30 seconds, my code will never see those documents update- it only sees the status at the time it created the first query. I have a few more loops, but the basic code outline is below- can someone tell me what I'm doing wrong?

Is there a way to update the current Database view from the Java API? The databases are not full text indexed, and cannot be due to outside constraints.

public static boolean queryDatabase(String adminFilePath, String targetItem)
    NotesThread.sinitThread();
    Session session =NotesFactory.createSession((String) null, (String) null, (String) null);
    Registration Reg = s.createRegistration();
    Reg.switchToID(adminFilePath, password);
    DocumentCollection dc = getRecentDocsFromDB(session);
    numResults=dc.getCount();
    if (numResults > 0) {
        //loop through documents to find what I'm looking for
        //if the documents contain "done", finish, else:
        Thread.sleep(60000);
        session.recycle();
        session=SessionFactory.newSession(adminFilePath, "password");
        dc = getRecentDocsFromDB(session);
        found = searchDocumentCollection(dc, targetItem); 
        //this is essentially doing the same thing again- create a session, get docs made in the
        //past day or so, and loop through looking for the ones I need. 
}

private static DocumentCollection getRecentDocsFromDB(Session session){
    Database db = SessionFactory.openDatabase(session, server, database);
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.DATE, -1);
    DateTime dt = session.createDateTime(cal);
    DocumentCollection dc = searchNotesDBUsingDate(session, db,"Form=\"event\"", dt);
}

public static DocumentCollection searchNotesDBUsingDate(Session session,
        Database database, String query, DateTime dt) throws NotesException {
    DocumentCollection dc = null;
    dc = database.search(query, dt);
    return dc;
}

I've updated the code with a session.recycle() call. (Thanks for the suggestion!) In testing, it's not having any effect- the code is working for the first document, but then never sees a second document being called. It's insane, because it seems to be caching the session anyway!

1
Am I being stupid, or do you never update numResults in your loop?Ordous
Thats my fault- didn't copy and paste that part of the code, just left a comment to say there's a loop. Inside that if statement is a while loop which re-runs everything. The numResults, if it's zero, says that there aren't any documents created in the last 24 hours- which is an error scenario for me anyway.scarecrow198504
I'm wondering, are you really creating a new session? I.e. are you closing the old session properly, or is the framework providing you with the same session because there already is a valid one?Ordous
I'm wondering the same thing- there's no session.destroy or session.close method, so is there a valid way to do this? I mean, as a hack, I could set session=null. But I'm still unsure if Domino would properly destroy it.scarecrow198504
Well there is recycle, but I'm really grasping at straws here - my experience is with Hibernate and Spring.Ordous

1 Answers

0
votes

I tried to reproduce the problem, but I wasn't able to. In my tests, Database.search() always returns the latest documents -- even if a document is added after the database is opened. I suspect there is a subtle problem in your code (perhaps what Richard Schwartz suggested in his comment).

It may or may not be relevant, but I wasn't able to compile your version of getRecentDocsFromDB() because I don't have a SessionFactory class. My version just uses Session.getDatabase() like so:

private static DocumentCollection getRecentDocsFromDB(Session session, String server, String database) throws NotesException {
    Database db = session.getDatabase(server, database);
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.DATE, -1);
    DateTime dt = session.createDateTime(cal);
    DocumentCollection dc = searchNotesDBUsingDate(session, db,"Form=\"event\"", dt);
    return dc;
}

Also, as Richard mentioned, you are not reading a view. You are searching the database for all documents created (or modified) by the "event" form in the last 24 hours. And you are doing this in a tight loop. Even if you get it to work, this approach isn't the best for production. You might want to research the use of lotus.domino.View and lotus.domino.ViewNavigator.