【发布时间】:2012-06-22 15:35:51
【问题描述】:
我使用一个函数来访问一个配置文件:
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;
}
在另一种方法中,我使用这个函数来获取文档:
Document wDoc = this.lookupDoc(key1);
if (wdoc != null) {
// do things with the document
wdoc.recycle();
}
我应该在回收 Document 对象时回收 Database 和 View 对象吗?还是应该在函数返回 Document 之前回收它们?
【问题讨论】:
-
除了 Tim 的出色回应之外,还有一条评论:检索特定文档的(更快)方法是使用 db.getDocumentByUNID() 调用。因此,如果您需要多次检索同一个文档,在第一次调用时,您可以从视图中检索它并将其 UNID 存储在私有变量中。在随后的调用中,您可以使用该 UNID 来检索它。
-
@Mark:一旦读取文档,我已经在适当的范围变量中实现了数据缓存,因此在范围变量消失之前很少需要重新读取文档......在某些情况下,作用域变量中的信息包括 UNID,以便尽可能快地重新访问文档。 /新人
标签: xpages