I understand the Java EE three-tier architecture (the difference between the software design pattern)

Source: Internet
Author: User
Tags flush html page time interval

As pictured above

1.J2EE is divided into 3 layers:
Server-side business logic (with business logic tier and persistent data tier, businness Tier and EIS Tier), server-side presentation layer (Web Tier) and client presentation layer (clients Tier)

The Java EE design pattern can be summed up to 6 categories
(1) Presentation layer architecture pattern (server-side presentation layer)
A. Front-end Controller mode
B.MVC mode
C. Adorner mode

(2) Presentation Layer Advanced Architecture pattern
A. Composite view mode (at the server-side presentation layer)
B. View Assistant mode
C. Service worker model

(3) Presentation layer scalability mode (server-side presentation layer)
A. Asynchronous page mode
B. Cache Filter Mode
C. resource pool model

(4) Business layer mode (server-side business logic layer)
A. Composite entity model
B. Domain object mode (business data tier)

(5) Data transfer mode (used between the business logic layer and the presentation layer)
A.dto mode
B.dto Pass-through hashing mode
C. Database Row collection Dto mode

(6) database schema (server persistence data tier)
A.dao mode
B.dao Factory mode


2. Front-end Controller mode
The common application is that a servlet, as a front-end controller, is responsible for requesting the page and then forwarding it to the page controller. The page controller is also a servlet, the servlet electrophoresis about the business logic that the request should perform, and returns to the concrete reality page based on the results of the business logic. The simplified use is that the front-end controller servlet uses "command mode" to transform the page controller into a finer-grained class.

Acitonservlet is a front-end controller, part of the code

Requestutils.selecetmodule (Request,getservletcontext ());
Getrequestprocessor (Getmoduleconfig (Request)). Process (Request,response);

Requestprocessor Process method handles common tasks, part of code
if (!processpreprocess (Request,response)) {
Return
}
Processxxx methods are dealing with public actions.


The Requestprocessor Processactionperform method implements the command mode, which assigns specific requested actions to the action.
Part of the Code
Return (Action.execute (mapping,form,request,response));

The front-end controller selects the page controller to parse the user's request, implement the specific business logic, and forward the results to the page by trying to


3. Adorner mode
(1) design pattern of the adorner mode
The adorner pattern provides a way for the client to transparently extend the functionality of an instance, and the return type of the method is this instance, and the internal representation of the instance has been completely different with the function changes as the client calls the method continuously.
(2) The adorner pattern in Java EE design mode
The servlet supports adorner mode, decorates a request, uses an adorner class to intercept all requests sent to the target object, performs the required work, and then forwards the request to the next adorner, knowing that there is no adorner, and then sends the request to the servlet

Servlet-Benefit filters to intercept requests and responses, and make a few extra deals for this request before the request arrives in the servlet. The processor can be seen as a chain, each filter can pass between each other, the following is the filter filter interface Dofilter has three parameters, Servletrrequest,servletresponse,filterchain, Activate the next associated filter using the Filterchain dofilter ()


public void Dofilter (ServletRequest request,servletresponse response,filterchain chain) throws Ioexception,servlet exception{
To set the character encoding with the Secletencoding method
if (Ingnore | | request.getcharacterencoding () = null) {
String encoding = selectencoding (request);
if (encoding!= null)
request.setcharacterencoding (encoding);
}
Chain.dofilter (Request,response);
}


4. Composite view mode
"Compositing mode" in design mode
Synthesis mode: Provide a tree-like object structure, the branch and leaf class all implement the same interface, so that the client calls any object as long as the need to call the root interface of the tree structure.

"Composite view mode" in Java EE design mode
Pulls out the layout of the view to form a template for a series of generic components. You can use XML to describe the composition of a view


5. View Assistant Mode
JSP page Tag library and struts of the tag library, a tag should inherit Javax.servlet.jsp.tagext.TagSupport, and give Dostartag and Doendtag two methods of implementation.
Dostartag Implement business logic
Doendtag Control output

6. Service Worker Model
Uses the page flow, front-end controller mode, and view Assistant mode to represent a complete set of processes for request-forward-view. This model is also the implementation of the MVC pattern, struts also based on this pattern to implement


7. Asynchronous Page Mode
When remote data is changed, it is cached, called the publisher-subscriber-model. The function of Java EE is to use a subscriber role to accept data from the publisher role at a time interval or when the data changes, and the Subscriber role uses the schema to update the database. Such work is lifetimes in the "Observer mode" in software design patterns. The common application is that when the publisher needs to display the latest information on the HTML page, it is responsible for using a subscriber role. such as Actionservlet

8. Cache Filter Mode
This pattern is used to create dynamically generated pages in the rafters, minimizing the duplication of generated pages. In the Java EE function, a cache filter is used to intercept the request to determine whether the page returned by the request has a cache. The cache filter should be placed before the "decorate filter" and the work servlet. A cache filter is a variant of a decorative filter. decorates the HttpServletResponse object to hold the result of the request processing.

9. Resource pool Model
The client should be obtained from a pool when it needs a JDBC connection. If there is a JDBC connection available in the pool, this object resource is returned. If there are no resources available, but there is capacity in the pool, a new instance is generated using the factory. If there are no resources available in the pool and the pool capacity is already covered, then you must wait and know that the other clients are returning at least one object.


10. Composite Entity Model
This pattern can reduce complexity and communication overhead in a working environment. A composite entity centralizes data from a variety of different sources into a single object. A centralized object that is applied as an EJB environment.


11. Domain Object Mode
To object a table structure in a database, such as a table in Hibernate, into an object, using the persistence layer framework theory

12.DTO mode
The actionform of struts is the implementation of a DTO pattern, from the page view to the data passed to the model layer, the model layer through the call of business logic will return the data to Actionform as the view layer of data display
Actionform is only used to pass from the view layer to the model layer.


13.DTO Hash Mode
The dynaactionform of struts is a DTO hash pattern that allows the programmer to set a primary key for a data, which can then be used to get the page data through the primary key in Acton

14. Database Row Collection Dto mode
The JDBC resultset is sent to the client display, and a stand-alone class using the ResultSet interface is sent as a DTO to the client display.

15.DAO mode
Data Access object patterns are considered to be a basic pattern of persistence layers
DAO mode has the function of rhetorical data and processing business logic, and it is no longer popular


16.DAO Factory mode
The user is interested only in the product being created, and many of the extra work done before the creation of the product is encapsulated into the subclass of the factory interface, but not the constructor of the specific product class, which is used implicitly

Change mode only and database connection function, do not realize the function of accessing data

The difference between 17.J2EE design pattern and design pattern
(1) The Software design pattern is the design, the Java EE design pattern concerns is the frame
(2) The software design pattern is the best time to solve the common problems in the software world, and it is the summary of many experienced software designers ' continuous success and failure.
The Java EE model is designed to solve the architectural problems of enterprise-level applications.
(3) The main purpose of the software design pattern is decoupling, which can appear in any layer of Java EE Model Software design pattern.
The Java EE design pattern is decoupled from the layering in the Java EE model. The software design pattern is concerned with the microscopic methodology, while the Java EE design pattern is the macroscopic methodology.

18.
(1) Front-End controller mode, MVC pattern, service worker mode are integrated into the presentation layer framework, such as Struts framework, webwork framework
(2) The composite view mode has tiles framework implementation
(3) The main implementation of view Assistant mode is tag library, JSTL Tag Library
(4) The DAO factory pattern does not necessarily need to be implemented with the dependency injection of the middle-tier framework spring.

The following excerpt from a Netizen's article:

First, MVC architecture
Struts is a nice MVC architecture that I've always used to combine view,controler and model with a simple configuration. View is implemented primarily as a JSP, because it is label-oriented, so it provides a good interface for web designers. Formbean is the intermediate data carrier between the JSP and the action, which undertakes the process of transferring data from JSP to action. Action is the transit point of the process, different business in different action in different model calls to achieve. Model is to achieve a specific business operation process, but this process is a higher level of implementation.
In summary, the MVC architecture implements two tiers of the three-tier structure, the presentation and business layers, and another layer called the persistence layer.
Two or three-tier architecture
As mentioned above, the three-tier architecture is "presentation layer", "Business Layer", "persistence layer". Presentation layer implementation of the representative works is a struts framework, the business layer to achieve the representative works is spring, the persistence layer to achieve the representative works is hibernate. But spring was skipped in my development because I thought the business was too simplistic to be implemented with spring. Below I will specifically say my three layer implementation.
1, three kinds of beans
in my implementation, there are a total of three kinds of beans, all of which exist to hold the object state. In the persistence layer, this bean is the Pojo object. It is database-oriented, or how much to take care of the implementation of the database, because I am accustomed to using PowerDesigner to design the database, the structure is also more comfortable, and if the direct use of hibernate to real database, it is not so clean. So the Pojo object design cannot be completely object-oriented. Beans in the business layer I call it entity, which is a fully program-oriented bean. It may be a collection of several pojo. For business logic, this kind of bean, called entity, is "used" and is very convenient for business. The beans in the display layer are Formbean and are used primarily for incoming data. The
Pojo only survives the persistence layer, and the data is delivered to entity at the business level. and entity not only live in the business layer, it is also uploaded to the JSP, for display.
2, Pojo, and DAO
I think this is the relationship between data and operations, DAO is only on call, and Pojo is only used to save data. Here is the real reality of my DAO interface.
Public interface Dao {

/
public void Resetpo (Pojo Pojo) {
This.userpo = (Userpo) Pojo;
}



Public String Save () {
String oid = null;
try{
Session session = Hibernateutil.currentsession () has been raised in the constructor to initialize the
Transaction tx = Session.begintransaction ();
if (userpo.getid () = null) {
OID = (String) session.save (USERPO);//If this is a new Pojo insert operation.
Session.flush ();
Tx.commit ();
}else{
Session.update (Userpo,userpo.getid ());//If the Pojo has been initialized then update
Session.flush ();
Tx.commit ();
}
}catch (Hibernateexception ex) {
System.out.println ("///n userdao.save () has an exception. ");
The Log.error ("Userdao.save ()" Exception occurred. ", ex);
}
Return OID;
}


Public Pojo load () {
Userpo tmp = new Userpo ();
try{
Session session = Hibernateutil.currentsession () has been raised in the constructor to initialize the
TMP = (USERPO) session.get (Userpo.class, Userpo.getid ()); Obtaining an object with an exact ID value
}catch (Hibernateexception hbe) {
Hbe.printstacktrace ();
}
if (tmp!= null) {
USERPO = tmp;
return Userpo;
}
Else
return null;
}


Public List find (short by) {
Session session = Hibernateutil.currentsession () has been raised in the constructor to initialize the
query query = NULL;
String Where=null;
Switch (by) {
Case 0:
where = "";
Break
Case 1:
where = "where Us.name= '" +userpo.getname () + "'";
Break
Case 2:
where = "where us.account= '" +userpo.getaccount () + "'";
Break
Case 3:
where = "where us.password= '" +userpo.getpassword () + "'";
Break
Case 4:
where = "where us.account= '" +userpo.getaccount () + "' and Us.password= '" +userpo.getpassword () + "'";
}
query = Session.createquery ("From Userpo Us" +where);
return Query.list ();
}

public void Close () {
Hibernateutil.closesession ();
}

}
Where Hibernateutil is a Hibernate method class that provides a thread-safe session. And the method of closing this session (although closing the session is too simple). Each DAO is produced by Daofactory. Daofactory also has a common interface. As follows:
Public interface Daofactory {

Dao Getdocumentdao ();
Dao Getdocheaddao ();
Dao Getdocaccessorydao ();
Dao Getuserdao (User u);

}
Here is an implementation of DAO based on hibernate.
public class Hbdaofactory implements Daofactory {

Public Hbdaofactory () {
}


Public Dao Getdocumentdao () {

return new Com.cecs.dao.DocumentDAO ();
}


Public Dao Getdocheaddao () {

throw new Java.lang.UnsupportedOperationException ("Method Getdocheaddao () not yet implemented.");
}


Public Dao Getdocaccessorydao () {

throw new Java.lang.UnsupportedOperationException ("Method Getdocaccessorydao () not yet implemented.");
}


Public Dao Getuserdao (User u) {
return new Userdao (U);
}

}
Such a but not hibernate to implement the persistence layer, it can be easily changed to other DAO without modifying the business layer.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.