我使用一个函数来访问配置文档:
private Document lookupDoc(String key1) {
try {
Session sess = ExtLibUtil.getCurrentSession();
Database wDb = sess.getDatabase(sess.getServerName(), this.dbname1);
View wView = wDb.getView(this.viewname1);
Document wDoc = wView.getDocumentByKey(key1, true);
this.debug("Got a doc for key: [" + key1 + "]");
return wDoc;
} catch (NotesException ne) {
if (this.DispLookupErrors)
ne.printStackTrace();
this.lastErrorMsg = ne.text;
this.debug(this.lastErrorMsg, "error");
}
return null;
}
Run Code Online (Sandbox Code Playgroud)
在另一种方法中,我使用此函数来获取文档:
Document wDoc = this.lookupDoc(key1);
if (wdoc != null) {
// do things with the document
wdoc.recycle();
}
Run Code Online (Sandbox Code Playgroud)
当我回收Document对象时,我应该回收数据库和View对象吗?或者应该在函数返回Document之前回收它们?
xpages ×1