• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need advice

 
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys

I have a mail DTO and a mailDAO - The mailDAO will get a List of mailDTO Objects and send them back to the servlet. Now, I also need to handle pagination, like (1) how many records are being viewed, (2) max records avaible, (3) whether the next/previous links should be available, (4) hold the new links for the previous/next if they are enabled. So as a result I have created another DTO called MailPagination and use that in my MailDAO to get all the relevent data. Now, my questions are, (1) Is this a good way of handling this problem ? And (2) do you think I should create a letterPaginateDAO for the DTO ?

EDIT: I just realised I will also need pagination for my contacts and drafts too.
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To save memory, do the pagination at DAO level. Just create a list() method taking two parameters: index of first row to be retrieved and amount of rows to be retrieved at once and simply use SQL to retrieve the desired subset of results. In for example MySQL you can use the LIMIT clause for this.

Doing so in Java --obtaining the complete database table-- is fairly memory intensive and here you´re not optimally making use of the powers of a database.
 
shaf maff
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bauke Scholtz wrote:To save memory, do the pagination at DAO level. Just create a list() method taking two parameters: index of first row to be retrieved and amount of rows to be retrieved at once and simply use SQL to retrieve the desired subset of results. In for example MySQL you can use the LIMIT clause for this.

Doing so in Java --obtaining the complete database table-- is fairly memory intensive and here you´re not optimally making use of the powers of a database.

Thanks for the reply. Thats what Im doing. I am using LIMIT to restrict number of records, and then place them into a list. What I am planning on doing is getting the mail records from mailDAO and in my MailProcessor class create a Pagination DTO instance, place the Mail List into it and the rest of the fields and return that to the servlet. So that way I can also do the same for the contacts and drafts lists which makes it alot less confusing. What do you think ?

Thanks for the link to your DAO/DTO btw - It has proved an invaluble source of information!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic