37
Struts Petstore Struts University Series

Struts Petstore

  • Upload
    alexia

  • View
    50

  • Download
    2

Embed Size (px)

DESCRIPTION

Struts Petstore. Struts University Series. Abstract. - PowerPoint PPT Presentation

Citation preview

Page 1: Struts Petstore

Struts Petstore

Struts University Series

Page 2: Struts Petstore

Abstract

Struts has always shipped with a simple example application. But for many teams,

MailReader is a bit too simple. Struts Petstore is a full-featured, production-grade Struts application inspired by the infamous

Java Pet Store. Struts Petstore uses a professional architecture that hooks up to

Apache iBATIS for data access. Let's have a look ...

Page 3: Struts Petstore

Struts PetStore

Page 4: Struts Petstore
Page 5: Struts Petstore
Page 6: Struts Petstore
Page 7: Struts Petstore
Page 8: Struts Petstore
Page 9: Struts Petstore
Page 10: Struts Petstore
Page 11: Struts Petstore
Page 12: Struts Petstore
Page 13: Struts Petstore
Page 14: Struts Petstore

A little background

Sun creates J2EE Pet StoreDemonstrates patterns

Microsoft creates .NET Pet ShopDemonstrates performance

Clinton Begin creates JPetStoreDemonstrates iBATIS

Page 15: Struts Petstore

iBATIS and Struts

iBATISData mapping framework for SQLCompares to Hibernate and OJB

StrutsWeb application framework Compares to WebWork and Tapestry

Clinton Begin Inventor of iBATIS and author of JPetStore

Page 16: Struts Petstore

The Purpose of JPetStore

Clinton Begin wrote JPetstore to showJava is easyJava is low costJava is highly productiveJava enables choiceJava enables change

Page 17: Struts Petstore

The Purpose of JPetStore

Clinton Begin wrote JPetstore to showJava is easyJava is low costJava is highly productiveJava enables choiceJava enables change iBATIS is cool

Page 18: Struts Petstore

Advantages without Tradeoffs

JPetStore uses superior design and architectureClearly defined application layersUses known best practices and patternsAvoids known worst practices

No stored proceduresNo SQL embedded in Java codeNo HTML in the databaseNo generated code

Page 19: Struts Petstore
Page 20: Struts Petstore
Page 21: Struts Petstore
Page 22: Struts Petstore

Presentation

Model View Controller PatternWell know and proven (GOF)Simple and maintainable

Apache StrutsFreely available, open sourceBased on JavaBeans

Page 23: Struts Petstore
Page 24: Struts Petstore

Domain

JavaBeans Components with properties and behavior Plug into presentation and persistence layers Compatible with many frameworks GUI tools available (IDEs, et cetera)

Logic Classes None/Verb separation More maintainable than prior versions

Page 25: Struts Petstore
Page 26: Struts Petstore

Persistence

Data Access Objects “Pluggable” persistance components Proven abstract factory pattern (GoF) Improves maintainability and flexibility

SQL Maps Reduces/eliminates repetive JDBC code Improves performance with caching Portable across many databases Based on JavaBeans

Page 27: Struts Petstore
Page 28: Struts Petstore

Link to a category query

JavaServer Page:

<html:link page="/shop/viewCategory.shtml?categoryId=DOGS">

Struts Config:

<action path="/shop/viewCategory" type="com.ibatis.struts.BeanAction"

name="catalogBean" scope="session" validate="false" > <forward name="success"

path="/catalog/Category.jsp"/> </action>

Page 29: Struts Petstore

CatalogBean

public String viewCategory() {

if (categoryId != null) {

productList = catalogService.getProductListByCategory(categoryId);

category = catalogService.getCategory(categoryId);

}

return "success";

}

Page 30: Struts Petstore

CatalogService

public PaginatedList getProductListByCategory(String categoryId) {

return queryForPaginatedList("getProductListByCategory", categoryId, PAGE_SIZE);

}

public Category getCategory(String categoryId) {

return (Category) queryForObject("getCategory", categoryId);

}

Page 31: Struts Petstore

SqlMaps

<select id="getCategoryList" resultMap="categoryResult">

select CATID, NAME, DESCN from CATEGORY

</select>

<select id="getCategory" resultMap="categoryResult" parameterClass="string">

select CATID, NAME, DESCN from CATEGORY where CATID = #value#

</select>

Page 32: Struts Petstore

ResultMap

<resultMap id="categoryResult" class="category">

<result property="categoryId" column="CATID"/>

<result property="name" column="NAME"/>

<result property="description" column="DESCN"/>

</resultMap>

Page 33: Struts Petstore

Cache Model

<cacheModel id="oneDayCategory" type="LRU">

<flushInterval hours="24"/>

</cacheModel>

Page 34: Struts Petstore

Cache Model

<cacheModel id="oneDayCategory" type="LRU">

<flushInterval hours="24"/>

<flushOnExecute statement="insertCategory"/>

</cacheModel>

Page 35: Struts Petstore

Dynamic SQL

<select id="getCategoryList" resultMap="categoryResult">

select CATID, NAME, DESCN from CATEGORY

</select>

<select id="getCategory" resultMap="categoryResult" parameterClass="string">

select CATID, NAME, DESCN from CATEGORY where CATID = #value#

</select>

Page 36: Struts Petstore

Dynamic SQL

<select id="getCategory" resultMap="categoryResult" parameterClass="string">

select CATID, NAME, DESCN from CATEGORY

<dynamic prepend="WHERE">

<isParameterPresent>

where CATID = #value#

</isParameterPresent>

</dynamic>

</select>

Page 37: Struts Petstore

Struts University Series