开发者

questions on database updation

开发者 https://www.devze.com 2023-01-16 01:15 出处:网络
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 solu

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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消