Download - Struts Petstore
![Page 1: Struts Petstore](https://reader036.vdocuments.us/reader036/viewer/2022081504/56813ff0550346895daafec4/html5/thumbnails/1.jpg)
Struts Petstore
Struts University Series
![Page 2: Struts Petstore](https://reader036.vdocuments.us/reader036/viewer/2022081504/56813ff0550346895daafec4/html5/thumbnails/2.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022081504/56813ff0550346895daafec4/html5/thumbnails/3.jpg)
Struts PetStore
![Page 4: Struts Petstore](https://reader036.vdocuments.us/reader036/viewer/2022081504/56813ff0550346895daafec4/html5/thumbnails/4.jpg)
![Page 5: Struts Petstore](https://reader036.vdocuments.us/reader036/viewer/2022081504/56813ff0550346895daafec4/html5/thumbnails/5.jpg)
![Page 6: Struts Petstore](https://reader036.vdocuments.us/reader036/viewer/2022081504/56813ff0550346895daafec4/html5/thumbnails/6.jpg)
![Page 7: Struts Petstore](https://reader036.vdocuments.us/reader036/viewer/2022081504/56813ff0550346895daafec4/html5/thumbnails/7.jpg)
![Page 8: Struts Petstore](https://reader036.vdocuments.us/reader036/viewer/2022081504/56813ff0550346895daafec4/html5/thumbnails/8.jpg)
![Page 9: Struts Petstore](https://reader036.vdocuments.us/reader036/viewer/2022081504/56813ff0550346895daafec4/html5/thumbnails/9.jpg)
![Page 10: Struts Petstore](https://reader036.vdocuments.us/reader036/viewer/2022081504/56813ff0550346895daafec4/html5/thumbnails/10.jpg)
![Page 11: Struts Petstore](https://reader036.vdocuments.us/reader036/viewer/2022081504/56813ff0550346895daafec4/html5/thumbnails/11.jpg)
![Page 12: Struts Petstore](https://reader036.vdocuments.us/reader036/viewer/2022081504/56813ff0550346895daafec4/html5/thumbnails/12.jpg)
![Page 13: Struts Petstore](https://reader036.vdocuments.us/reader036/viewer/2022081504/56813ff0550346895daafec4/html5/thumbnails/13.jpg)
![Page 14: Struts Petstore](https://reader036.vdocuments.us/reader036/viewer/2022081504/56813ff0550346895daafec4/html5/thumbnails/14.jpg)
A little background
Sun creates J2EE Pet StoreDemonstrates patterns
Microsoft creates .NET Pet ShopDemonstrates performance
Clinton Begin creates JPetStoreDemonstrates iBATIS
![Page 15: Struts Petstore](https://reader036.vdocuments.us/reader036/viewer/2022081504/56813ff0550346895daafec4/html5/thumbnails/15.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022081504/56813ff0550346895daafec4/html5/thumbnails/16.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022081504/56813ff0550346895daafec4/html5/thumbnails/17.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022081504/56813ff0550346895daafec4/html5/thumbnails/18.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022081504/56813ff0550346895daafec4/html5/thumbnails/19.jpg)
![Page 20: Struts Petstore](https://reader036.vdocuments.us/reader036/viewer/2022081504/56813ff0550346895daafec4/html5/thumbnails/20.jpg)
![Page 21: Struts Petstore](https://reader036.vdocuments.us/reader036/viewer/2022081504/56813ff0550346895daafec4/html5/thumbnails/21.jpg)
![Page 22: Struts Petstore](https://reader036.vdocuments.us/reader036/viewer/2022081504/56813ff0550346895daafec4/html5/thumbnails/22.jpg)
Presentation
Model View Controller PatternWell know and proven (GOF)Simple and maintainable
Apache StrutsFreely available, open sourceBased on JavaBeans
![Page 23: Struts Petstore](https://reader036.vdocuments.us/reader036/viewer/2022081504/56813ff0550346895daafec4/html5/thumbnails/23.jpg)
![Page 24: Struts Petstore](https://reader036.vdocuments.us/reader036/viewer/2022081504/56813ff0550346895daafec4/html5/thumbnails/24.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022081504/56813ff0550346895daafec4/html5/thumbnails/25.jpg)
![Page 26: Struts Petstore](https://reader036.vdocuments.us/reader036/viewer/2022081504/56813ff0550346895daafec4/html5/thumbnails/26.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022081504/56813ff0550346895daafec4/html5/thumbnails/27.jpg)
![Page 28: Struts Petstore](https://reader036.vdocuments.us/reader036/viewer/2022081504/56813ff0550346895daafec4/html5/thumbnails/28.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022081504/56813ff0550346895daafec4/html5/thumbnails/29.jpg)
CatalogBean
public String viewCategory() {
if (categoryId != null) {
productList = catalogService.getProductListByCategory(categoryId);
category = catalogService.getCategory(categoryId);
}
return "success";
}
![Page 30: Struts Petstore](https://reader036.vdocuments.us/reader036/viewer/2022081504/56813ff0550346895daafec4/html5/thumbnails/30.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022081504/56813ff0550346895daafec4/html5/thumbnails/31.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022081504/56813ff0550346895daafec4/html5/thumbnails/32.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022081504/56813ff0550346895daafec4/html5/thumbnails/33.jpg)
Cache Model
<cacheModel id="oneDayCategory" type="LRU">
<flushInterval hours="24"/>
</cacheModel>
![Page 34: Struts Petstore](https://reader036.vdocuments.us/reader036/viewer/2022081504/56813ff0550346895daafec4/html5/thumbnails/34.jpg)
Cache Model
<cacheModel id="oneDayCategory" type="LRU">
<flushInterval hours="24"/>
<flushOnExecute statement="insertCategory"/>
</cacheModel>
![Page 35: Struts Petstore](https://reader036.vdocuments.us/reader036/viewer/2022081504/56813ff0550346895daafec4/html5/thumbnails/35.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022081504/56813ff0550346895daafec4/html5/thumbnails/36.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022081504/56813ff0550346895daafec4/html5/thumbnails/37.jpg)
Struts University Series