Document Locking and Java

I’m pretty new to writing Notes agents in Java and haven’t been able to find a solution to a document locking issue that I am having. My Java program walks a document collection. The first step is to check whether the document is already locked, (we can’t make changes if another user is already using the document.) The agent is scheduled to run every 5 minutes, so if the document is locked, it should just make an entry in the lock, move to the next document and try again in 5 minutes. The problem I am having is that if the document is already locked, an exception error is thrown and my program ends without finishing the document collection. Following is sample code of what I am trying to do. Any ideas how to make this work using Java?

Doc RFSdoc = dc.getFirstDocument()

While (RFSdoc != null) {

if (RFSdoc.lock() {

/* Process document and make changes

This works fine without error

Problem is when RFSdoc is unable to get lock on document

*/

} else {

// Make entry to error log and move on

}

RFSdoc = dc.getNextDocument(RFSdoc);

}

Subject: Document Locking and Java

Well, Lotus is no better at documenting which exceptions that methods may throw in Java than they are in LotusScript (Runtime errors).

The only two exceptions mentioned in document.lock() is

  1. “IsDocumentLockingEnabled in Database must be true or this method throws an exception.”

  2. “throws an exception if the administration server is not available and the second parameter is false”

Don’t you just love the specificity of “an exception”, they might as well have said “a throwable” :wink:

Anyway, this is unlikely to be the problem, or?

You did not provide a stacktrace of the exception - that might be useful, if you want us to assist your debugging.

Did you try to catch the exception and treat the exception as if lock() had returned false?

Subject: RE: Document Locking and Java

Well, I found a workaround . . .Instead of using doc.lock(), I used doc.getLockHolders(), which works good enough for now:

Vector holders = doc.getLockHolders();

if (holders.size() == 0) {

doc.lock();

// Process document

} else {

// Create error message in log and move to next document, try again later

}

I figure if there are 0 lock holders then the doc.lock() will be successful. Not the greatest solution but will work for now 'til I learn more about Java and Notes.