lightweight architecture
DESCRIPTION
Lightweight Architecture. Issue Date: 03/10/2008 Author: Vu Tran. Agenda. Objectives Lightweight Architecture Overview each component (Struts 2, Tiles 2, Spring 2.5, Hibernate 3.2) Demo Analysis the sample. Objectives. Opportunity from CSC Improve researchable, new technology - PowerPoint PPT PresentationTRANSCRIPT
©2003First Consulting Group, Inc.
Lightweight ArchitectureLightweight Architecture
Issue Date: 03/10/2008
Author: Vu Tran
© FCG | Slide 2 FCG Internal/Restricted/Confidential Version: 1.0 | Issue Date: 03/10/2008
AgendaAgenda
Objectives Lightweight Architecture Overview each component (Struts 2, Tiles 2, Spring 2.5,
Hibernate 3.2) Demo Analysis the sample
© FCG | Slide 3 FCG Internal/Restricted/Confidential Version: 1.0 | Issue Date: 03/10/2008
ObjectivesObjectives
Opportunity from CSC Improve researchable, new technology Technologies bring you increase productivity and quality. Next action. …
© FCG | Slide 4 FCG Internal/Restricted/Confidential Version: 1.0 | Issue Date: 03/10/2008
Lightweight Architecture
© FCG | Slide 5 FCG Internal/Restricted/Confidential Version: 1.0 | Issue Date: 03/10/2008
Productivity and QualityProductivity and Quality
Increase Productivity Increase Quality Productivity Quality Technologies.
– Struts, JSF…– Spring…– Hibernate, EJB, Top Link, JPA, JDO …
Struts 2.x, Tiles 2.x, Spring 2.5.x, Hibernate 3.2.x
© FCG | Slide 6 FCG Internal/Restricted/Confidential Version: 1.0 | Issue Date: 03/10/2008
ArchitectureArchitecture
DAO Interface Implement Layer (Retrieves, save entities using ORM, JDBC)
DAO Interface Layer (Defines persistence operations, independent of implementing technology)
Business Services Layer: Expose key functionality. Manages Transaction boundaries, include business logic
Persistence Domain Object (entity)
JDBC
Database
Web tier action: Process user input, call service layer, choose view to display
Remote Service: Webservice or other
protocol
JSP: or other Generice HTML
Presentation Layer
Business Layer
DAO Layer
© FCG | Slide 7 FCG Internal/Restricted/Confidential Version: 1.0 | Issue Date: 03/10/2008
Technologies
© FCG | Slide 8 FCG Internal/Restricted/Confidential Version: 1.0 | Issue Date: 03/10/2008
Struts2Struts2
Apache Struts2 was originally known as WebWork 2. Goal of Struts2:
– To make web development easier for developer.– To reduce XML configuration (intelligent defaults, annotations, …)– Actions are now POJOs increases testability and reduces
coupling in the framework.– Spring, SiteMesh and Tiles integration.– OGNL expression language integration.– Themes based ta libraries and Ajax tags.– Multiple view options (JSP, Freemarker, Velocity, XSLT)
© FCG | Slide 9 FCG Internal/Restricted/Confidential Version: 1.0 | Issue Date: 03/10/2008
ConfigurationConfiguration
Web.xml
<filter> <filter-name>struts2</filter-name> <filter-class> org.apache.struts2.dispatcher.FilterDispatcher </filter-class> </filter>
<filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
© FCG | Slide 10 FCG Internal/Restricted/Confidential Version: 1.0 | Issue Date: 03/10/2008
ConfigurationConfiguration
Struts.xml
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"><struts> <constant name="struts.devMode" value="true" /> <package name="person" extends="struts-default"> <action name="list" method="execute" class="personAction"> <result>pages/list.jsp</result> <result name="input">pages/list.jsp</result> </action> <action name="save" method="save“ class="personAction"> <result>/home.jsp</result> <result name="input">pages/list.jsp</result> </action> </package></struts>
© FCG | Slide 11 FCG Internal/Restricted/Confidential Version: 1.0 | Issue Date: 03/10/2008
TilesTiles
What is Tiles?– To be a templating framework built to simplify the development of
web application user interfaces.– To define page fragments which can be assembled into a complete
page at runtime
Footer
Header
BodyLeftnav
Footer
© FCG | Slide 12 FCG Internal/Restricted/Confidential Version: 1.0 | Issue Date: 03/10/2008
ConfigurationConfiguration
Web.xml
<listener> <listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class> </listener> <context-param> <param-name> org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG </param-name> <param-value> /WEB-INF/tiles.xml </param-value> </context-param>
© FCG | Slide 13 FCG Internal/Restricted/Confidential Version: 1.0 | Issue Date: 03/10/2008
ConfigurationConfiguration
Tiles.xml
<?xml version="1.0" encoding="ISO-8859-1" ?> <!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN" "http://tiles.apache.org/dtds/tiles-config_2_0.dtd"><tiles-definitions> <definition name="myapp.homepage" template="/template/layout.jsp"> <put-attribute name="title" value="everyone" /> <put-attribute name="header" value="/include/header.jsp" /> <put-attribute name="footer" value="/include/footer.jsp" /> </definition> <definition name="myapp.homepage.home" extends="myapp.homepage"> <put-attribute name="detail" value="/pages/detail.jsp" /> <put-attribute name="list" value="/pages/list.jsp" /> </definition></tiles-definitions>
© FCG | Slide 14 FCG Internal/Restricted/Confidential Version: 1.0 | Issue Date: 03/10/2008
JSP fileJSP file
JSP file:
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %><tiles:insertDefinition name="myapp.homepage.home" />
© FCG | Slide 15 FCG Internal/Restricted/Confidential Version: 1.0 | Issue Date: 03/10/2008
Spring
© FCG | Slide 16 FCG Internal/Restricted/Confidential Version: 1.0 | Issue Date: 03/10/2008
SpringSpring
What is Spring? – Spring is an open source framework for developing enterprise
application. – Spring is a light-weight framework for the development of
enterprise-ready applications – Spring can be used to configure declarative transaction
management, remote access to your logic using RMI or web services, mailing facilities and various options in persisting your data to a database.
– Spring framework can be used in modular fashion; it allows using in parts and leaving the other components, which is not required by the application.
© FCG | Slide 17 FCG Internal/Restricted/Confidential Version: 1.0 | Issue Date: 03/10/2008
SpringSpring
What are features of Spring?– Lightweight– Inversion of control (IOC)– Aspect oriented (AOP)– Container– MVC Framework– Transaction Management– JDBC Exception Handling
© FCG | Slide 18 FCG Internal/Restricted/Confidential Version: 1.0 | Issue Date: 03/10/2008
SpringSpring
What are features of Spring?– Lightweight– Inversion of control (IOC)– Aspect oriented (AOP)– Container– MVC Framework– Transaction Management– JDBC Exception Handling
© FCG | Slide 19 FCG Internal/Restricted/Confidential Version: 1.0 | Issue Date: 03/10/2008
SpringSpring
What are features of Spring?– Lightweight– Inversion of control (IOC)– Aspect oriented (AOP)– Container– MVC Framework– Transaction Management– JDBC Exception Handling
© FCG | Slide 20 FCG Internal/Restricted/Confidential Version: 1.0 | Issue Date: 03/10/2008
SpringSpring
What are features of Spring?– Lightweight– Inversion of control (IOC)– Aspect oriented (AOP)– Container– MVC Framework– Transaction Management– JDBC Exception Handling
© FCG | Slide 21 FCG Internal/Restricted/Confidential Version: 1.0 | Issue Date: 03/10/2008
SpringSpring
What are features of Spring?– Lightweight– Inversion of control (IOC)– Aspect oriented (AOP)– Container– MVC Framework– Transaction Management– JDBC Exception Handling
© FCG | Slide 22 FCG Internal/Restricted/Confidential Version: 1.0 | Issue Date: 03/10/2008
SpringSpring
What are features of Spring?– Lightweight– Inversion of control (IOC)– Aspect oriented (AOP)– Container– MVC Framework– Transaction Management– JDBC Exception Handling
© FCG | Slide 23 FCG Internal/Restricted/Confidential Version: 1.0 | Issue Date: 03/10/2008
SpringSpring
What are features of Spring?– Lightweight– Inversion of control (IOC)– Aspect oriented (AOP)– Container– MVC Framework– Transaction Management– JDBC Exception Handling
© FCG | Slide 24 FCG Internal/Restricted/Confidential Version: 1.0 | Issue Date: 03/10/2008
SpringSpring
What are modules of Spring?– The core container– Spring context – Spring AOP – Spring DAO – Spring ORM – Spring Web module – Spring MVC framework
© FCG | Slide 25 FCG Internal/Restricted/Confidential Version: 1.0 | Issue Date: 03/10/2008
SpringSpring
What are modules of Spring?– The core container– Spring context – Spring AOP – Spring DAO – Spring ORM – Spring Web module – Spring MVC framework
© FCG | Slide 26 FCG Internal/Restricted/Confidential Version: 1.0 | Issue Date: 03/10/2008
SpringSpring
What are modules of Spring?– The core container– Spring context – Spring AOP – Spring DAO – Spring ORM – Spring Web module – Spring MVC framework
© FCG | Slide 27 FCG Internal/Restricted/Confidential Version: 1.0 | Issue Date: 03/10/2008
SpringSpring
What are modules of Spring?– The core container– Spring context – Spring AOP – Spring DAO – Spring ORM – Spring Web module – Spring MVC framework
© FCG | Slide 28 FCG Internal/Restricted/Confidential Version: 1.0 | Issue Date: 03/10/2008
SpringSpring
What are modules of Spring?– The core container– Spring context – Spring AOP – Spring DAO – Spring ORM – Spring Web module – Spring MVC framework
© FCG | Slide 29 FCG Internal/Restricted/Confidential Version: 1.0 | Issue Date: 03/10/2008
SpringSpring
What are modules of Spring?– The core container– Spring context – Spring AOP – Spring DAO – Spring ORM – Spring Web module – Spring MVC framework
© FCG | Slide 30 FCG Internal/Restricted/Confidential Version: 1.0 | Issue Date: 03/10/2008
SpringSpring
What are modules of Spring?– The core container– Spring context – Spring AOP – Spring DAO – Spring ORM – Spring Web module – Spring MVC framework
© FCG | Slide 31 FCG Internal/Restricted/Confidential Version: 1.0 | Issue Date: 03/10/2008
SpringSpring
What is BeanFactory?– A BeanFactory is like a factory class that contains a collection of
beans. The BeanFactory holds Bean Definitions of multiple beans within itself and then instantiates the bean whenever asked for by clients.
BeanFactory is able to create associations between collaborating objects as they are instantiated. This removes the burden of configuration from bean itself and the beans client.
BeanFactory also takes part in the life cycle of a bean, making calls to custom initialization and destruction methods.
© FCG | Slide 32 FCG Internal/Restricted/Confidential Version: 1.0 | Issue Date: 03/10/2008
SpringSpring
What is Application Context?– Like BeanFactory, load bean definitions, wire beans together, and
dispense beans upon request. But it also provides: A means for resolving text messages, including support for
internationalization. A generic way to load file resources. Events to beans that are registered as listeners.
© FCG | Slide 33 FCG Internal/Restricted/Confidential Version: 1.0 | Issue Date: 03/10/2008
SpringSpring
Application Context config file
sa
© FCG | Slide 34 FCG Internal/Restricted/Confidential Version: 1.0 | Issue Date: 03/10/2008
Hibernate
© FCG | Slide 35 FCG Internal/Restricted/Confidential Version: 1.0 | Issue Date: 03/10/2008
HibernateHibernate
What is hibernate?– A pure Java object-relational mapping (ORM) and persistence
framework. Why do you need a tool like Hibernate?
– Improved productivity High-level object-oriented API Less Java code to write No SQL to write
– Improved performance Sophisticated caching Lazy loading Eager loading
– Improved maintainability A lot less code to write
– Improved portability ORM framework generates specific DB script for you.
© FCG | Slide 36 FCG Internal/Restricted/Confidential Version: 1.0 | Issue Date: 03/10/2008
HibernateHibernate
What does Hibernate simplify?– Saving and retrieving your domain objects– Making DB column and table name changes– Complex joins for retrieving related items– Schema creation from object model
Core Hibernate Framework– Session– SessionFactory– Configuration– Transaction– Query and Criteria
© FCG | Slide 37 FCG Internal/Restricted/Confidential Version: 1.0 | Issue Date: 03/10/2008
HibernateHibernate
Session– A single threaded, short-lived object representing a conversation
between application and the persistent store.– Session role
Wraps a JDBC connection Factory for Transaction Holds a mandatory cache of persistent objects, used when navigating
the object graph or looking up objects by identifier
– Session session = sessionFactory.openSession(); SessionFactory
– There is a single SessionFactory for the whole application and created during application initialization
– Cache session object– Cache generate SQL statements and other mapping metadata that
Hibernate uses at runtime– Cached data that has been read in one unit of work and may be
reused in a future unit of work
© FCG | Slide 38 FCG Internal/Restricted/Confidential Version: 1.0 | Issue Date: 03/10/2008
HibernateHibernate
Flow of Hibernate communication with RDBMS?– Load the Hibernate configuration file and create configuration
object. It will automatically load all hbm mapping files – Create session factory from configuration object – Get one session from this session factory – Create HQL query – Execute query to get list containing Java objects
© FCG | Slide 39 FCG Internal/Restricted/Confidential Version: 1.0 | Issue Date: 03/10/2008
ConfigurationConfiguration
hibernate.cfg.xml
<hibernate-configuration><session-factory><property name="connection.url">jdbc:mysql://localhost/tranquang?useUnicode=true&characterEncoding=UTF-8</property><property name="connection.username">root</property><property name="connection.driver_class">com.mysql.jdbc.Driver</property><property name="dialect">org.hibernate.dialect.MySQLDialect</property><property name="connection.password"></property><property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property><property name="connection.pool_size">10</property><property name="current_session_context_class">thread</property><property name="show_sql">false</property><property name="hbm2ddl.auto">update</property></session-factory></hibernate-configuration>
© FCG | Slide 40 FCG Internal/Restricted/Confidential Version: 1.0 | Issue Date: 03/10/2008
Demo
© FCG | Slide 41 FCG Internal/Restricted/Confidential Version: 1.0 | Issue Date: 03/10/2008
DeploymentDeployment
JDK5 Ajax: jquery Struts2 Tiles2 Spring2.5 Hibernate3.2 Server: Jetty
Q & A
Thank You