This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Multiple sessions paging result sets... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Reply locked New topic
Author

Multiple sessions paging result sets...

Jim Hardin
Ranch Hand

Joined: Aug 02, 2006
Posts: 46
Greetings Big Moose Saloon.
I am interested in using a tabular result set display binding tag library like either DisplayTag (Sourceforge) or DataGrid (Apache), and paging results (from a database). I can do all of this fine, but the question I have is a question of result collection object scoping, and multiple sessions.
The problem/challenge that I have is that if I put the List/Collection object for the results in session scope, and the user opens another session, then the new session object clobbers the last sessions session scoped object.
I'm kind of looking for a general purpose technique (if it exists) to page result sets in potentially more than one session. Another criteria I have is that I do not want to requery when the users page through results (I will be doing a "top-500" query, retrieving the first 500 records and then allowing for the users to page through those, sort them, export them, etc).
I was thinking I might avoid this object collision/clobbering problem by maybe creating a separate session object for each result set (or having separate session result sets be elements in an Array) and supplying the particular session's array-index as a request parameter to the view page or something like that. This seems like it would work, but have the downside of causing problems with session cleanup... Like how would I know which objects are active (since the result sets are largish, then I would expect performance degradation if I just ignore cleanup).
Thank you very kindly for reading, and I am greatful for any and all comments or suggestions.
Sincerely,
-Jim
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Hi, welcome to the ranch!

We've had lots of conversations about pagination, but I don't think with the multi-session concerns you've raised. How does a user come to have multiple sesions?


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Jim Hardin
Ranch Hand

Joined: Aug 02, 2006
Posts: 46
I'm sorry--my apologies. I did *not* mean to say that the user has multiple "sessions", but that the user has multiple "brower windows" open. That really undermined my whole question. Excellent clarification, thank you. Please substitute "browsers" where I said "sessions"... Thank you very much.
-Jim
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
If you open IE (or I imagine most or all other browsers) twice by starting it from some shortcut you'll get two sessions. They are independent and act like two users at two computers in most respects.

If you use File/Open/New Window or use JavaScript or target to pop a new window you'll get a new window on the same session. Then you could be browsing the same dataset in two windows at two different locations. Is that the situation?

Could each window keep track of its own position and ask for the next or prior screen full of data by row number or page number?

Some pagination options ...

Repeat the whole query every time, which you already ruled out.

Repeat a partial query every time with starting row number or starting key and a number of rows. I don't think there is a standard, portable way to do this on all databases. Might not be able to page backwards.

Query once, save all the results in memory, page the user up and down the memory collection. Takes lots of memory!

Query once, save all the keys in memory, page as before, query a page full of data using the keys. Less memory, more database queries.

Query once, save all the results somewhere not in memory ... on disk, another database table, in the transporter buffer ...

Any of those sound interesting?
Jim Hardin
Ranch Hand

Joined: Aug 02, 2006
Posts: 46
Stan,
I reformulated my question thanks to your helpful clarification. Please see below for a *hopefully* clearer articulation of my question.
I am thinking that maybe a better forum for this question might be a more webapp oriented one, like say the JSP forum, and I might post it tomorrow on that--I will reply back on this if I end up doing that. Please feel free to give this a read. Thank you for all the help.
-Jim

I am interested in using a tabular result set display binding tag library like either DisplayTag (Sourceforge) or DataGrid (Apache), and paging results (from a database). I can do all of this without any problems; the question I have is a question of result collection object scoping, and potentially multiple browsers open for a user session.

The problem/challenge that I have is that if I put the List/Collection object for the search result in session scope, and the user opens another browser (via ctrl-N, whatever), then any subsequent interrogation done in the new browser window will clobber the session scoped result object which was originally created by the first browser interaction.

Note: I'm assuming there is no clear way to page through a request scoped collection, because the request lifecycle has ended when the first page is rendered on the browser.

Also, to clarify, the session scoped collection is the first up-to-500 rows of some ad-hoc database search/interrogation; on the search form, the user specifies some mandatory and optional search criteria, and a dynamic query is executed populating the (currently session) scoped collection with results. I *do not* want to requery the database (not even partial result set queries for page subsets) as the user pages paging through these potentially up-to-500 results (this is not an option, sorry).

At this juncture some EJB adepts might suggest "stateful session EJBs" are the solution, but I would personally prefer to avoid EJB altogether if possible. Maybe that's really the most natural approach though? Anyway, if after searching/retrieving some initial results, but before paging to say the 2nd page, suppose the user opens another browser window and goes back and performs a different ad hoc search/interrogation, repopulating the same session scoped collection which the first browser window is supposed to be paging through, clobbering the previous results. My dilemma is what's the best way to handle this problem.

What I'm hopefully kind of looking for a is general purpose technique/approach/standard-practice (hopefully strictly webapp, no EJB, if possible) which might allow users to page results concurrently in multiple browser windows.
Thank you very much.
-Jim
Jim Hardin
Ranch Hand

Joined: Aug 02, 2006
Posts: 46
Stan,
I reposted this reformulated question on the JSP forum. Thank you very much for all of the help!
-Jim
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Yup, that was a good move there. Sounds like session scope needs some qualification, maybe a map keyed by some unique identifier from each browser window.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Multiple sessions paging result sets...
 
Similar Threads
storing data from database
Multiple forms with Use bean.
Tomcat session performance
Paging search results and multiple browser windows
Creating Temp table and querying it