Monday, April 22, 2013

Maven / Spring / Hibernate / JSF2 Tutorial - First Part (Introduction)

In this first part we introduce some notions related to the Java Enterprise Edition specification (JEE).
We also give an overview of the tools we are going to use.


Outline:


1.1 - Introduction of the multi-tier architecture.
  a - The mainframe architecture
  b - The client/server (2-tier) architecture
  c - The 3-tier architecture
  d - The multi-tier (n-tier) architecture

1.2 - The 3-tier logical architecture
  a - The presentation layer
  b - The service (business) layer
  c - The persistence (data access) layer
  d - Advantages of the 3-tier architecture


1.3 - Tools' overview.
  a - Java Server Faces (JSF)
  b - Hibernate
  c - Spring
  d - Maven
  e - JPA



1.1 - Introduction of the multi-tier architecture:

Automated computing has evolved in the last decades through many physical architectures:

a - The mainframe architecture:

A central computer (the mainframe) is doing the hole work. Several passive terminals connect to the mainframe to order computations and display the results. While the mainframe's computation power permits to thousands of users to be simultaneously connected, the terminals offer poor interfaces.

b - The client/server (2-tier) architecture:

A user uses a client machine to order computations to a server machine. The server performs the computations and returns the results to the client which handles (using its own resources) the display of the results to the user using a more or less sophisticated interface.

c - The 3-tier architecture:

It is an enhancement of the client/server architecture where the server part is split into two parts: (i) an application server acting as an intermediate (a middleware) between the client and (ii) a data server holding the data being computed.

d - The multi-tier (n-tier) architecture:

It is an enhancement of the 3-tier architectue where the server parts can be split again to match some security, flexibility or performance targets. For example the authentication part of the application could be handled by a security server (for instance a LDAP directory).

1.2 - The 3-tier Logical Architecture:

We put the focus here on the underlying logic of thinking (designing) applications to be deployed and run over a 3-tier architecture. Roughly speaking the purpose of almost any application is (i) to collect some data from an end user, possibly apply some treatment over the data before storing it in a data base, or (ii) to retrieve some data previously stored in the data base, possibly apply some treatment over the data before presenting the result to the end user. This definition addresses three application layers:

a - The presentation layer:

It is the part of the application that interacts with the end user. We call it also the Human-Computer Interface. This layer relays the requests of the user to the business layer (defined below) and relays back to the former the results of the treatments performed by the latter.

b - The service (business) layer:

It is the functional part of the application. It implements the logic of the application, i.e. the different operations the application could perform over the data according to a set of business rules.
This layer offers its business services to the presentation layer and to provide these services it may use the data stored by the application by addressing a lower-level layer : the data access layer (see below).

c - The persistence (data access) layer:

This layer handles the access to the application data. Whether data is stored on the same server as the business layer or not the data access layer provides data access services to the business layer in a transparent way.

d - Advantages of the 3-tier architecture:

Loose coupling between the three layers eases the design and the maintenance of an application.
For instance a bank could propose a different presentation of the same business service (which is implemented once) depending on the way a customer request it: through a web-site, using her smart-phone or by interacting with an ATM (Automated Teller or Bank Machine).
Splitting down these different layers permits also a collaborative design of the application where graphic, business and data base experts could work each on a different layer, then easily integrate their works to the same application project.
The 3-tier logical architecture permits also a better maintenance of an application where modifying one layer does not necessarily imply modifying the other ones. For instance changing the graphical chart of the presentation layer or the order according to which data is displayed by the application does (and should) not impact the business layer.

1.3 - Tools overview:

We present in this section the different tools we use in the tutorial.

a - Java Server Faces (JSF):

JSF is an MVC-oriented java framework for designing web applications.
MVC stands here for Model-View-Controller which is a user interface programming paradigm that separates the data (Model), the presentation (View) and the treatment (Controller).
It it is based on the notion of components where the state of a component is saved when rendering the page, updated then restored back after a request is executed.
We use JSF with an extension: RichFaces which enriches its set of GUI graphical components.

b - Hibernate:

Hibernate is an object-relational mapping (ORM) library for the Java language, providing a framework for mapping from Java classes to database tables (and from Java data types to SQL data types). Hibernate also provides data query and retrieval facilities. It also generates the SQL calls and attempts to relieve the developer from manual result set handling and object conversion and keep the application portable to all supported SQL databases with little performance overhead.

c - Spring:

The Spring Framework is an open source application framework for the Java platform. It defines extensions for building web applications on top of the Java EE platform.

Spring Core: Spring's core is based on (i) a generic factory of particular objects, named Java Beans and (ii) a container permitting to store these beans. Spring's core permits also dependency injection or injecting beans inside others as properties. In this way beans can be composed in a declarative way using for example simple XML configuration files (in contrast with the imperative way, i.e. inside java code).

Spring DAO (Data Access Objects): Supports data base access features including JDBC and Hibernate.

Spring Context, Spring MVC: Supports integration with JSF among other frameworks.

Spring Security: Handles access control and security policies of the application.

We use Spring in this tutorial as the bandmaster of the tools: it handles the Controller layer of JSF and delegates to Hibernate the data access part of the work. Moreover Spring's bean dependency injection is used to (loosely) couple the business and the data access layer of our application.
Eventually we use Spring Security to handle access control policies of our application.

What are Java Beans ? A Java Bean is a Java Class respecting the following conventions:
- The class implements the java.io.Serializable interface to support serialization. (In computer science, in the context of data storage and transmission, serialization is the process of translating data structures or object state into a format that can be stored (for example, in a file or memory buffer), or transmitted across a network connection link) and "resurrected" later in the same or another computer environment. Wikipedia);
- The class declares a parameter-less constructor (the default constructor);
- All the private fields of the class should admit corresponding properties, i.e. public getter and setter with names obtained by concatenating get or set to the name of the field with its first letter capitalized.
- The class shouldn't  be declared as final.

d - Maven:

Maven is a build automation tool used primarily for Java projects. Maven uses an XML file to describe the software project being built, its dependencies on other external modules and components, the build order, directories, and required plug-ins. It comes with predefined targets for performing certain well-defined tasks such as compilation of code and its packaging. Maven dynamically downloads Java libraries and Maven plug-ins from one or more repositories such as the Maven 2 Central Repository, and stores them in a local cache.

e - JPA:

The Java Persistence API, sometimes referred to as JPA, is a Java programming language framework managing relational data in applications using Java Platform, Standard Edition and Java Platform, Enterprise Edition.



Previous | Next

No comments:

Post a Comment