网页功能: 加入收藏 设为首页 网站搜索  
Process-Display-Process (PDP) pattern
发表日期:2004-07-30作者:[转贴] 出处:  


Solution :- Process-Display-Process Desgin.
In this we adopt a approach which will process a small set of data first and then display the results to the user. While the user is having a look at the given results we can process the remaining results in the background and store them for further use.

Suppose we have a requirement, where we need to query on a table having a million records and fetch ten thound of them to display it to the user. But we sure can not display ten thousand records at a time, so we devide the records into the batches of 100 records each and the user can then scrole through the batches.

The Normal design would implement a Servlet and stateless session bean. The Session Bean queries the database based on the query criteria and then passes on the result set bound in PBV (pass-by-value) objects to the servlet. The servlet then Displays first batch and subsequent batches to the user based on this query data.

In this design (PDP pattern) we will make use of Servlets and Stateful session beans. The stateful session bean will have two methods, one for selecting the first batch, and another for selecting the remaining of the records. When the client enters some query criteria, these are passed to the first method of the stateful session bean (typically getFirstBatchResults() ). This method will then process the first batch results and send them back to the Servlet. The servlet displays the results to user making use of ( Response.flushBuffer() ). The query to database for selecting first batch can be made faster by using database features which allow you to select the "top n" records from the results.

After this, the control is still in the servlet. So we can call the second method of the Statefull session bean. This method ( typically getAllResults() ) will fetch all the records from the database and store them in the stateful session bean's privatte variable (arraylist). When the user wants to scroll through the records, we simply try to get that perticular batch from the stateful session bean. The getAllrecords() method needs to ommit the first batch results from subsequently adding to the arraylist.

Advantages :-
1. This gives the user a feeling that the response is quite fast.
2. Since the most of the data is stored in the Stateful Session Bean, It reduces the size of HttpSession.

Disadvantages / limitations :-
1. It can not be used where in the user is required to show the summery of all the results. In that case we need to process all the records before we can show anything to the user.
2. It results into two network calls for the same query criteria.
3. Thread safe ness of the methods needs to be checked, as we are operating on a private variable of the Stateful Session Bean.
4. If the user needs to sort the records based on some perticular columns, then this can not be implemented.
1 replies in this thread Reply
Read more Process-Display-Process (PDP) pattern.
Posted By: Bob Lee on October 17, 2001 in response to this message.
First, for an argument as to why a stateful session bean should absolutely not be used in this situation, I'll point you here: http://www.onjava.com/pub/a/onjava/2001/10/02/ejb.html.

Second, this is just a page-by-page iterator, and you can find it in the Sun blueprints.

The way you should set this up is with a stateless session bean with a single method, getRows(int startIndex, int pageSize,...).

If you're lucky enough to have jdbc 2.0, you can query the entire set and return only the window of rows requested using ResultSet.setFetchSize(pageSize) and ResultSet.absolute(startIndex). You can also use prepared statements here to make things more efficient. If you want to sort by a particular column, just pass it as a parameter to your session bean and generate it on the fly.

If you’re stuck with older drivers, you can use database-specific parameters to retrieve the results a page at a time.

我来说两句】 【加入收藏】 【返加顶部】 【打印本页】 【关闭窗口
中搜索 Process-Display-Process (PDP) pattern
本类热点文章
  Java读取文件中含有中文的解决办法
  Java读取文件中含有中文的解决办法
  简单加密/解密方法包装, 含encode(),de..
  EJB 3.0规范全新体验
  java简单的获取windows系统网卡mac地址
  让Java程序带着JRE一起上路
  抢先体验"野马"J2SE6.0
  Java连接各种数据库的实例
  Java连接各种数据库的实例
  JAVA的XML编程实例解析
  Java学习从入门到精通(附FAQ)
  新手必读:Java学习的捷径
最新分类信息我要发布 
最新招聘信息

关于我们 / 合作推广 / 给我留言 / 版权举报 / 意见建议 / 广告投放  
Copyright ©2003-2024 Lihuasoft.net webmaster(at)lihuasoft.net
网站编程QQ群   京ICP备05001064号 页面生成时间:0.0109