Professional Documents
Culture Documents
Enterprise Java Beans
Enterprise Java Beans
Objectives
Middle
Tier Other Legacy
GUI Client Storage
Server
• Business Logic/Rules
• Resource access management (database
connection pooling)
• Remote access between clients and data
sources
• Session and transaction management
• Security management
J2EE Three Tiered
Servlet
Other Client Database
JSP Storage
J2EE Middle-Tier
Web Container
• For deploying WEB components
Why EJB?
• Business-Logic
• Extensibility
• Scalability
Business-Logic
Java Beans,
Session DAO,
Client HTML, Beans, Entity
JSP, Message Beans,
Servlet Driven Hibernate
External
Beans
Resources
Business Integration
Presentation
Logic
J2EE Scenario
Extensibility
Web-Client
Swing-Client
Application Server
xml-Client
J2ME-Client
What All We Should
Know?
What all we should know?
• Application server
• Containers
• Implicit Services
• Other auxiliary systems
• EJB clients
Application Server
The Basics
EJB Fundamentals
• What is an EJB?
• Types of EJB
• Session Bean
• Entity Bean
• Message Driver Bean
• Passivation / Activation
• Deployment Descriptor
What is EJB?
• void ejbActivate()
• void ejbPassivate()
• void ejbRemove()
• void setSessionContext(SessionContext)
CurrencyConverterBean-Code
Interface that
extends Remote; is
package com.converter; extended by the
import javax.ejb.*; component interface
import java.rmi.*;
public interface CurrencyConverter extends EJBObject {
public double convert (double dollars) throws
RemoteException;
} The business-
Every BL method logic method
must throw this
exception
Questions?
Interface that is
extended by the
package com.converter; home interface
import javax.ejb.*;
import java.rmi.*;
public interface CurrencyConverterHome extends EJBHome {
public CurrencyConverter create () throws
CreateException, RemoteException;
} The create
method
Every create
method must throw
this exception
Questions?
Zubair-o-Scope
Client lookup for Home
JNDI
Client
Home
Object
JNDI
Client
Home Home
stub Object
Client
Home Home
stub Object
EJB
Object
Client
Home Home
stub Object
EJB EJB
Object
Object
Client stub
Home Home
Object
stub
Object
Zubair-o-Scope
Container…
Bean Pool
Session
Context
EJB Container
Gives SessionContext to bean
Bean Pool
Session
Context
EJB Container
Taking bean from pool
EJB
Object Bean Pool
Session
Context
EJB Container
Serving to the client
Session
Client Context
create()
new
new
setSessionContext()
ejbCreate()
Stateful Session Bean
The Stateful Transitions
Bean does
not exist
constructor
setSessionContext()
ejbCreate()
ejbRemove()
or timeout
timeout
ejbActivate()
method ready passivated
Entity Beans
What Entity Bean represents?
empid: 243
ename: Zubair
sal: 5500
Employee Table
empid ename salary
234 Zubair 5500
435 Nilesh 8750
empid: 653
ename: Advait
sal: 7500
Getting Entity Bean
Find a Bean
• Using finder methods
Creating bean
Zubair-o-Scope
create() way
Bean Pool
Client
Home
Object
Home
Object
stub
EJB Container
Bean Pool
Client
Home
Object
Home
Object
stub
EJB Container
Bean Pool
Context
Client
Home
Object
Home
Object
stub
EJB Container
Bean Pool
Context
Client
Home
Object
Home
Object
stub
EJB Container
Bean Pool
Context
Home
Object
Client
EJB Container
Home
Object
Client
EJB Container
EJB
Object
stub
Home
Object
Client
EJB Container
Zubair-o-Scope
findByMethod() way
Bean Pool
Context
Client Context
Home
Object
Home
Object
stub
EJB Container
Bean Pool
Context
Client Context
Home
Object
Home
Object
stub
EJB Container
Bean Pool
Context
Context
Home
Object
Client
EJB Container
Bean Pool
Context
Context
Home
Object
Client
EJB Container
Bean Pool
EJB
Object Context
Context
Home
Object
Client
EJB Container
Bean Pool
EJB
Object Context
Context
EJB
Object
stub
Home
Object
Client
EJB Container
• “Leave it on container”
Zubair Shaikh
imzubair@gmail.com
Presentation Version 2.0