The technique for building a better Notes Java API
This is a followup post to yesterdays post titled Want to join me in building a better Notes Java API? and here I'll show just how easy it was to build the wrapper API.
Below is the code from the implementation of the getView(String) method of the lotus.domino.Database interface. As you can see the central element is to get the current thread the method is called on and the thread used for Notes data access. If we're not on the Notes thread execute a blocking request and return the result. If we're on the Notes thread simply go ahead and do the operation. Simple right?
The most difficult part of all this was that I had to write my own Notes thread handler (equivalent of NotesPlatform) as there isn't a method for doing a blocking request on the Notes thread in NotesPlatform class supplied by Lotus.
public View getView(final String name) throws NotesException {
// get threads
Thread curThread = Thread.currentThread();
Thread notesThread = NotesPlatform.getInstance().getThread();
// decide if we're in the Notes thread or not
if (curThread != notesThread) {
// we're not on the Notes thread so wrap
final Holder h = new Holder();
NotesPlatform.getInstance().syncExec(new Runnable() {
public void run() {
try {
h.value = DatabaseWrapper.this.db.getView(name);
} catch (NotesException e) {
h.throwable = e;
}
}
});
if (null != h.throwable) {
throw (NotesException)h.throwable;
} else {
return new ViewWrapper((View)h.value);
}
} else {
// we're on the thread so do request
return new ViewWrapper(DatabaseWrapper.this.db.getView(name));
}
}





