Their understanding of the J2EE three-tier architecture (design patterns and software differences between the contact)
3 layer 1.J2EE points:
Server-side business logic (Business Logic Tier, and there is persistent data layers, Businness Tier and the EIS Tier), server-side presentation layer (Web Tier) and express the client layer (Client Tier)
J2EE design patterns can be summarized into six categories
(1) that the layer architecture mode (server-side express Layer)
a. front-end controller mode
b.MVC mode
c. decorative mode
(2) that the advanced architecture model layer
a. composite view mode (in the server-side express Layer)
View Helper pattern b.
c. mode of service workers
(3) that the layer scalability mode (server-side express Layer)
a. asynchronous page mode
b. filter cache mode
c. resource pool model
(4) business layer mode (server-side Business Logic Tier)
a. composite entity model
b. domain object model (business data layers)
(5) data transmission mode (for the Business Logic Tier and layer express)
a.DTO mode
mode of transmission of the hash b.DTO
c. collection of DTO model line database
(6) Database Schema (server persistent data layers)
a.DAO mode
Factory mode b.DAO
2. The front-end controller mode
Commonly used applications, a servlet as a front-end controllers, it is responsible in accordance with the request page, and then page forward to the controller. Page is also a controller servlet, the servlet about the request by electrophoresis should implement business logic and business logic based on the results back to the reality of the specific page. The use of simplified front-end controller servlet is to use "command mode" to the page controller into a more fine-grained type.
AcitonServlet is the front-end controller, part of the code
RequestUtils.selecetModule (request, getServletContext ());
getRequestProcessor (getModuleConfig (request)). process (request, response);
RequestProcessor's process method of dealing with public mission, part of the code
if (! processPreprocess (request, response)) (
return;
)
processXXX methods of action in dealing with public
Ways of the RequestProcessor implementation processActionPerform command mode, the mode of action of specific requests will be assigned to the Action.
Part code
return (action.execute (mapping, form, request, response));
Controller front-end user select the page to resolve the request of the controller to achieve the specific business logic, and based on the results page forward to trying to
3. Decoration mode
(1) of the decorative design pattern mode
Decorative mode for the client to provide a transparent example of a function expansion method is that the return type of example, the client continued to call this method at the same time, the example of the internal representation has changed with a completely different function.
(2) J2EE design patterns in the decoration mode
Supported Servlet mode decoration, decoration of a request the request to use decorative class intercepted target of all sent to the request and the implementation of the necessary work is completed and then forward to the next request for a decorative, and know that there is no decoration, and the final will be request sent to the Servlet
Lee Servlet filters to intercept request and response, at the request of Servlet arrive before the request to do a deal with some extra. Processor can be regarded as a chain, each filter can transfer between, the following is a filter Filter interface doFilter has three parameters, ServletRRequest, ServletResponse, FilterChain, the use of FilterChain the doFilter () to activate the filter under a relevant browser
public void doFilter (ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException (
/ / Using character encoding settings secletEncoding Ways
if (ingnore | | request.getCharacterEncoding () == null) (
String encoding = selectEncoding (request);
if (encoding! = null)
request.setCharacterEncoding (encoding);
)
chain.doFilter (request, response);
)
4. Composite view mode
Design Patterns in the "synthesis model"
Synthesis model: the object to provide a tree structure, tree branches and leaves category all achieve the same type of interface, so that the client calls any object at all as long as necessary to call the root of the tree structure can be the interface.
J2EE Design Pattern in the "composite view mode"
The layout of the view out from the vacuum, forming a series of common components from the template. Can use XML to describe the composition of view
5. View helper mode
jsp page in struts tag libraries and tag library, a tag should be the successor javax.servlet.jsp.tagext.TagSupport, and both give doStarTag and doEndTag methods of implementation.
business logic implementation doStarTag
doEndTag control output
6. Mode of service workers
Page flow controller front-end model, view model combined the use of aides, saying that "the request - forward - view" of a set of flow. The model is the standard implementation of the MVC pattern, struts implementation is also based on this model
7. Asynchronous page mode
Change happened when the remote data, it will be down the cache, referred to as the "publisher - Subscribers - Model." At the function of J2EE is to use a subscription to play, in a time interval or data changes, the role of the publisher from the data, subscribers will make use of role models at the same time came to update the database. Yet job this model in the software design of the "observer mode." Common application, when the publishing server needs to display the HTML page-to-date information, we will use a subscription to be responsible for the role. Such as ActionServlet
8. Cached mode filter
Village rafters used this model dynamically generated pages, as far as possible to reduce the generation of duplicate pages. At the function of J2EE is to use filters intercepted a cache request, the request to determine the return Whether or not there is the cache of the page. Filter cache should be placed on "filters decorative" and before the job Servlet. Cache filter is a filter decorative variations. Objects of decoration HTTPServletResponse request to save the results of treatment.
9. Resource pool model
At the client required JDBC connection should be made from a pool go. If the pool has available JDBC connection, then return the object resources. If there is no any available resources, but also the capacity of the pool, on the use of plants to generate a new instance. If there is no pool and the pool of available resources have been stained with the capacity, it must wait for that other clients also return at least one object.
10. Composite entity model
This model can reduce the complexity of the work environment and communication overhead. A composite entity will come from a variety of different sources of data into a single object. Applications focus on the environment for the EJB object.
11. Domain object model
Will be a database table structure of the object, such as table hibernate into objects used in the framework of the theory of persistence layer
12.DTO mode
struts of the ActionForm is a DTO model implementation, data from the page view to be passed to the model layer, model layer through the business logic of the call will be returned to the ActionForm data layer for the data view
ActionForm only be used in transmission from the view layer to the model layer.
13.DTO hash model
DynaActionForm the struts is a hash DTO pattern, so that a programmer set up the primary key data, and then at Acton can be obtained through the primary key information page
14. DTO model database set line
JDBC's ResultSet will be sent to the client indicated that the use of the ResultSet interface type as an independent DTO sent to the client display.
15.DAO mode
Data Access Object Pattern Persistence be considered one of the basic model
DAO mode data and deal with questions of the functional business logic, is no longer popular
Factory mode 16.DAO
Users were only interested in the creation of products, which were created before the product made in the creation of much extra work to the factory interface is packaged into a sub-category, and not product-specific category of constructor to implicitly the use of
Change model and the database connection is only the function to access the data did not achieve the function of
Design Pattern 17.J2EE the difference between model and design
(1) software design pattern is to design, J2EE design pattern framework that is of concern
(2) software design patterns in order to solve common software problem in the world refining a best time is experienced much of the software designers keep a summary of successes and failures.
J2EE solution for enterprise-class model framework applied problem.
(3) software design pattern is the main purpose of decoupling can be at any layer of the J2EE model of software design patterns have emerged.
J2EE Design Patterns for J2EE layered model for decoupling. Software design pattern is concerned about the method of micro-study, J2EE design patterns is a way to study the macro.
18.
(1) the front controller pattern, MVC model, integrated model of service workers has become the presentation layer frameworks such as struts framework, webwork framework
(2) Composite Tiles view mode there is the framework of implementation
(3) view helper implementation is the main mode of tag libraries, JSTL tag library
(4) DAO Factory pattern as the middle layer of the dependency injection framework for Spring has not necessarily need to achieve.
The following article is taken from users:
First, MVC architecture
Struts is a good MVC architecture, I have been using it, through the simple configuration can be view, controler, and Model together. View mainly JSP to achieve, because it is for the tags, so for web designers to provide a good interface. FormBean between JSP and Action is the middle between the data carrier, it shoulders the responsibility of the data from the JSP to the ACTION of the transfer process. Action is a transit point for the flow of different business in different Action with different calls to the Model implementation. Model is to achieve a specific business process, but this process is on a higher level of implementation.
In short, MVC framework for the implementation of a two-tier three-tier structure, namely the performance of layer and business layer and another layer also known as persistent layer.
Two, three-tier architecture
As mentioned above, the three-tier architecture that is "performance level", "business layer", "persistence layer." Performance level is the implementation of the Struts Framework representative works, the business layer is the implementation of the works on behalf of Spring, persistence layer implementation works on behalf of the Hibernate. However, the development of my Spring was saved because the operation is so easy in my opinion, not go so far as to achieve by Spring. The following specific example I will say that my three-tier implementation.
1, three Bean
In my implementation, a total of three Bean, they are all targets for the preservation of the status and existence. Persistence layer, this is a POJO object Bean. It is a database-oriented, or the number of a database implementation to take care of, because I used to use PowerDesigner to design databases, make up the structure is relatively quite satisfactory, and if it is directly to the database using Hibernate, then, is not so clean the. POJO objects so design will not be able to fully object-oriented. Bean business layer call it my Entity, this is a totally process-oriented logic of Bean. It may be some good collection of POJO. For business logic, which is called the Bean done Entity "brought on by", it is easy to conduct business. Show at the Bean layer is FormBean, mainly used for incoming data.
Survive alone in the POJO persistence layer, the operational data layer will be handed over to the Entity. The Entity is not only to survive in the business layer, it was spread in the JSP for display.
2, Pojo and Dao
This is in my opinion the relationship between data and operations, Dao Hu operation only, and only to save the data Pojo. The following is my Dao interface is actually a.
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 referred to in the constructor to initialize the
Transaction tx = session.beginTransaction ();
if (userPo.getId () == null) (
oid = (String) session.save (userPo); / / If this is a new insert operation carried out pojo.
session.flush ();
tx.commit ();
) else (
session.update (userPo, userPo.getId ());// have been if the pojo initialization update operations have been carried out
session.flush ();
tx.commit ();
)
) catch (HibernateException ex) (
System.out.println ( "/ / \ n UserDao.save () abnormal!");
log.error ( "UserDao.save () abnormal!", ex);
)
return oid;
)
public Pojo load () (
UserPo tmp = new UserPo ();
try (
/ / Session session = HibernateUtil.currentSession () has been referred to in the constructor to initialize the
tmp = (UserPo) session.get (UserPo.class, userPo.getId ()); / / existence of the ID with the exact value of access to object
) 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 referred to 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 ();
)
)
Hibernate is a one of Ways HibernateUtil class that provides thread-safe Session. And turn off the Ways of the Session (Session turn off too easy though). Each Dao is to generate the DaoFactory. DaoFactory also have a public interface. As follows:
public interface DaoFactory (
Dao getDocumentDAO ();
Dao getDocHeadDAO ();
Dao getDocAccessoryDAO ();
Dao getUserDao (User u);
)
The following is a Hibernate-based implementation of the Dao.
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);
)
)
This one to achieve but do not Hibernate persistence layer, it can be easily replaced by other business Dao layer without modification.
Related Posts of Their understanding of the J2EE three-tier architecture (design patterns and software differences between the contact)
-
Hibernate easy extract
Simple terms the following excerpt from hibernate: DAO mode, the database access layer implementation is hidden to the Data Accessor, the front said, DAO mode are in fact a combination of two modes, namely Data Accessor and domain Object mode. What i ...
-
hibernate brief introduction
1: hibernate, what are? 1: hibernate is a JDBC package is responsible for object persistence, in the middle layer, in the application and database has played a role as a bridge between a mapping tool. Second: Why is the use of hibernate? 1: the use o ...
-
Strength of live practice teaching materials, suitable for each person team look - UFIDA Hua Table CTO talk about "out of the software factory"
A few months ago, on reading "Going the software factory," one book, not yet published at that time, it can be considered the reference of the watch. Although the language rather uneventful, but the contents of people really can not but car ...
-
WEB test summary (architecture, design) the best part
1, for a total test architecture 1) thin-client, business logic rules in the server-side implementation of the majority. Such as news sites, portals, information websites. 2) fat client, a high security requirements, frequent interaction, complex bus ...
-
Software Performance
1.1 Software Performance In general, the performance is an indicator that the software system or component to its timeliness requirements in line with the level; followed by software performance, are an indicator can be used to measure time. Performa ...
-
What is the JPA
Same, JDO, also started compatible JPA. At the field of ORM, it seems that JPA is a benevolent government, is the normative specification. At the support of major manufacturers, JPA use became widespread. 2 Spring Spring + Hibernate often referred to ...
-
Java technology 25 study points
1. You need to master the object-oriented analysis and design (OOA / OOD), involving patterns (GOF, J2EEDP) as well as the integrated model. You should understand the UML, especially class, object, interaction and statediagrams. 2. You need to learn basic
-
In the servlet use Bean
According to Sun's definition, JavaBean is a reusable software components. In fact JavaBean is a Java class, through the package into a property and methods of treatment of a function or a business object, referred to as bean. Because JavaBean is ...
-
Java Technology wishing cow needed 25 points of study
1. You need to master the object-oriented analysis and design (OOA / OOD), involving patterns (GOF, J2EEDP) as well as the integrated model. You should understand the UML, especially class, object, interaction and statediagrams. 2. You need to learn basic













Leave a Reply