Thứ Năm, 14 tháng 3, 2013

Struts 2 Architecture

From a high level, Struts2 is a pull-MVC (or MVC2) framework. The Model-View-Controller pattern in Struts2 is realized with following five core components:
  • Actions
  • Interceptors
  • Value Stack / OGNL
  • Results / Result types
  • View technologies
Struts 2 is slightly different from a traditional MVC framework in that the action takes the role of the model rather than the controller, although there is some overlap.
Struts 2 Architecture
The above diagram depicts the Model, View and Controller to the Struts2 high level architecture. The controller is implemented with a Struts2 dispatch servlet filter as well as interceptors, the model is implemented with actions, and the view as a combination of result types and results. The value stack and OGNL provide common thread, linking and enabling integration between the other components.
Apart from the above components, there will be a lot of information that relates to configuration. Configuration for the web application, as well as configuration for actions, interceptors, results, etc.
This is the architectural overview of the Struts 2 MVC pattern. We will go through each component in more detail in the subsequent chapters.

Request life cycle:

Based on the above digram, one can explain the user's request life cycle in Struts 2 as follows:
  • User sends a request to the server for requesting for some resource (i.e pages).
  • The FilterDispatcher looks at the request and then determines the appropriate Action.
  • Configured interceptors functionalities applies such as validation, file upload etc.
  • Selected action is executed to perform the requested operation.
  • Again, configured interceptors are applied to do any post-processing if required.
  • Finally the result is prepared by the view and returns the result to the user.

Shall we do some Spring together?

Shall we do some Spring together?

About: In this tutorial I will show you, how to write Spring webapplication from the scratch and we will do it with step-by-step approach. Maybe you’ve already tried some Spring but you didn’t have the opportunity or will to use more than one particular Spring technology. Maybe you gave up because it looked hard to get all the libraries correct. Don’t worry, we will go together through every step and create working application from the scratch.

Targeted audience: Java programmers. If you’re new to Spring, I hope this will help you to start with Spring development. We will specifically look at assembling complete application with handful of technologies.

Prerequisites: You should be familiar with Java programming language. You will require some general knowledge about web applications, Servlet technology, SQL, REST, ORM , unit testing and dependency injection. We won’t go too deep in any of those, but if something is new to you please check at least some wiki pages or presentations or maybe even tutorials.

List of chapters:
Read more: http://vrtoonjava.wordpress.com/2012/06/17/shall-we-do-some-spring-together/

Thứ Tư, 13 tháng 3, 2013

Presentation Layer - Business Layer - Data Access Layer

Presentation Layer

JSF is used to build the presentation layer of the application. JFS allows us to create rich GUI for web application. It resolves the technical challenges of creating rich GUI web application. In this layer we have JSP pages
consists of JSF components. All the requests to the web server pass through FacesServlet.

Business Layer

The POJO classes and classes to process the business logic are used to create the Business Layer. The POJO classes, with the help of spring framework, create an ideal solution to implement the Business Layer.

Data Access Layer

The data access layer handles all the logic to save and retrieve the data from database. Hibernate O/R mapping tools is an ideal solution for enterprise application of any size. Hibernate handles all the logic to store and retrieve POJO objects. It also handles resource management and transaction management activities.

Java Serialization.

Java has a built in mechanism for converting the state of an object into a specific form of bytes. All of the data , type , and member information of the object is converted into this byte format by a process called "Serialization" and is stored in a file.

The beauty of this technique is that , that Serialization is a JVM independent process. Hence you can serialize an object from Java , and deserialize it from the .NET platform.

Transient Keyword.

The transient keyword is attached to a member field of an object , whose state you do not wish to persist during serialization.

Difference between Hibernate Sessions and Transactions.


Session

Most technology terms mean literally what they represent in the English dictionary, well with a little ketchup. A session is a lease of time that you’d take with a fellow, or any other entity. Once you are in a session with the other entity, you can actively use it ; or communicate with whatever communication mechanism that entity has.

Transaction

A transaction occurs AFTER a session. Once you are in a session, you perform transactions. You are in absolute need to be in a session to perform a transaction. You cannot perform a transaction with an entity without being in session with it. For example let’s take an example of a ATM machine.
You go and stand in queue of waiting customers who wish to acquire a session with the ATM. Once the ATM is free, you initiate your session. Now you and the ATM are tunneled, face to face and ready to do business. You dial your pin, and this is where you start your transaction. So any material work you perform with an entity will be called a transaction. So basically the purpose of acquiring a session IS in effect because you wished to perform a transaction. The transaction is the real action that full fills the business you have with the other entity.
Making the other entity aware of yourself is hence called a session, in which you and the entity have now shaken hands. After that as you work, it’ll be termed as a transaction.

What's the difference between @Component, @Repository & @Service annotations in Spring?


In Spring 2.0 and later, the @Repository annotation is a marker for any class that fulfills the role or stereotype (also known as Data Access Object or DAO) of a repository. Among the uses of this marker is the automatic translation of exceptions.
Spring 2.5 introduces further stereotype annotations: @Component, @Service, and @Controller. @Component is a generic stereotype for any Spring-managed component. @Repository, @Service, and @Controller are specializations of @Component for more specific use cases, for example, in the persistence, service, and presentation layers, respectively.
Therefore, you can annotate your component classes with @Component, but by annotating them with @Repository, @Service, or @Controller instead, your classes are more properly suited for processing by tools or associating with aspects. For example, these stereotype annotations make ideal targets for pointcuts.
Thus, if you are choosing between using @Component or @Service for your service layer, @Service is clearly the better choice. Similarly, as stated above, @Repository is already supported as a marker for automatic exception translation in your persistence layer.
| Annotation | Meaning                                             |
+------------+-----------------------------------------------------+
| @Component | generic stereotype for any Spring-managed component |
| @Repository| stereotype for persistence layer                    |
| @Service   | stereotype for service layer                        
| @Controller| stereotype for presentation layer (spring-mvc) |