JaVa
   

Case Study Example: The Pet Store

The case study app is an online pet store. In this example, we have a catalog system stored in a database that is accessed by a Web app. This example can display the catalog to customers and also has a small content-management system that enables the owner of the pet store to enter catalog information (for example, new pets and new categories of pets). You can download the complete code from www.wrox.com. The case study app is a more complex—but more realistic—example for demonstrating how open source tools are used in a real production environment. Even so, this example is by no means a complete pet store like the J2EE Blueprint Pet Store. Sun’s purpose for building the J2EE Blueprint Pet Store is to show good design and coding techniques for building an e-commerce app with J2EE. Conversely, our pet store case study is built to demonstrate good techniques for testing, building, and deploying a J2EE app with open source tools. We’ll work through several iterations of the pet store. The baseline version has no connection pooling and no EJBs. This iteration is a simple, small example. It has several JSPs, a few classes that use JDBC, and some tables in a database. We discuss the details of the baseline version in subsequent sections of this chapter. The second iteration of the case study changes the content management piece of the system to a container managed persistence (CMP) entity bean, which implements the backend product management. This approach allows online product entry (add, delete, and edit). This iteration demonstrates how to incorporate enterprise bean deployment into your Web app and how to ensure that the unit testing of the category systems still works after the addition of the CMP entity bean support. The third iteration of the case study uses an EJB stateless session bean to add pooling of connections and prepared statements. We use this iteration to demonstrate the use of JUnitPerf and show the time savings from pooling prepared statements when the site is hit by many users (the original, non-pooled version would most likely be a bottleneck under heavy traffic). The fourth iteration of the case study creates a Catalog TagLib. We use Cactus to test this TagLib. This is an excellent example to show how to operate and run Cactus tests and how to integrate them in the build/deploy process.

Java Start Sidebar
Database

The example apps in this tutorial use MS SQL Server, primarily because it is what a large number of developers use. Realizing the irony of writing a tutorial about open source tools, yet using a closed source database, we ported several of the example apps to HSQL (a very fast, light-weight, open source database written in Java). These example apps are available on the tutorial’s Web site at: www.wrox.com.

Java End Sidebar

The fifth iteration of the case study refactors the JSPs using the Apache Struts project. Then, it uses HttpUnit to test that the app still works. The HttpUnit test is run against the baseline and the new version to show that the new version works like the old.

The sixth and final iteration of the case study refactors the Web app to use Extensible Style Language Transformation (XSLT) instead of JSP to do the catalog view. It then compares the throughput of the two approaches using JMeter.


JaVa
Comments