Plants by WebSphere



Getting started
Locating database tables
Locating source code
Reviewing coding notes

Getting started

You can create a unique e-mail address and password for the Plants by WebSphere Sample by clicking register for your own account here on the Login page. In addition, a default e-mail address and password exist for the Plants by WebSphere Sample that is presented in the following table:


E-mail address plants@plantsbywebsphere.ibm.com
Password plants

Locating database tables

The database tables for this Sample are CUSTOMER, INVENTORY, ORDERINFO, ORDERITEM, IDGENERATOR, BACKORDER, and SUPPLIER. These tables are found in the PLANTSDB database. The PLANTSDB database is in the PlantsByWebSphere.ear file, and is located in the profile_root/installedApps/cell name/PlantsByWebSphere.ear/Database/PLANTSDB directory, where cell name is the name of the cell where your application is installed.

View the table layout in the following SQL statements:


	CREATE TABLE CUSTOMER
  	 (  CUSTOMERID VARCHAR(250) NOT NULL,
   	 PASSWORD VARCHAR(250),
   	 FIRSTNAME VARCHAR(250),
   	 LASTNAME VARCHAR(250),
   	 ADDR1 VARCHAR(250),
   	 ADDR2 VARCHAR(250),
   	 ADDRCITY VARCHAR(250),
   	 ADDRSTATE VARCHAR(250),
   	 ADDRZIP VARCHAR(250),
   	 PHONE VARCHAR(250));

ALTER TABLE CUSTOMER ADD CONSTRAINT PK_CUSTOMER PRIMARY KEY (CUSTOMERID); CREATE TABLE INVENTORY ( INVENTORYID VARCHAR(250) NOT NULL, NAME VARCHAR(250), HEADING VARCHAR(250), DESCRIPTION VARCHAR(250), PKGINFO VARCHAR(250), IMAGE VARCHAR(250), IMGBYTES LONG BIT VARYING, PRICE REAL, COST REAL, CATEGORY INTEGER, QUANTITY INTEGER, NOTES VARCHAR(250), ISPUBLIC INTEGER, MINTHRESHOLD INTEGER NOT NULL, MAXTHRESHOLD INTEGER NOT NULL); ALTER TABLE INVENTORY ADD CONSTRAINT PK_INVENTORY PRIMARY KEY (INVENTORYID); CREATE TABLE ORDER1 ( ORDERID VARCHAR(250) NOT NULL, SELLDATE VARCHAR(250), BILLNAME VARCHAR(250), BILLADDR1 VARCHAR(250), BILLADDR2 VARCHAR(250), BILLCITY VARCHAR(250), BILLSTATE VARCHAR(250), BILLZIP VARCHAR(250), BILLPHONE VARCHAR(250), SHIPNAME VARCHAR(250), SHIPADDR1 VARCHAR(250), SHIPADDR2 VARCHAR(250), SHIPCITY VARCHAR(250), SHIPSTATE VARCHAR(250), SHIPZIP VARCHAR(250), SHIPPHONE VARCHAR(250), CREDITCARD VARCHAR(250), CCNUM VARCHAR(250), CCEXPIREMONTH VARCHAR(250), CCEXPIREYEAR VARCHAR(250), CARDHOLDER VARCHAR(250), SHIPPINGMETHOD INTEGER NOT NULL, PROFIT REAL NOT NULL, CUSTOMERID VARCHAR(250)); ALTER TABLE ORDER1 ADD CONSTRAINT PK_ORDER1 PRIMARY KEY (ORDERID); CREATE TABLE ORDERITEM ( INVENTORYID VARCHAR(250) NOT NULL, NAME VARCHAR(250), PKGINFO VARCHAR(250), PRICE REAL NOT NULL, COST REAL NOT NULL, CATEGORY INTEGER NOT NULL, QUANTITY INTEGER NOT NULL, SELLDATE VARCHAR(250), ORDER_ORDERID VARCHAR(250) NOT NULL); ALTER TABLE ORDERITEM ADD CONSTRAINT PK_ORDERITEM PRIMARY KEY (INVENTORYID, ORDER_ORDERID); CREATE TABLE IDGENERATOR ( IDNAME VARCHAR(250) NOT NULL, IDVALUE INTEGER NOT NULL); ALTER TABLE IDGENERATOR ADD CONSTRAINT PK_IDGENERATOR PRIMARY KEY (IDNAME); CREATE TABLE BACKORDER ( BACKORDERID VARCHAR(250) NOT NULL, INVENTORYID VARCHAR(250), QUANTITY INTEGER NOT NULL, STATUS VARCHAR(250), LOWDATE BIGINT NOT NULL, ORDERDATE BIGINT NOT NULL, SUPPLIERORDERID VARCHAR(250) NULL); ALTER TABLE BACKORDER ADD CONSTRAINT PK_BACKORDER PRIMARY KEY (BACKORDERID); CREATE TABLE SUPPLIER ( SUPPLIERID VARCHAR(250) NOT NULL, NAME VARCHAR(250), STREET VARCHAR(250), CITY VARCHAR(250), USSTATE VARCHAR(250), ZIP VARCHAR(250), PHONE VARCHAR(250), URL VARCHAR(250)); ALTER TABLE SUPPLIER ADD CONSTRAINT PK_SUPPLIER PRIMARY KEY (SUPPLIERID);

Locating source code

Locate the source code in the
profile_root/samples/src/PlantsByWebSphere directory.

z/OS customers: The source code tree for Samples is not provided on the z/OS platform because Sample applications are not built on the z/OS platform.

Reviewing coding notes

Overview
Servlets
Enterprise beans

Overview

The Plants by WebSphere Sample incorporates the following technologies:

The Plants by WebSphere application is supported through a series of JSP pages and HTML pages. These pages communicate with the following servlets: AccountServlet, ShoppingServlet, ImageServlet, and AdminServlet. The servlets use the various enterprise bean business methods, which in turn, access data from the database as needed. In general, stateless session beans are used to interface with the entity beans, in order to reduce the number of transactions.

Servlets

The following section provides information on the servlets used in this application.

ShoppingServlet

The ShoppingServlet servlet processes the majority of interactions between the browser and the enterprise beans. This interaction includes inventory, shopping cart, and order functions. Selecting a shopping category to browse uses a Catalog session bean, to find and display all of the relevant Inventory objects. Displaying the details of an item is also performed using a Catalog session bean to obtain information from an Inventory CMP entity bean.

Adding an item to the shopping cart creates a ShoppingCart stateful session bean. A Catalog session bean obtains the Inventory data, and places the item in the ShoppingCart bean. Viewing and updating the shopping cart is done using the ShoppingCart stateful session bean.

After entering billing and shipping information, the ShoppingCart bean creates a new Order CMP entity bean. Upon completing the checkout procedure, a Mailer stateless session bean is created to send a confirmation e-mail, using the JavaMail API.

ImageServlet

The ImageServlet servlet obtains and places product images into the database. The servlet obtains images from the JSP pages and the HTML pages from the database and serves back to the browser through the HTTP response.

AdminServlet

The AdminServlet servlet processes the requests from a user (browser) for database re-population.

When processing re-populate requests from the help.jsp page, the AdminServlet servlet creates a bean-managed persistence (BMP) bean called ResetDB. This bean deletes all database tables and re-populates the tables with initial data values from the pbw.properties properties file.

Enterprise beans

The following section provides information on the enterprise beans used in this application.

Catalog

Catalog is a stateless session bean. It is the primary access to the Inventory container-managed persistance entity bean (CMP). Stateless session beans generally access entity bean data, while limiting the number of transactions used. The Catalog session bean has business methods to obtain information from one or more Inventory beans. Methods exist to add and remove an Inventory item. The Catalog session bean also has methods to modify existing Inventory beans.

Customer

Customer is a CMP entity bean. It contains and manages the account data needed for a customer. The Customer entity bean has methods for creating, finding, and updating customer information, as well as verifying a password and getting fields in the Customer entity bean.

Inventory

Inventory is a CMP entity bean. This entity bean contains and manages inventory item data. Methods are available for finding, creating, getting, and setting data fields.

Login

Login is a stateless session bean. This session bean interfaces with the Customer CMP entity bean to create and update customer accounts.

Mailer

Mailer is a stateless session bean. This session bean creates and sends an order confirmation e-mail using the JavaMail API.

Order

Order is a CMP entity bean. This session bean contains and manages order data. Methods are available for finding, creating, and getting data fields.

OrderItem is a CMP entity bean. This entity bean contains and manages a single order item. Methods are available for finding, creating, and getting data fields.

ReportGenerator

ReportGenerator is a stateless session bean. This session bean generates reports based on information found in orders. The ReportGenerator session bean interfaces with the Order CMP entity bean. The reports consist of top-selling items for a set date range, and top-selling zip codes for a set date range.

ShoppingCart

ShoppingCart is a stateful session bean. This session bean maintains a list of inventory items to purchase throughout the HTTP session. The ShoppingCart session bean has business methods to add, remove, and update inventory items. The ShoppingCart session bean also has a method to create a new Order CMP entity bean when the customer is ready to complete a purchase.

ResetDB

ResetDB is a BMP entity bean. This entity bean deletes all rows in the database tables.