This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Implementing a paging logic using stateful EJB  RSS feed

 
partho mukherjee
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
can anybody tell me if we can use stateful session beans for implementing the paging logic for a page,i.e a case when a lot of data is retrieved at a time, but shown only ten at a time.I tried setting the bean object in session but that is of no use, as multiple users bring in performance issue making the session heavy. Also using Handle to store the session information does not help in local session beans.Hope there's a way out other than resorting to remote beans.
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I dont see a reason to use a session bean as you would probably not use the transaction, security etc. provided by the container in this scenario. I would rather suggest to use a simple data object with the following features:

1) Do not retrieve the entire result set into the memory for the first call.
2) Depending on the number of links you provide on the page(Typically in pagination people give "Prev. 1,2,3 Next" sort of links) fetch only the required data.
3) Fetch more data on demand.

Now, you can have a container class that will hold these data objects per client (You can use HTTP session id as the client id). This will be a simple hashmap and you also dont need to worry about multi-threading as these POJOs are related to a unique client.
Whenever, a page is requested, you take your HTTPSession id and query this container with relevant information. The container will create an object if not already present. (You can differentiate between a next page request or a fresh request based on a parameter. A new page request should always create a new object.)
For cleaning up, you can register a HttpSessionListener and when a session expires you can clean your container. Also, you can clean up when the user browses away from the page.

P.S: With this approach, you would not be able to handle a case where a user can share HTTP session across two browser windows(Creating a child browser instance using CTRL+N), as in that case two concurrent requests can be made for the same session id and that will pose multi-threading issues.
However, this is a common problem if you want to store state across user actions.
[ April 25, 2007: Message edited by: Nitesh Kant ]
 
partho mukherjee
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply... but then the code I am talking about is a huge one and the approach you are talking about would cost a massive change.I just wanted to find out if there is any way out keeping the code intact.Anyway thanks for the info. would use the same technique henceforth.
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Either cache the results in memory and retrieve them later. Or modify the select query so that it fetches X records at a time anywhere from the result set. For example you can use rownum in Oracle to do this.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!