1
votes

I’m a begginer concerning the Notes/Xpages technologies and I’m facing a conception issue :

I have an XPages Application running on Domino Server.

We are trying to modernize our development practices using Java and JSF possibilities, I would like to introduce the MVC pattern in our applications.

I will try to sum it up clearly:

Let's consider a global locking system on domino documents. I have an xsp which represents the details of the document : document_details.xsp. This form uses a controller class DocumentDetailsAction.java. This class is also a managed bean with view scope.

So when the user clicks on an 'edit' button on my xsp : boolean DocumentDetailsAction.isDocumentLocked(String unid) is invoked.

if false, the document changes to edit mode, etc. if true, add a Message to inform the user that the doc is locked.

With the MVC pattern, the method isDocumentLocked instantiates a business service class : DocumentLockBO which contains the business logic concerning to the locking system. This business class has a DocumentLockDAO instance as an attribute. This attribute is instantiated in the constructor.

In my DAO, I instantiate a Domino Database object in the constructor and set it as an attribute of my class.

Problem : Let's imagine that the document is locked and that the user clicks on the edit button a million times! Each time, DocumentLockBO, DocumentLockDAO and finally Domino-Database objects will be instantiated.

That's a real nightmare for memory and performances. A solution : using an instance of DocumentLockBO and set it as an attribute of my controller class. On each click, the same instance of BO/DAO/Domino-Database objects will be used Problem : DocumentLockBO has a DocumentLockDAO attribute which has itself a Domino-Database attribute.

A serialization Exception occurs with Domino object!

Am I taking the right direction? Any suggestions?

3
Wellcome to SO. Just few hints: It's always good to attach some of your code. And also, please, try to simplify your questions as much as possible - this is really long question :).Erveron
For document locking, you may want to consider the document locking in-built in Domino. See the relevant part of Mastering XPages. Bear in mind that in-built document locking also requires you lock the document before deleting too.Paul Stephen Withers

3 Answers

2
votes

The Domino backend classes are not Serializable, and are recycled after each request anyway. So, while you can make the rest of your objects Serializable, you'll have to make sure to mark any Domino member variables as transient and re-fetch them as needed. The DominoDocument wrapper class is Serializable, but you'll have to call one of the methods on it after deserialization (restoreWrappedDocument, probably), so it doesn't save you too much in this case.

Essentially, the Domino backend objects can be seen as a peculiar network resource that is torn down and recreated on each HTTP request.

1
votes

I would say that you are definitely on the right track! MVC is a very good thing in XPages. I use it a lot.

However, as Jesse mentioned you CANNOT cache any Domino objects. I just create a "data" class to hold the information from the DAO class and pass that around. If you can use the document's universal id as key then you will have extremely fast database access anyway. Using views will slow things down. So caching all (or perhaps just the keys) of your data in some intelligent way may be a good option for you.

You have to be aware of the various scopes for the beans you use. Especially Session scope can do bad things to your app... I have collected some of the advice I use in a short article about tuning XPages. On the other hand you can easily implement a global locking mechanism in Java using Application scope. Actual implementation obviously depends on the specific needs.

You should consider the OpenNTF Domino API - it also comes with a Graph database that is extremely efficient for some types of data structures.

I did a presentation on the concepts of how I do MVC. Perhaps you can get some ideas (there are som sources that may help you further - and an example database).

/John

0
votes

In my opinion, for an NSF local to your XPages, this kind of requests would be extremely fast. Reusing the database object (and views for ex) during a request (not more) should be a sufficient approach to have great performance. Btw, my personal opinion is that, while I value MVC pattern, when XPages talks exclusively to NSF data, you'll find a great deal of performance optimisation while using native XPages elements (declaring datasource, repeat, panels, views).