Plants By WebSphere Technotes

Overview

Getting Started

Development and Build

Application Install and Management

Run the Application

Technotes

Javadoc

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 located in the install_root/Derby/ databases /PLANTSDB directory.

    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);

    Reviewing coding notes

    Overview
    Servlets
    Enterprise beans

    Overview

    The Plants by WebSphere Sample incorporates the following technologies:

    • Java Persistence API (JPA) entity beans
    • Stateless session beans
    • Stateful session beans
    • Servlets
    • JavaServer Faces (JSF) files and Facelets
    • Java 2 platform, enterprise edition (J2EE) security

    The Plants by WebSphere application is supported through a series of JSF 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.

    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 JPA 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 JPA entity bean. Upon completing the checkout procedure, a MailerBean 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 uses a session bean called ResetDBBean. This bean deletes all database tables and re-populates the tables with initial data values from the pbw.properties properties file.

    JPA Entity beans

    The following JPA entity beans are used to represent the table information listed above:

    Customer

    Customer is a JPA entity bean that contains the account data needed for a customer. It is managed by a CustomerMgr session facade.

    Inventory

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

    Order

    Order is a JPA entity bean. This bean contains and manages order data.

    OrderItem is a JPA entity bean that contains and manages a single order item.

    BackOrder

    The BackOrder JPA entity bean handles restocking requirements as inventory dwindles.

    Supplier

    The Supplier bean manages a list of suppliers which satisfy BackOrder requests.

    Enterprise beans

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

    CatalogMgr

    Catalog is a stateless session bean. It is the primary access to the Inventory JPA entity beans. 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.

    CustomerMgr

    The CustomerMgr has methods for creating, finding, and updating customer information, as well as verifying a password and getting fields in the Customer entity bean.

    MailerBean

    MailerBean is a stateless session bean used to create and send an order confirmation e-mail using the JavaMail API.

    ShoppingCartBean

    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 JPA entity bean when the customer is ready to complete a purchase.

    ResetDBBean

    ResetDBBean is a stateless session bean. This entity bean deletes all rows in the database tables and repopulates the database using a property file.