会员: 密码:  免费注册 | 忘记密码 | 会员登录 网页功能: 加入收藏 设为首页 网站搜索  
 安全技术技术文档
  · 安全配制
  · 工具介绍
  · 黑客教学
  · 防火墙
  · 漏洞分析
  · 破解专题
  · 黑客编程
  · 入侵检测
 安全技术论坛
  · 安全配制
  · 工具介绍
  · 防火墙
  · 黑客入侵
  · 漏洞检测
  · 破解方法
  · 杀毒专区
 安全技术工具下载
  · 扫描工具
  · 攻击程序
  · 后门木马
  · 拒绝服务
  · 口令破解
  · 代理程序
  · 防火墙
  · 加密解密
  · 入侵检测
  · 攻防演示
技术文档 > JAVA
Process-Display-Process (PDP) pattern
发表日期:2004-07-30 17:27:41作者: 出处:  


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.

返回顶部】 【打印本页】 【关闭窗口

关于我们 / 给我留言 / 版权举报 / 意见建议 / 网站编程QQ群   
Copyright ©2003- 2024 Lihuasoft.net webmaster(at)lihuasoft.net 加载时间 0.00147