1 / 43

Lightweight Architecture

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

cosima
Download Presentation

Lightweight Architecture

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lightweight Architecture Issue Date: 03/10/2008 Author: Vu Tran

  2. Agenda • Objectives • Lightweight Architecture • Overview each component (Struts 2, Tiles 2, Spring 2.5, Hibernate 3.2) • Demo • Analysis the sample

  3. Objectives • Opportunity from CSC • Improve researchable, new technology • Technologies bring you increase productivity and quality. • Next action. • …

  4. Lightweight Architecture

  5. Productivity 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

  6. Presentation Layer Business Layer DAO Layer Architecture

  7. Technologies

  8. Struts2 • 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)

  9. Configuration • 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>

  10. Configuration • 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>

  11. Header Leftnav Body Footer Footer Tiles • 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

  12. Configuration • 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>

  13. Configuration • 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>

  14. JSP file • JSP file: <%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %> <tiles:insertDefinition name="myapp.homepage.home" />

  15. Spring

  16. Spring • 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.

  17. Spring • What are features of Spring? • Lightweight • Inversion of control (IOC) • Aspect oriented (AOP) • Container • MVC Framework • Transaction Management • JDBC Exception Handling

  18. Spring • What are features of Spring? • Lightweight • Inversion of control (IOC) • Aspect oriented (AOP) • Container • MVC Framework • Transaction Management • JDBC Exception Handling

  19. Spring • What are features of Spring? • Lightweight • Inversion of control (IOC) • Aspect oriented (AOP) • Container • MVC Framework • Transaction Management • JDBC Exception Handling

  20. Spring • What are features of Spring? • Lightweight • Inversion of control (IOC) • Aspect oriented (AOP) • Container • MVC Framework • Transaction Management • JDBC Exception Handling

  21. Spring • What are features of Spring? • Lightweight • Inversion of control (IOC) • Aspect oriented (AOP) • Container • MVC Framework • Transaction Management • JDBC Exception Handling

  22. Spring • What are features of Spring? • Lightweight • Inversion of control (IOC) • Aspect oriented (AOP) • Container • MVC Framework • Transaction Management • JDBC Exception Handling

  23. Spring • What are features of Spring? • Lightweight • Inversion of control (IOC) • Aspect oriented (AOP) • Container • MVC Framework • Transaction Management • JDBC Exception Handling

  24. Spring • What are modules of Spring? • The core container • Spring context • Spring AOP • Spring DAO • Spring ORM • Spring Web module • Spring MVC framework

  25. Spring • What are modules of Spring? • The core container • Spring context • Spring AOP • Spring DAO • Spring ORM • Spring Web module • Spring MVC framework

  26. Spring • What are modules of Spring? • The core container • Spring context • Spring AOP • Spring DAO • Spring ORM • Spring Web module • Spring MVC framework

  27. Spring • What are modules of Spring? • The core container • Spring context • Spring AOP • Spring DAO • Spring ORM • Spring Web module • Spring MVC framework

  28. Spring • What are modules of Spring? • The core container • Spring context • Spring AOP • Spring DAO • Spring ORM • Spring Web module • Spring MVC framework

  29. Spring • What are modules of Spring? • The core container • Spring context • Spring AOP • Spring DAO • Spring ORM • Spring Web module • Spring MVC framework

  30. Spring • What are modules of Spring? • The core container • Spring context • Spring AOP • Spring DAO • Spring ORM • Spring Web module • Spring MVC framework

  31. Spring • 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.

  32. Spring • 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.

  33. Spring • Application Context config file sa

  34. Hibernate

  35. Hibernate • 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.

  36. Hibernate • 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

  37. Hibernate • 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

  38. Hibernate • 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

  39. Configuration • hibernate.cfg.xml <hibernate-configuration> <session-factory> <property name="connection.url">jdbc:mysql://localhost/tranquang?useUnicode=true&amp;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>

  40. Demo

  41. Deployment • JDK5 • Ajax: jquery • Struts2 • Tiles2 • Spring2.5 • Hibernate3.2 • Server: Jetty

  42. Q & A

  43. Thank You

More Related