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



Aug 29, 2011, 6:16 PM
66 Posts

Where to keep JDBC connection object to be shared in application?

  • Category: Other
  • Platform: All
  • Release: 8.5.3
  • Role:
  • Tags:
  • Replies: 4
 I would like to use H2 database in embeded mode in xPages app. Where to keep connection object to be shared? In standard JAVA app I would initialize this in Servlet listener or use spring singleton or something similar. What is equivalent in xPages? Is it application scope variable/object?  If so, how to handle the connection to be released/closed properly when application unload or reload? I havent found any info about some application unloading or reloading events... Do you have some suitable pattern for such scenario? 
Aug 30, 2011, 2:14 PM
25 Posts
Re: Where to keep JDBC connection object to be shared in application?
 David,
 
In the designer client, open up the package explorer by navigating to  Window\Show Eclipse Views and in the resulting dialog pick Package Explorer in the Java section. Once Package Explorer is open, navigate to your nsf and open that up and navigate to the WebContent\WEB-INF folder. Create a new folder here called lib, then place your jar file here. This will make it available to the server and your application. I don't remember off the top of my head if I had to include that in the build path, so if it's still not available to your application you may want to look there.
 
You can also check out the article I did on connecting to MySQL with an XPage application here Sharing Data between MySQL and Lotus Domino
 
HTH 
Keith 
Aug 30, 2011, 6:24 PM
66 Posts
Re: Where to keep JDBC connection object to be shared in application?
 Thank you for you reply. I know how to put libraries together but not sure how properly define connection object to avoid opening and closing connection to SQL in every request. This technique would be very inefficient. I would rather  use some connection pooling. Managed bean with application scope should be good place but not sure how application(xpages) unloading works regarding to managed bean closing ... beacuse this should also close openned database connections.
Sep 1, 2011, 1:59 AM
25 Posts
Re: Where to keep JDBC connection object to be shared in application?
 Ah, I see. OK, I would attempt to set this up in a sessionScope bean and then it should be available everywhere for that particular user. However, I'm not sure how you would ensure the connection got closed when the session had expired. Or even better would be a viewScope bean and then close the connection via an RPC call in the onWindowUnload event or something to that effect as long as the viewScope was still available at that time.  
 
Of course I haven't tested either one of those scenarios so I'm not sure of their feasibility. Personally, I've just always started a new connection for each request. I'm sure in a heavily used application that probably isn't the best way to do things, but it does work pretty reliably. 
 
HTH 
Keith 
Sep 1, 2011, 5:12 PM
54 Posts
Re: Where to keep JDBC connection object to be shared in application?
Domino 8.5.3 will (as far as I know) support connection pooling out of the box (incl. JNDI support). I know this is in 8.5.3 and you don't have that one yet, but it is good to know.
 
I'm afraid that there's no way you can share the connection. The scope variables (applicationScope) might work, but don't know about the timesouts and closing / reopening the connection. Is it 100% safe? I think someone from IBM could know this for sure.
 
If you find out something usefull, keep the forum posted. 
 

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