Mini Project Discussion:-
-->Sending ResultSet object from DAO class to service is bad practice because
a.)ResultSet object is not Serializable object
b.)To receive ResultSet object in service layer we need to write jdbc code and writing jdbc code in service layer is bad practice
-->To overcome above problems
Solution(1) Use RowSets instead of ResultSets
-->RowSets are serializable objects
-->To receive RowSets we need to place jdbc code in service class
-->Some jdbc drivers do not support RowSets
Solution(2) Copy the records of ResultSet to Collection and send Collection
-->Collections are serializable objects
-->We can receive collection in service class as non jdbc code
-->If you are looking to perform more read operations on collections then use non-synchronized collection for better performance
E.g: ArrayList, HashMap
-->If you are looking to perform both read & write operations on collections then use Synchronized collections for Thread safety
E.g: Hashtable, Vector & etc...
(Q) Problem in copying the records of ResultSet to ArrayList collections ?
-->Each element of ArrayList holds only one object, but each record of ResultSet contains multiple values, So we can not copy the each record of ResultSet to the each element of ArrayList
-->To solve this problem copy the records of ResultSet to one object of BO class and add that object(BO) to ArrayList element
Sample Code:
- public class StudentBO{
- private int sno;
- private String sname;
- private String sadd;
- //setters & getters
- .....
- }
- //Logic to copy ResultSet records to ArrayList collections
- ResultSet rs=st.executeQuery("select * from student");
- List<StudentBO> list= new ArrayList<StudentBO>();
- while(rs.next()){
- StudentBO bo=new StudentBO();
- //copy each record to BO class object
- bo.setSno(rs.getInt(1));
- bo.setSname(rs.getString(2));
- bo.setSadd(rs.getString(3));
- //add BO class objects to ArrayList collections
- list.add(bo)
- }//while
(Q) Where did you used java bean in your project ?
a.)As helper class to transfer ResultSet records to ArrayList collection
b.)As BO class to holds inputs(form data) or outputs
c.)As DTO class to transfer huge amount of data from one layer to another layer
d.)As BO class representing persistence logic data
e.)To store huge amount of form data in single session/ request / application attribute, it will be placed in java bean class object
(Q) Where did you use collectionin your project ?
-->To send ResultSet object data from one layer to another layer, we copy the data to list collection
-->To maintain JDBC properties in properties file we use java.util properties
-->To develop dynamically growable buffer or cache we use Hashmap
-->To maintain huge amount of data in single session/request/application attribute. We place that huge amount of data in list collection and etc...
Mini Project :-
View
|-->html files, jsp files
Controller
|-->Servlet component
Model
|-->service class(java class)
|-->DAO class(java class)
a.)Given based on MVC(2) Architecture
b.)Service class, DAO class comes under Model Layer components
c.)ResultSet data copied list collection using BO support
d.)DAO, service class bending results to other layer in the form of ListBO, ListDTO respectively
e.)Ordinary buttons are used to submit the request using javaScript
f.)JavaScript also used for form validations and also for printing webpage
g.)Controller servlet is using rd.forward(-,-) to forward the request to destination webpage
h.)Controller servlet is passing data to result JSP's in the form of request attributes
i.)Facility is given to get printout of webpage and to download output as downloadable file
-->While developing Multi-Layer app we don't catch and handle exceptions in DAO, service class that means we declare the exception to be thrown to its caller layer
-->If we catch and handle exception in DAO, service classes, the raised exception will be eaten and suppressed in those classes itself so we can't propagate the exception to the user for display.
-->To overcome these problem DAO class propagates the exception to service class, service class propagates the exception to controller class and controller class displays the exception in non-technical terms by forwarding control to error page
Comments
Post a Comment