java - Managed beans and caching view lookups -
from traditional notes development learned retrieving domino objects databases , views in script not effective, , should avoided in loops.
in xpages cannot serialize domino objects , retrieve same object many times. have example retrieving project data, based on project number stored in project related documents. bean scoped applicationscope
, results cached.
public class projects{ private treemap<string, project> projectlist; public projects() { } public project getprojectinfo(string projnum) { project project = null; if (projectlist==null) { projectlist = new treemap<string,project>(); } if (projectlist.containskey(projnum)) { project = projectlist.get(projnum); } else { try { database projdb = dominoaccess.getdatabase("projects"); view v = projdb.getview("(projlookup)"); viewentry ve = v.getentrybykey(projnum); if (ve != null) { project = new project(ve); projectlist.put(projnum, project); } } catch (exception e) { } } return project; } }
when first used in example repeat, database , view objects created each document. best practice or there better ways of solving this?
i know can put projects in map @ first use, not sure if best practice regarding memory?
when use in repeat control (e.g. 30 times), use 30x @dblookup. doesn't seem efficient. do: use view navigator rapidly read projects id , unid map. instead of doing @dblookup unid map , getdocumentbyunid load it. should faster. variation - if project data isn't big: save json representation field , put view navigator. way need read view (again have 2 variation of sequentially read or search through) , field.
let me know if need clarify further