Java Ejb Presentation
Java Ejb Presentation
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
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
3
Introduction
4
Introduction
5
Applicaton Server
• Presentation
– HTML Application
– Java Application
• Business Logic
• Data Access
6
Presentation
• HTML • Java
– Generated server-side – Required Java virtual
HTML Machine
– Runs on any Web – More client side power
browser – Runned on a page
– Less client-side power – Security (Applet)
– Launched from a
browser or a
standalone application
7
Business Logic
8
Data Access
9
J2EE Application Server
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)
• Replicates the table model as objects
11
EJB Properties
• Bean writers need not write
– Remote access Protocols
– Transactional Behaviour
– Threads
– Security
– State Management
– Object life cycle
– Resource pooling
– Persistence
– Native queries execution
12
EJB Overview
13
Deployment Phase
14
Deployment Phase
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
• Multilevel security layer
16
Type of beans
• Session Bean
• Entity Bean
• Message Driven Bean
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
• Unique to each client
18
Session Bean
19
Stateful Session Bean
20
Stateless Session Bean
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.
• Auto commit.
22
Entity Bean persistent
23
Bean managed
persistence
• Who write the bean’s code must access the
database and save his own data
• you will have more control over how the entity
bean accesses a database
24
Container managed persistence
26
Entity bean’s primary key
27
Entity bean’s relationship
28
Message Driven bean
29
Message Driven bean
• Retain no data or conversational state for a specific
client
• All instances are equivalent, allowing the EJB
container to assign a message to any message-
driven bean instance. The container can pool these
instances.
• The instance variables of the message-driven
bean e can contain some state across the
handling of client messages--for example, a
JMS API connection, an open database
connection, or an object reference to an ejb.
30
Message Driven bean
31
Client access with interfaces
32
Remote access
33
Remote access
34
Remote access example
35
Local access
36
Local access
37
Local interfaces
38
Contents of an Enterprise Bean
• Deployment descriptor
– Persistence type
– Transaction attribute
• Enterprise bean class
• Interfaces
• Helper classes
– Exception
– Utility classes
39
EJB Example
40
EJB Example
Virtual Bank
Security Accounts
Services
Client
41
EJB Example
43
A few EJB implementations
• WebLogic
• Bluestone
• Novera
• Persistence
• Oracle AS
• Oracle8i
44
What’s new in EJB 2.0
• Released On April 26, 2001
• Integration with JavaTM Message Service (JMS) --
Asynchronous Capabilities Streamline Systems
– Send asynchronous messages via the JMS API
• Container-Managed Persistence (CMP) -- Simplifying
and Expediting Application Development
– Used to isolate the application developer from the physical
database schema
– Introduces for the first time a portable query language, based on
the abstract schema
– No need to worry about data access code
45
What’s new in EJB 2.0
• Local Interfaces -- Streamlining Calls Between Local
Beans
– The local interface may be defined for a bean during
development, to allow streamlined calls to the bean if a caller is
in the same container
– Uses when Client and bean reside in same JVM
• Inter-Server Interoperability -- Enabling Heterogeneous
Environments
– Takes the benefit of cross-server application portability
– Able to deploy the EJB technology-based application across a
heterogeneous environment mixing application servers from
different vendors
46
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
• Threading
• Pooling
47
The EJB architecture
48
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
• Business methods ready to be called
49
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
– Client cannot invoke passivate
50
Stateful session bean’s
life cycle
51
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
52
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
– It’s can be pooled
53
Stateless session bean’s
life cycle
54
Entity bean’s life cycle
55
Entity bean’s life cycle
• While in the pool :
– Instance is not associated with any particular object
identity
– All instances in the pool are identical
– EJB container may assign an identity to an instance
when moving it to the ready stage invoking the
ejbActivate method
– A client may invoke the create method
• EJB container calls ejbCreate and ejbPostCreate
– EJB container may remove the instance invoking
unsetEntityContext
– Same bean instance (row) shared by all client
56
Entity bean’s life cycle
57
Entity bean’s life cycle
58
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.
– is only a bean class – no interfaces
59
Message driven bean’s
life cycle
• While in the ready state :
– EJB container may call onMessage
– EJB container may call the ejbRemove
60
Message driven bean’s
life cycle
61