Process-Display-Process (PDP) Pattern

zhaozj2021-02-11  197

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 a nd 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 ReplyProcess-Display-Process (PDP) Pattern.

转载请注明原文地址:https://www.9cbs.com/read-5248.html

New Post(0)