MVC Projects

Different logics of web application:-
a.)Request data gathering logics:
-->Reading form data/request headers values/miscellaneous information
b.)Form validation logics:
-->Verifying the pattern and format of form data
c.)Business logics/service logics:
-->The main logic of the application
d.)Persistence logics:
-->CURD operations on DB s/w
e.)Presentation logics:
-->Logic that gives user interfaces
f.)Middleware services
-->Additional services like security, logging and etc...
Different models/Architectures of developing java web applications
 Model1:
-->All the logics of web applications will be placed in either in servlet component or jsp component of web application
-->If servlet components are used in web app, the jsp components will not be used & vice versa
-->Model 1 architecture is more of working with jsp component
Model 2(MVC)
a.)MVC(1)
b.)MVC(2)
-->Here we use multiple technologies in multiple layers to develop various logics
Model(1) architecture:

Disadvantages:
-->In Model(1) architecture we mix up multiple logics, so there is no clean separation between logics
-->The modifications done in one kind of  logic effects other kind of logics
-->Maintenance & Enhancement of the application becomes complex
-->Parallel development is not possible, so the productivity is poor
-->It is not industry standard architecture to develop the applications
-->Certain middleware services must be implemented by programmer manually, so it gives burden to programmers
Advantages
-->Knowledge on only servlet or only jsp is sufficient to developthe application
-->Since parallel development is not possible multiple programmers are not required
Note: Model(1) is suggested for small scale websites which are less than 10 pages
MVC Architecture
M=Model Layer (represents business logic+persistence logic like accounts officer(CA)(data)
V=View Layer (represents presentation logic like Beautician(Gives user interface to gather inputs & to display outputs)
C=Controller Layer (represents Integration logics like supervisor
-->Integration logic controls & monitors all the activities of application execution
-->Integration logic is responsible to trap the request from clients, to pass the request to Model Layer components, to gather results from model layer components and to pass the results to View Layer components
-->In MVC(1) Architecture we take single component having View, Controller Layer logics and we take separate components having model layer logics
-->In MVC(2) Architecture we take separate components for View Layer, separate components for  Model Layer & separate components for Controller Layer
MVC(1) Architecture:-

-->We use MVC(1) Architecture to develop medium scale applications (less than 20 pages)
-->Compare to Model(1) Architecture MVC(1) gives clean separation between logics but to get more clean separation between logics use MVC(2) Architecture
MVC(2) Architecture:-

Advantages:
-->Multiple layers are given for supporting clean separation of logics
-->The modifications done in 1 layer doesn't effect on other layers
-->The maintenance & enhancement of the project becomes simple
-->Parallel development is possible, so the productivity is good
-->It is industry standard architecture tl develop large scale web projects
-->The EJB, SPRING, HIBERNATE used in Model Layer gives built in middleware services
Disadvantages:
-->For parallel development multiple programmers are required
-->Knowledge on multiple technologies is required

(Q) How can we do parallel development while working with MVC architecture?
-->The PL/TL divides the team into two parts
a.)Part(1): (Presentation tier component developers)
-->Uses servlet,jsp technologies to develop View, Controller layer logics
b.)Part(2): (Business tier component developers)
-->Uses JEE technologies, java frameworks to develop model layer service, persistence logics
Note: Since both parts(1)&(2)  can go together so we can say parallel development is possible
MVC(2) Architecture Principles:-
-->Every layer is designed to have specific logics, so don't place any additional logics
-->All the operations of the application execution must happen through Controller component
-->There can be multiple components in View Layer & Model Layer but we must take single component (servlet) as controller
-->The View Layer component must not talk with Model Layer components directly & vice-versa i.e., they must talk through Controller component

Mini Project(1) 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:
  1. public class StudentBO{
  2.  private int sno;
  3.  private String sname;
  4.  private String sadd;
  5.  //setters & getters
  6.   .....
  7. }
  1. //Logic to copy ResultSet records to ArrayList collections
  2. ResultSet rs=st.executeQuery("select * from student");
  3. List<StudentBO> list= new ArrayList<StudentBO>();
  4. while(rs.next()){
  5. StudentBO bo=new StudentBO();
  6.  //copy each record to BO class object
  7. bo.setSno(rs.getInt(1));
  8. bo.setSname(rs.getString(2));
  9. bo.setSadd(rs.getString(3));
  10. //add BO class objects to ArrayList collections
  11. list.add(bo)
  12. }//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

Mini Project (2) discussion:-
Real time File Uploading & File Downloading:-
-->In real time the uploaded files will not be saved in DB table directly because they improve burden on DB software and DB software cannot maintain huge amount of data, So the best practice is save the uploaded files to server machine file system and write their address locations to DB table columns as String values

-->While performing File Downloading get address locations from DB software and locate the files of server machine file system and perform File Downloading



Comments

Popular posts from this blog

Java Mail API

JSP Life Cycle

Project Architecture's