tags:

views:

57

answers:

2

I have a web application that is implemented using java,jsp,servlets . whenever i have updates in the database table, the arraylist in my DAO should be updated. is there any better solutions.

Solutions

  1. create a thread in bean and query the database, if updates found then repopulate the arraylist.
  2. from client send an ajax request using polling concept.

kindly let me know solutions,even if possible using any framework.

+1  A: 

An arraylist in your DAO? This really doesn't sound right. The DAO class itself should not hold any data. You should also not store the data in session but just let the client load it on every fresh HTTP request. Any performance hogs you encounter with this are to be solved by using a connection pool and if necessary a second level cache.

As to the triggering one or other on updates, there are several ways to achieve this. Repopulating "an arraylist" in the server side makes at least no sense. The request has to come from the client side. Ajax polling is indeed one of the best ways. Another way is to just headlessly refresh the JSP page at intervals (e.g. once a minute) using a <meta http-equiv="refresh" content="60"> header so that it re-queries the data from the database. This is the easiest, but least user friendly.

As to the frameworks, I'd suggest jQuery and/or JSF for this.

BalusC
+1  A: 

So First of all in agreement with BalusC you really should not be storing any data in the DAO! This is a DAO and the main purpose of this class is to query the database to retrieve that data, understanding this concept will help you greatly in figuring out how to implement updates. As far as the updates are concerned you need to consider how your application is going to work are there going to be frequent updates to the database that the user is intended to see like a scoreboard therefore would have to be semi live for this perhaps an update thread should run if in java, or if using jsp servlets the above method would be a good compromise.If your application is user driven then I would suggest retrieving the data on users first request then not again unless the user reviews that page this shouldn't require any extra coding as I imagine your set up will suffice for this.

Please do not constantly re populate the array list via a thread tho think of the effect this would have on performance and even maintainability of your application.

When thinking about Database access I use this as a general rule of thumb live vs user driven apps require different models.

Chris
@chris thanks for answering. i could not understand following lines on update thread and above method "consider how your application is going to work are there going to be frequent updates to the database that the user is intended to see like a scoreboard therefore would have to be semi live for this perhaps an update thread should run if in java, or if using jsp servlets the above method would be a good compromise"
Suresh S
Yeah so basically what i mean by this is that if your application is intended to display data live and there is bound to be vital changes to the data the user has to see then and update thread would be necessary otherwise it would be much easier to do request based updating, Hope this helps Suresh . Thanks Chris
Chris
@chris semi live:when u say update thread on java or jsp how the client will see the recent data.i mean the code logic.
Suresh S