Session Beans Business Logic CS 486 Sagar Deshpande Requirements 1 2 3 4 5 6 The Engineering Dept needs to be able to define a product as series of steps that manufacturing facility will follow to build it Should be able to accept from web as well as from phone operators who get orders from Sales personnel Notify Manufacturing dept that a particular is placed and must be delivered on a particular due date The identifier to this order is a unique sales division and a number provided by sales division Duplicate order numbers exist between sales division Should be able to cancel orders on which manufacturing has not started and prevent cancellation of order on which work has started Manufacturing dept should be able to select a order based on due date and time it has to be in inventory before delivering Management should be able retrieve a list of overdue orders Manufacturing dept should notify shipping dept if a shipment is read indicate carrier appropriate for the size and weight and loading dock where the product is sent Two session Beans ManageOrders stateless Manufacture stateful Two entity beans Product Order Implementation ManageOrders a stateless session bean used to manage orders which also has a utility function to create sample products Package factory manage orders consisting of ManageOrders remote interface ManageOrdersHome Home interface ManageOrdersEJB DuplicateOrderException NoSuchOrderException NoSuchProductException OpenOrderView OverdueOrderView ProductCreationHelper helper class A stateful session bean Manufacture used to control manufacturing process factory manufacture package consisting of Manufacture remote interface ManufactureHome home interface ManufactureEJB Remote Interface for ManageOrders stateless session bean package factory manage orders import javax ejb import java util Date import java rmi RemoteException import factory order OrderNotCancelableException public interface ManageOrders extends EJBObject void placeOrder int salesDivision int orderNumber String product Date datedue throws RemoteException NoSuchProductException DuplicateOrderException void cancelOrder int salesDivision int orderNumber throws RemoteException orderNotCancelableException NosuchOrderException OverdueOrderView getOverdueOrders throws RemoteException OpenOrderView getSchedulableOrders throws RemoteException void createProduct String id String name throws RemoteException void createSampleProducts throws RemoteException utitlityfunction void addRoutingInstruction String id int sequence String instruction throws RemoteException In the above interface in a few methods salesDivision and ordernumber form a unique combination to identify any order Two methods getOverdueorders and getSchedulabeorders return arrays of objects The other way to implement this to implement java sql Resultset interface or java sql RowSet Interface with info provided in rows and columns Here the assumption is result set is manageable what if not Typical to arbitrary search criteria Depends on specifics of application Send a chunk ask for refinement Get a marker from client send data in chunks this is possible because connections to database are pooled hence no burden of creating connections Another issue to be addressed How to transfer data about a single entity from server to client getEachParameter increases network traffic Use a structure with serializable parameter and pass it Problem with this Specific to particular type of client introducing coupling between client and server Use java sql resultset What if data not tabled Use java util map using a Key value pair Implementing exception classes package factory manage orders Public class DuplicateOrderException extends Exception public DuplicateOrderException package factory manage orders public class NoSuchProductException extends Exception public NoSuchProductException Implementing OpenOrderView class package factory manage orders import java io Serializable import java util Date public class OpenOrderView implements Serializable public final int salesDivision public final int orderNumber public final String product public final Date datedue public OpenOrderView int salesDivision int orderNumber String product Date datedue this salesDivision salesDivision this orderNumber orderNumber this product product this datedue datedue Implementing OverdueOrderView class package factory manage orders import java io Serializable import java util Date public class OverdueOrderView implements Serializable public final int salesDivision public final int orderNumber public final String product public final Date datedue public OverdueOrderView int salesDivision int orderNumber String product String status Date datedue this salesDivision salesDivision this orderNumber orderNumber this product product this status status this datedue datedue Home interface for manage orders typical to any stateless bean package factory manage orders import javax ejb public interface ManageOrders extends EJBHome ManageOrders create throws java rmi RemoteException java ejb CreateException Implementation of ManageOrdersEJB package factory manage orders public class ManageOrdersEJB implements SessionBean void placeOrder int salesDivision int orderNumber String productName Date datedue try find product ProductHome phome get ProductHome Product p phome findByPrimaryKey productName create order OrderHome ohome getOrderHome Ohome create int salesDivision int orderNumber String productName Date datedue catch NamingException ne throw new EJBException ne catchFinderException fe If fe instanceOf objectNotFoundException throw NoSuchProductException fe catch CreateException ce if OrderExists int salesDivision int orderNumber throw new DuplicateOrderException ce else throw new EJBException ce placeOrder method makes use of both entity beans It uses getProductHome helper method to get a reference to ProductHome uses it to call getByPrimaryKey and getOrderHome to get reference to OrderHome and Use the reference to call create method of entitybean Order Exceptions If finder exception is result of product not being found in database NosuchProduct exception is thown if it due to indeterminate cause a general EJBException is thrown similary with createException here it uses helper function orderExists void cancelOrder int salesDivision int orderNumber throws RemoteException orderNotCancelableException NosuchOrderException try OrderHome oh getOrderHome OrderPk pk new OrderPk int salesDivision int
View Full Document
Unlocking...