pipalia
pipalia

Reputation: 911

Domino Database connection for a Java bean architecture

We are moving our multi-database web application from LS to a Java beans architecture, but are struggling to decide how best to handle database connections and what scope should we use for them.

If we use sessionScope then connection to 5-6 databases per call will be created for each user. If we use a applicationScope bean for the database connection then it will remain open until the server is restarted, causing memory leaks. I understand that certain values such as System Configuration values which rarely change can be cached at applicationScope level, but I am concerned about the rest of the connections.

My question really is what's the best way to handle domino database connections (domino objects are not serializable) without affecting performance or memory leaks or automatic GC issues?

Upvotes: 2

Views: 486

Answers (2)

Simon O'Doherty
Simon O'Doherty

Reputation: 9359

As Russell mentions, there is no one way to do this and each will have their pros/cons.

There is a Wrapped Document class you can use to store Document information.

public static DominoDocument wrap(java.lang.String database,
                              lotus.domino.Database db,
                              java.lang.String parentId,
                              java.lang.String form,
                              java.lang.String computeWithForm,
                              java.lang.String concurrencyMode,
                              boolean allowDeletedDocs,
                              java.lang.String saveLinksAs)

Javadoc is here:

http://public.dhe.ibm.com/software/dw/lotus/Domino-Designer/JavaDocs/XPagesExtAPI/8.5.2/com/ibm/xsp/model/domino/wrapped/DominoDocument.html

However this just does some of the handling of recycle() in the background. So you are still going to have the same overheads generated by making/recycle() of the database objects.

The main overhead you will find is the creating the connection to the Database in your Java code. Once that connection is made, everything else is relatively faster.

I would recommend when testing this for performance that you use the XPages Toolkit. Videos on how to use it are part of the XPages Masterclass on openNTF.

http://www.openntf.org/internal/home.nsf/project.xsp?action=openDocument&name=XPages%20Masterclass

Upvotes: 1

Russell Maher
Russell Maher

Reputation: 378

This is a tough one because it deals with architecting a specific solution vs just some generic "this works better than that" advice. We have had great success architecting a consumer XPage application so that data is retrieved from additional databases. Sort of a front end with database backends but with Domino.

We use no applicationScope anything because there is nothing global to the application but even if there was there is enough chatter out there to indicate that perhaps applicationScope is not as ubiquitous as it sounds and therefore you have to monitor your objects closely.

You already figured out the Domino object issue so that has to be done no matter which approach you choose.

Depending on your application you may be staring down some major rearchitecting but my recommendation is to try it with the sessionScope first and see how it performs. Do some benchmarking. If it works fast enough then go with that but as you develop your beans you should pay VERY close attention to performance optimization. The multiple database calls could be an issue but you really won't know until you play with it a little bit.

One thing that will help is that if you build your classes beans using a more detailed architecture than you think you need at first (don't try to pile everything into a single class or bean), not only will it be easier to adapt your architecture if needed but you will also start to see design patterns that you may not have even known were possibilities.

Upvotes: 2

Related Questions