Académique Documents
Professionnel Documents
Culture Documents
Application
Carol McDonald
1
Sample Application
2
Use Case Scenarios
Browse Catalog
Customer
<<includes>>
<<includes>>
Send Receipt
3
Divide the Application Into
Modules Based on Functionality
Account Catalog Shopping Order Inventory Mailer
Cart
: Customer
login
getProducts
addItem
checkOut createOrder
updateInventory
sendOrderConfirmation
4
Divide the Application Into
Modules Based on Functionality
Cart
Shopping Cart Module: allows user to save
selected items for the session.
Order
Order Processing Module: performs order
Processing when user buys the items in the
cart.
© Copyright 1999 Sun Microsystems, Inc., All rights reserved.
5
Divide the Application Into
Modules Based on Functionality
Inventory
Inventory Module: maintains information
on the number of each type of product in
stock.
Control
Control Module: control interactions
between user (browse, add items,
check out) and business objects.
(Servlets)
6
Interrelationship of the modules
User
interface browse Catalog
Control
new/existing account
add/remove Account
items
Cart
checkout Inventory
Mail Order
7
Divide Application into Objects
8
Model View Controller Design Pattern
Model
State change
State
query
Notify Change
Event
View selection
View Controller
User event
JSP Servlets, or
JavaBeans Controller classes
components Session EJB
© Copyright 1999 Sun Microsystems, Inc., All rights reserved.
The model is the heart of an application. It represents the application data and
the business rules that govern access and modification of this data. The model
serves as a software approximation to a real world process. Thus we can use
simple real world modeling techniques when defining the model.
The model abstraction provides:
• The ability for the view to query the model about its state.
• Notification to the view when the model changes.
• The ability for the controller to access application functionality encapsulated
by the model.
A view renders the contents of a model. It accesses data from the model and
specifies how that data should be presented. When the model changes, it
notifies
the view. It is the view’s responsibility to maintain consistency in its
presentation
after a model change. When the view is rendered in a Web browser, it is
generated
as part of a response to a user request. In this scenario the treatment of model
changes applies to parts of the model that might be cached in the Web server
tier.
9
MVC
data model
Entity Bean
Manages data
control
Process
/service
Servlet
Session Bean
10
Model: Business Objects:
Business Data
There is state associated both with the application user interface and with the
application or business logic. In general, an application must maintain the
follow-ing
state:
• The user identity - Typically, the user account module maintains the user
iden-tify,
which includes the user’s login ID and certain security credentials.
• The search cursor and catalog position - The catalog module maintains the
cur-sor’s
position within the current search and within the catalog hierarchy.
• The items in the shopping cart - The shopping cart module maintains the list
of
items placed in the shopping cart.
• Order information - When the user commits the order, the shopping cart
passes
this information the order information—billing address, shipping address, and
payment method—to the order management module, which eventually stores
it to a database.
11
Online BookStore Database Schema
1 0-n
Orders
Customer
orderid
email
email
password date
name ShipAddress
address Total price
1
0..n
OrderLineItem
Product
orderId
ISBN
linenumber
title ISBN
author quantity
description Unit price
The application maintains accounts and tracks orders for products. Thus, there
are three areas for which data must be maintained: product, account, and order
information. The product, category, and item tables represent the business’s
product catalog. Each item has an associated entry in the inventory table that
represents the inventory for that product. The account table maintains account
information, one record per customer, with information such as customer
name,
password, and customer address. Finally, there is an orders table with one
record
per order, which keeps information about the order, including ship-to address,
bill-to address, total price of the order, and payment (credit card name,
expiration
date, type) information. The orders table is linked to lineitem and orderstatus
tables. Each item in an order is stored in a separate lineitem record, which con-
tains
the quantity ordered and price and a separate orderstatus record, which
contains a reference to the item and the status of the order.
12
UML for Entity Objects
Customer Order
1 0..n
orderId
email email
0..n
13
Customer Entity EJB
C u s t o m e rE J B
e m a il
a d d res s
Customer nam e
p a s s w o rd
email c r e d i t C a rd N u m b e r
password s e t C u s to m e r D e ta i l s ( )
g e t C u s to m e r D e ta i l s ( )
name lo g in ( )
e j b C r e a te ( )
address e j b P o s tC r e a t e ( )
e jb F in d B yN a m e ()
e jb R e m o ve ( )
s e tE n tityC o n te xt()
u n s e tE n tityC o n te x t ( )
e jb A c tiva te ( )
e jb P a s s iva te ( )
e jb L o a d ()
e j b S to r e ( )
14
Order Entity EJB
orders OrderEJB
orderid orde rId
orderLineItem s
emailId
email
date
s ta tu s
1 ShipAddress to talPrice
Total price orde rDate
getOrderDeta i l s ()
ejbCreate()
ejb R e m ove()
lineitem s e tEntityContext()
n orderId ejb L o a d ()
linenumber ejb S tore()
itemId ejbFind ByPrim a ryK e y()
ejb Activate()
quantity
ejb P a s s ivate()
Unit price
© Copyright 1999 Sun Microsystems, Inc., All rights reserved.
15
Value Objects
CustomerEJB
email
address
name CustomerDetails
password email
creditCardNumber address
name
setCustomerDetails() password
getCustomerDetails() cred itCardNum ber
login()
ejbCreate() getEmail()
ejbPostCreate() g e tA d d r e s s ( )
ejbFindByName() getName()
ejbRemove() getPassword()
setEntityContext() g e tC reditCardNumber()
unsetEntityContext()
ejbActivate()
ejbPassivate()
ejbLoad()
ejbStore()
Value objects are used to encapsulate a serializable read only version of an entire
remote object. This allows to retrieve the value of all the details of a remote object
This App has details objects named XXXDetails (where XXX takes the values Book,
Customer, and Order) for each enterprise bean.
© Copyright 1999 Sun Microsystems, Inc., All rights reserved.
Value Objects
A value object is a business object that can be passed by value. The pass-by-
value semantics can be achieved by implementing the object as a serializable
Java object. A business concept should be implemented as a value object when
it is fine-grained, dependent, and immutable. There are two types of value
objects: dependent objects and details objects.
An object is a dependent object of another object if its life cycle is completely
managed by that object and if it can only be accessed indirectly through that
object. Dependent objects have no set methods. Therefore, dependent objects
can only be modified by creating a new containing object. Examples of
dependent objects in the sample application are Address and CreditCard.
A value object can also be used to encapsulate a serializable version of an
entire remote object. Such objects are used to allow a client to retrieve the
value of all the details of a remote object in one call. The sample application
contains a details object named XXXModel (where XXX takes the values
Catalog, Inventory, Account, Cart, and Order) for each enterprise bean.
16
Model: Business Objects:
Business Rules, Process, Workflow
17
Stateless Services:
Catalog Session EJB
CatalogEJB
product
ISBN
getBooks()
title
getBookDetails()
author findBooksBySubject()
description ejbCreate()
s e tSessionContext()
e j b R e m o ve()
ejbActivate()
ejbPassivate()
The sample application uses stateless session beans for objects containing
more than one database row. In particular, because stateless session beans
provide high performance, stateless session beans are a good choice to provide
a high-performance cache of data for operations that access multiple rows. In
the sample application, the Catalog stateless session bean functions as a cache
that is built up over time.
18
Model: Business Objects:
Business Rules, Process, Workflow
19
Stateful Session EJB
ShoppingCartEJB
cart
numberOfItems
addItem ()
deleteItem ()
clear()
getItem s ()
getItem ()
getNumberOfItems()
getTotal()
ejbCreate()
s e tSessionContext()
ejbRemove()
ejbActivate()
ejbPassivate()
20
Controller Objects
Responsible for coordinating the Model
and View.
1. Receives user requests, and translate
them into application business events.
2. Invokes methods on the model to
cause desired state changes.
3. Selects the screen shown in response
to the request.
request event
controller model
Customer
display
view
© Copyright 1999 Sun Microsystems, Inc., All rights reserved.
he Controller
The sample application must reflect the state of a user’s interaction with the
applica-tion
and the current values of persistent data in the user interface. According to the
MVC pattern, this functionality is assumed by the controller. In the sample
applica-tion,
the controller is split between the Web tier and the EJB tier. In this section we
will discuss the implementation of the controller for the shopping interaction
in the
sample application.
The controller is responsible for coordinating the model and view. The view
depends on the controller for view selection. The model depends on the
controller
for making state changes to the model. The controller must accept user
gestures
from the view, translate them into a business events based on the behavior of
the
application, and process these events. The processing of an event involves
invok-ing
methods of the model to cause the desired state changes. Finally, the controller
selects the screen shown in response to the request that was processed.
21
Since the controller must coordinate both the view and the data, it straddles
Example Solution: EJBs
EJB Container
Servlets
Servlets
Order Entry
Shopping
Cart
EJB Server
22
Example Scenario continued
Servlets
add to cart
register show
or login products
Shopping
cart
purchase
catalog
customer Order
23
Example Scenario continued
Server Configuration
JNDI
Directory Server
© Copyright 1999 Sun Microsystems, Inc., All rights reserved.
24