Understanding the Design


The Plants-By-WebSphere application follows the Model-View-Controller pattern. In the previous chapter we built the view and controller portions of the application using JSP pages and servlets. There, we created a model fa ade using simple Java objects in order to create a layer of insulation between the presentation and business logic components. The EJBs we are about to build will "snap-in" to the model objects. The following diagram illustrates the relationship between these components:

click to expand

We will therefore create an EJB corresponding to each of the model objects. The model objects implement the following interfaces:

 /**  * CartModel represents a simple shopping cart.  **/ public interface CartModel {   /**    * add a StoreItem to the Shopping Cart    */   public void addItem(StoreItem si);   /**    * get the list of StoreItem in the Shopping Cart    */   public Vector getItems(); } 

   /**    * OrderModel represents an order placed by a customer.    **/ public interface OrderModel {    /**    * Create an order for the list of StoreItems requested    * by the specified customer. Return the order ID.    */   public String addOrder(CustomerInfo c, Vector orderItems); } /**  * InventoryModel represents an item in the store's inventory.  **/ public interface InventoryModel {    /**    * find all Inventory items in the specified category    */   public Collection findByCategory(String category);   /**    * find the Inventory item with the specified ID    */   public StoreItem findById(String id); } 

 /**  * CustomerModel represents a customer making an order through our system.  **/ public interface CustomerModel {   /**    * Add a new customer    */   public void addCustomer(CustomerInfo i);   /**    * Retrieve an existing customer     */   public CustomerInfo getCustomer(String key); } 

We will build four primary EJBs:

  • ShoppingCart

  • Order

  • Inventory

  • Customer

ShoppingCart will contain temporary state while the customer shops, so we will implement that using a stateful session bean. Order, Inventory, and Customer have long-lived state that we will keep in a database, so we'll use entity beans for those. With entity beans we can either choose to let the EJB container manage our persistent state or we can implement it ourselves. These two persistence models are referred to as container-managed persistence and bean-managed persistence, or CMP and BMP, respectively. We will use CMP because the WebSphere tools and runtime will take care of most of the data logic for us. This built-in persistence support is powerful, but does have its limitations. Highly complex data mappings or certain EIS integration scenarios could force us to implement the data logic ourselves using the BMP persistence model, but that won't be necessary for this application.




Professional IBM WebSphere 5. 0 Applicationa Server
Professional IBM WebSphere 5. 0 Applicationa Server
ISBN: N/A
EAN: N/A
Year: 2001
Pages: 135

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net