Caching and displaying the results

Hi Gurus,

I have to display some thousands of records to the user, which obviously comes from the database. I don't want to load the session with huge Vector or ArrayList.

Now i want to know the following things:

1. Is there any pattern to cache/retrive the objects in fast and efficient manner?

2. Display them to the view in pages.

I have gone through Fast Lane Reader, Page-by-Page Iterator patterns. But i need something different than these two, even though i can use Page-by-Page. And yes, i want a NON EJB solution.

Thanks in advance,

- Venu

[598 byte] By [venu01a] at [2007-9-27 23:20:34]
# 1

Venu,

See the solution at backend rather than to see it on front end.

Let me know which database you are using. If you are using Mysql at backend, It has a function called "limit" which gives you a particular block of recored you want to show with page no. For ex. if you put "select * from table limit 0,10", it will bring first 10 records. If you use the same for limit 10,20; it will return next 10 rows betn 10 to 20.

Just manipulate this with you page number and you will get a required no. of filtered data n a very fast and efficient way for any page number.

Comment for any further discussion.

Satya

tsatyawalia at 2007-7-7 15:23:11 > top of Java-index,Other Topics,Patterns & OO Design...
# 2

The only problem being, that if someone else writes to the table in between the page views, you are in trouble.

Say view the first 10 records on a page, and while waiting for user to click for the next page, someone else deletes the ten first records from the table. Then the next page the user sees are those that were row 21-30 when the first page was shown. Those rows that were 11-20 are never shown to the user!

Unless you lock the table until the user is finished viewing pages you cannot guarantee what the user sees. If you lock the table, nobody else can write to the table for that long, and figuring out when a user is finished can be a problem in itself.

So your approach will only work in case the tables are read-only.

tychoSa at 2007-7-7 15:23:11 > top of Java-index,Other Topics,Patterns & OO Design...
# 3

Friends,

If we are concentrate on the backend rather than front end, then for every next or prev links one click is passed to the database, for this is performance is reduced or not.because i have already facing this problem, that is the reason i have taken all the records in an array list and put the list into session, and for every clicks i taken it from the session and show the results on the page.

For this approach the fresh data is not able to shown the user this is one problem for this apprach. Is there any better approach for this and that approach should reduce the number of clicks to the database also.

Thank you.

Veeru K.

veeruk344a at 2007-7-7 15:23:11 > top of Java-index,Other Topics,Patterns & OO Design...