Professional Documents
Culture Documents
Software Engineering 2
a.a. 2001/2002
11/6/2019 1
Enterprise Java Beans
Introduction
Application Server
Java 2 Enterprise Edition
What is an Enterprise Bean ?
EJB Properties
EJB Overview
Deployment Phase
Type of beans
Client access with interfaces
Remote access
Local Access
11/6/2019 2
Enterprise Java Beans
Contents of an Enterprise Bean
EJB Example
EJB vs MTS
A few EJB implementations
What’s new in EJB 2.0
Bibliography
11/6/2019 3
Introduction
11/6/2019 4
Introduction
11/6/2019 5
Applicaton Server
Presentation
HTML Application
Java Application
Business Logic
Data Access
11/6/2019 6
Presentation
HTML Java
Generated server- Required Java virtual
side HTML Machine
Runs on any Web More client side
browser power
Less client-side Runned on a page
power Launched from a
browser or a
standalone
application
11/6/2019 7
Business Logic
11/6/2019 8
Data Access
11/6/2019 9
J2EE Application Server
11/6/2019 10
What is an Enterprise Bean ?
Is a server side component written in Java
Language
Industry standard distribuited component
model
Incorporates the business logic of an
application ( the code that implements the
purpose of the application)
11/6/2019 11
EJB Properties
11/6/2019 12
EJB Overview
11/6/2019 13
Deployment Phase
11/6/2019 14
Deployment Phase
11/6/2019 15
When to use Enterprise bean
The application must be scalable.It will run on
different machine and their location will
remain transparent to the client
Transaction requirement
The application will have lot of different type
of clients
11/6/2019 16
Type of beans
Session Bean
Entity Bean
Message Driven Bean
11/6/2019 17
Session Bean
Represents a single client inside the server
The client calls the session bean to invoke methods
of an application on the server
Perform works for its client, hiding the complexity of
interaction with other objects in the server
Is not shared
Is not persistent
When the client stops the session,the bean can be
assigned to another client from the server
11/6/2019 18
Session Bean
11/6/2019 19
Stateful Session Bean
11/6/2019 20
Stateless Session Bean
11/6/2019 21
Entity Bean
Represents a business object in a persistent
storage mechanism such as a relational database
Usually is a table in the database and each
instance of that entity bean is a row in that table
Properties:
Persistent
Allow shared access
Have primary key
Have relationship with other entity beans.
11/6/2019 22
Entity Bean persistent
11/6/2019 23
Bean managed
persistence
Who write the bean’s code must access the
database and save his own data
11/6/2019 24
Container managed
persistence
The container save the data
There is no code in the bean for access the
database
The container handles all database access
required for the bean
Links between beans are created using a
structure called abstract schema
11/6/2019 25
Entity bean’s shared access
Entity beans can be used by different clients
It’s important that they work whithin transactions
The EJB container provides transaction
management
The transaction’s attribute are specified in the
bean’s deployment description
11/6/2019 26
Entity bean’s primary key
11/6/2019 27
Entity bean’s relationship
11/6/2019 28
Message Driven bean
A Web component
11/6/2019 29
Message Driven bean
11/6/2019 30
Message Driven bean
11/6/2019 31
Client access with interfaces
11/6/2019 32
Remote access
11/6/2019 33
Remote access
11/6/2019 34
Remote access example
11/6/2019 35
Local access
11/6/2019 36
Local access
11/6/2019 37
Local interfaces
11/6/2019 38
Contents of an Enterprise
Bean
Deployment descriptor
Persistence type
Transaction attribute
Enterprise bean class
Interfaces
Helper classes
Exception
Utility classes
11/6/2019 39
EJB Example
11/6/2019 40
EJB Example
Virtual Bank
Security Accounts
Services
Client
11/6/2019 41
EJB Example
11/6/2019 42
EJB Example
11/6/2019 43
EJB vs MTS
11/6/2019 44
EJB vs MTS
Analogies
Implement business logic for Application
Server components
Have a Server and a container ( for MTS
called MTS Executive )
Similar architecture in both models
A client invokes wrapped method
11/6/2019 45
EJB vs MTS
Difference
EJB MTS
Component instance Component is not
are pooled created until the call
Don’t support from a client reaches
heterogeneous the container
transactions Support
Portability accross heterogeneous
multiple platforms transactions
using Java platform Portability only on
Windows NT
11/6/2019 46
EJB vs MTS
Difference
EJB MTS
Invoked by clients Invoked by clients
using RMI using DCOM or
Has both through local COM
persistent and calls
non-persistent Components are
components not persistent,
even though they
may contain
information
11/6/2019 47
A few EJB implementations
WebLogic
Bluestone
Novera
Persistence
Oracle AS
Oracle8i
11/6/2019 48
What’s new in EJB 2.0
11/6/2019 49
What’s new in EJB 2.0
11/6/2019 50
Bibliography
11/6/2019 51
Bibliography
11/6/2019 52
The MTS architecture
Is made up of:
The MTS Executive (mtxex.dll)
The Factory Wrappers and Context Wrappers for
each component
The MTS Server Component
MTS clients
Auxiliary systems like
COM runtime services,
Service Control Manager (SCM)
The Microsoft Distributed Transaction Coordinator (MS-
DTC)
The Microsoft Message Queue (MSMQ)
The COM-Transaction Integrator (COM-TI)
11/6/2019 53
The MTS architecture
11/6/2019 54
The EJB architecture
Consists of:
An EJB server
EJB containers that run within the server
Home objects
Remote EJBObjects
Enterprise Beans
EJB clients
Auxiliary systems like
Java Naming and Directory Interface (JNDI)
Java Transaction Service (JTS)
Security services
11/6/2019 55
The EJB architecture
11/6/2019 56
Stateful session bean’s
life cycle
The client invoke the create method
The EJB container :
Instantiates the bean
Invokes the setSessionContext
Invokes ejbCreate
The bean is ready
11/6/2019 57
Stateful session bean’s
life cycle
While in the ready state
EJB container may passivate the bean moving it
from memory to secondary storage
A client may invoke a business method
EJB container may activate a bean,moving it back
to the ready stage, and then calls the bean's
ejbActivate method
A client may invoke the remove method and the
container calls the bean's ejbRemove method
11/6/2019 58
Stateful session bean’s
life cycle
11/6/2019 59
Stateless session bean’s
life cycle
The client invoke the create method
The EJB container :
Instantiates the bean
Invokes the setSessionContext
Invokes ejbCreate
The bean is ready
11/6/2019 60
Stateless session bean’s
life cycle
While in the ready state
A client may invoke a business method
A client may invoke the remove method and the
container calls the bean's ejbRemove method
It’s never passivate
11/6/2019 61
Stateless session bean’s
life cycle
11/6/2019 62
Entity bean’s life cycle
11/6/2019 63
Entity bean’s life cycle
11/6/2019 64
Entity bean’s life cycle
11/6/2019 65
Entity bean’s life cycle
11/6/2019 66
Message driven bean’s
life cycle
EJB container creates a pool of message-
driven bean instances
For each instance, the EJB container
instantiates the bean :
It calls the setMessageDrivenContext
It calls the instance's ejbCreate
Like a stateless session bean,it’s never
passivated, It has only two states:
Nonexistent
Ready to receive messages.
11/6/2019 67
Message driven bean’s
life cycle
While in the ready state :
EJB container may call onMessage
EJB container may call the ejbRemove
11/6/2019 68
Message driven bean’s
life cycle
11/6/2019 69
Abstract schema
11/6/2019 70
Example of Abstract schema
11/6/2019 71
Abstract schema
Persistent fields
Are stored in the underlying data store
Constitute the state of the bean. At runtime, the
EJB container automatically synchronizes this
state with the database
During deployment, the container
Maps the entity bean to a database table
Maps the persistent fields to the table's columns
11/6/2019 72
Abstract schema
Relationship fields
It’s like a foreign key in a database table.It
identifies a related bean
Like a persistent field, a relationship field is virtual
and is defined in the enterprise bean class with
access methods
Unlike a persistent field, a relationship field does
not represent the bean's state
11/6/2019 73
Abstract schema
Multiplicity in Container-Managed
Relationships
One-to-one: Each entity bean instance is related
to a single instance of another entity bean
One-to-many: An entity bean instance may be
related to multiple instances of the other entity
bean
Many-to-one: Multiple instances of an entity bean
may be related to a single instance of the other
entity bean
Many-to-many: The entity bean instances may be
related to multiple instances of each other
11/6/2019 74
Abstract schema
Direction in Container-Managed
Relationships
Bidirectional relationship: each entity bean has a
relationship field that refers to the other bean.
Through the relationship field, an entity bean's
code can access its related object
Unidirectional relationship: only one entity bean
has a relationship field that refers to the other
11/6/2019 75