This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal



Mar 21, 2011, 10:31 AM
8 Posts

NotesDatabase() Object in scoped variables

  • Category: Server Side JavaScript
  • Platform: All
  • Release: 8.5.2
  • Role: Developer
  • Tags: scoped variable,sessionScope,NotesDatabase,Object
  • Replies: 5
Hi,
 
I want to save a NotesDatabase() Object in a scoped variable. I did not found a example for that. Actually I read that this is not possible, only Strings/Numbers.
 
Really?
 
I tried this here, and this works because I set the sessionscope.

sessionScope.databases = new java.util.HashMap();
var view:NotesView = database.getView("configuration)");
var doc:NotesDocument = view.getFirstDocument();
var db:NotesDatabase;
try{
//try to init the db
db = session.getDatabase(doc.getItemValueString("server"), doc.getItemValueString("path"));
}catch(e){
//cant get the db
return null;
}
sessionScope.databases.put("config",db);
print (sessionScope.databases.config); //correct here
return sessionScope.databases.configDB; 
 
If I do
 
print (sessionScope.databases.configDB
 
next time, it says "null".  
 
Greetings, 
Michael 

Mar 21, 2011, 11:56 AM
8 Posts
Re: NotesDatabase() Object in scoped variables
  Well, this solution is better than nothing:
 
if (sessionScope.databases == null || sessionScope.databases.configDB == ""){ 
 
[...] 
 
}
 
return sessionScope.databases.configDB; 
 
Mar 21, 2011, 12:35 PM
5 Posts
Re: NotesDatabase() Object in scoped variables
 You can't put Domino objects into the scope variables because the Domino Objects are recycled by the server.
 
I think I understand why you are trying to do it, you have a config databases that contains lookup tables etc. and you want to put them it into the scope for easy assess and to cut down on open DB handles.
 
If this is what your doing then I'd suggest a serialized function that reads the values into an application scope ( so all users of the app can benefit ). the function would create a hashmap, put all the lookup vales into it and then return it as an array to the caller. The next time the function is called it checks to see if the hashmap exists and if it does it just returns it without having to open the config database. Then you can add some sort of expiry system to the function that checks to see if the values in the hashmap are older then, say 60 minutes, then update the hashmap before returning it.
 
Hope that helps. 
Mar 21, 2011, 1:48 PM
8 Posts
Re: NotesDatabase() Object in scoped variables
 It is too much what I need from the configuration database, but for some special config values your solution sounds good. Thank you :-) 
Apr 22, 2011, 3:36 PM
135 Posts
Re: NotesDatabase() Object in scoped variables
That's a pity. It would make scope variables much more useful if you could store setup documents etc. Scope variables are destroyed any way soon (the time depending on which scope you choose) and I don't understand why Domino wants to destroy them immediately. Hopefully this will be fixed at some point.
Mar 23, 2011, 7:56 PM
1 Posts
Re: NotesDatabase() Object in scoped variables
Hi, as Declan says I'm using a central config database to store all my database paths.
I collect these information in a profile document and I read this document and put them into scope variables when loading the application.
In my xPage application I have many views and links to different databases and I use computed  values to fetch a view.
The example script below works for Notes client and web client
 
 
var cserv:NotesName= session.createName(database.getServer());
var serv=cserv.getCommon();
var db=sessionScope.get("activityDb")
if(serv=="" ||serv==null){
    return db
}else{
    return serv +"!!"+db
}
 

This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal