53
Seminar: Enterprise JavaBe ans

Seminar: Enterprise JavaBeans. Agenda Agenda Java™ 2 Platform Java™ 2 Platform Java™ 2 Platform,Enterprise Edition(J2EE) Java™ 2 Platform,Enterprise Edition(J2EE)

Embed Size (px)

Citation preview

Page 1: Seminar: Enterprise JavaBeans. Agenda Agenda Java™ 2 Platform Java™ 2 Platform Java™ 2 Platform,Enterprise Edition(J2EE) Java™ 2 Platform,Enterprise Edition(J2EE)

Seminar: Enterprise JavaBeans

Page 2: Seminar: Enterprise JavaBeans. Agenda Agenda Java™ 2 Platform Java™ 2 Platform Java™ 2 Platform,Enterprise Edition(J2EE) Java™ 2 Platform,Enterprise Edition(J2EE)

AgendaAgenda

• Java™ 2 PlatformJava™ 2 Platform

• Java™ 2 Platform,Enterprise Edition(J2EE)Java™ 2 Platform,Enterprise Edition(J2EE)

• Enterprise JavaBeans ™ Enterprise JavaBeans ™

• Enterprise JavaBeans ™ ArchitectureEnterprise JavaBeans ™ Architecture

Page 3: Seminar: Enterprise JavaBeans. Agenda Agenda Java™ 2 Platform Java™ 2 Platform Java™ 2 Platform,Enterprise Edition(J2EE) Java™ 2 Platform,Enterprise Edition(J2EE)

Java™ 2 Platform

Page 4: Seminar: Enterprise JavaBeans. Agenda Agenda Java™ 2 Platform Java™ 2 Platform Java™ 2 Platform,Enterprise Edition(J2EE) Java™ 2 Platform,Enterprise Edition(J2EE)

Java HistoryJava History

1995 Sun World951995 Sun World95

1996 JDK1.0 Final Release1996 JDK1.0 Final Release

1997 JDK1.1 Final Release1997 JDK1.1 Final Release

1999 JDK1.2 Final Release1999 JDK1.2 Final Release

2000 JDK1.3 Final Release2000 JDK1.3 Final Release

Page 5: Seminar: Enterprise JavaBeans. Agenda Agenda Java™ 2 Platform Java™ 2 Platform Java™ 2 Platform,Enterprise Edition(J2EE) Java™ 2 Platform,Enterprise Edition(J2EE)

Today/TomorrowWeb ContentWeb Content

E-mailE-mail

EntertainmentEntertainment

TravelTravel

Personal Personal Finance Finance

E-commerceE-commerce

Voice Over IPVoice Over IP

Long Distance Long Distance PhonePhone

Page 6: Seminar: Enterprise JavaBeans. Agenda Agenda Java™ 2 Platform Java™ 2 Platform Java™ 2 Platform,Enterprise Edition(J2EE) Java™ 2 Platform,Enterprise Edition(J2EE)

Today’s Enterprise

Page 7: Seminar: Enterprise JavaBeans. Agenda Agenda Java™ 2 Platform Java™ 2 Platform Java™ 2 Platform,Enterprise Edition(J2EE) Java™ 2 Platform,Enterprise Edition(J2EE)

Short History of Java Enterprise Technology

Page 8: Seminar: Enterprise JavaBeans. Agenda Agenda Java™ 2 Platform Java™ 2 Platform Java™ 2 Platform,Enterprise Edition(J2EE) Java™ 2 Platform,Enterprise Edition(J2EE)

Java™ 2 Platform

Java™ 2 Platform,Standard Edition(J2SE) Java™ 2 Platform,Standard Edition(J2SE)

Java™ 2 Platform,Enterprise Edition(J2EE)Java™ 2 Platform,Enterprise Edition(J2EE)

Java™ 2 Platform,Micro Edition(J2ME)Java™ 2 Platform,Micro Edition(J2ME)

Page 9: Seminar: Enterprise JavaBeans. Agenda Agenda Java™ 2 Platform Java™ 2 Platform Java™ 2 Platform,Enterprise Edition(J2EE) Java™ 2 Platform,Enterprise Edition(J2EE)

Java™ 2 Platform

Page 10: Seminar: Enterprise JavaBeans. Agenda Agenda Java™ 2 Platform Java™ 2 Platform Java™ 2 Platform,Enterprise Edition(J2EE) Java™ 2 Platform,Enterprise Edition(J2EE)

Java HistoryJava History

Page 11: Seminar: Enterprise JavaBeans. Agenda Agenda Java™ 2 Platform Java™ 2 Platform Java™ 2 Platform,Enterprise Edition(J2EE) Java™ 2 Platform,Enterprise Edition(J2EE)

Java Enterprise ArchitectureJava Enterprise Architecture

PDAPDA

KioskKiosk

Java DeviceJava Device

VideoVideoServerServer

SolsticeSolsticeFirewallFirewall

WebWebServerServer

WorkstationWorkstation

ServerServer Java DesktopJava Desktop

Corporate Corporate LANLAN

PCPC

WorkgroupWorkgroupServerServer

MainframeMainframe

Public InternetPublic

InternetCorporateCorporateIntranetIntranet

CorporateCorporateIntranetIntranet

FirewallFirewall

BeeperCell PhoneATMGame

Page 12: Seminar: Enterprise JavaBeans. Agenda Agenda Java™ 2 Platform Java™ 2 Platform Java™ 2 Platform,Enterprise Edition(J2EE) Java™ 2 Platform,Enterprise Edition(J2EE)

AgendaAgenda

• Java™ 2 PlatformJava™ 2 Platform

• Java™ 2 Platform,Enterprise Edition(J2EE)Java™ 2 Platform,Enterprise Edition(J2EE)

• Enterprise JavaBeans ™ Enterprise JavaBeans ™

• Enterprise JavaBeans ™ ArchitectureEnterprise JavaBeans ™ Architecture

Page 13: Seminar: Enterprise JavaBeans. Agenda Agenda Java™ 2 Platform Java™ 2 Platform Java™ 2 Platform,Enterprise Edition(J2EE) Java™ 2 Platform,Enterprise Edition(J2EE)

Java™ 2 PlatformEnterprise Edition(J2EE)

Page 14: Seminar: Enterprise JavaBeans. Agenda Agenda Java™ 2 Platform Java™ 2 Platform Java™ 2 Platform,Enterprise Edition(J2EE) Java™ 2 Platform,Enterprise Edition(J2EE)

Application Servers

Provides infrastructure to support Provides infrastructure to support management of business logic and access to management of business logic and access to servicesservices

Provide proprietary APIs,which leads to Provide proprietary APIs,which leads to vendor lockvendor lock

Diminishes ability to reuse business logic on Diminishes ability to reuse business logic on another vendor’s application serversanother vendor’s application servers

Page 15: Seminar: Enterprise JavaBeans. Agenda Agenda Java™ 2 Platform Java™ 2 Platform Java™ 2 Platform,Enterprise Edition(J2EE) Java™ 2 Platform,Enterprise Edition(J2EE)

Enterprise Goals

ReuseReuse

InteroperabilityInteroperability

PortabilityPortability

Time-to-MarketTime-to-Market

Page 16: Seminar: Enterprise JavaBeans. Agenda Agenda Java™ 2 Platform Java™ 2 Platform Java™ 2 Platform,Enterprise Edition(J2EE) Java™ 2 Platform,Enterprise Edition(J2EE)

Why another Java 2 Platform?Enterprise Services Require

AvailabilityAvailability

DistributionDistribution

ConcurrencyConcurrency

SecuritySecurity

ConsistencyConsistency

ScalabilityScalability

EIS IntegrationEIS Integration

AdministrationAdministration

Page 17: Seminar: Enterprise JavaBeans. Agenda Agenda Java™ 2 Platform Java™ 2 Platform Java™ 2 Platform,Enterprise Edition(J2EE) Java™ 2 Platform,Enterprise Edition(J2EE)

What is J2EE ?

J2EEJ2EE is An Integrated Application is An Integrated Application Environment ( consist of below )Environment ( consist of below )– API specifications (EJB,JSP,JDBC etc)

Defines J2EE requirements

– Reference implementation of APIsOperational J2EE platform

– Compatibility tests with brandingValidates J2EE platform compatibility

– Application Programming ModelDescribes how to build J2EE application

Page 18: Seminar: Enterprise JavaBeans. Agenda Agenda Java™ 2 Platform Java™ 2 Platform Java™ 2 Platform,Enterprise Edition(J2EE) Java™ 2 Platform,Enterprise Edition(J2EE)

What is J2EE ? The enterprise developer can concentrate on The enterprise developer can concentrate on

application components,not the underlying application components,not the underlying services services

Separation of business logic and services Separation of business logic and services provide for better reuse of business logic provide for better reuse of business logic

BusinessBusiness

logiclogicBusinessBusiness

logiclogic

ServicesServices ServicesServices

Page 19: Seminar: Enterprise JavaBeans. Agenda Agenda Java™ 2 Platform Java™ 2 Platform Java™ 2 Platform,Enterprise Edition(J2EE) Java™ 2 Platform,Enterprise Edition(J2EE)

J2EE Architecture

Page 20: Seminar: Enterprise JavaBeans. Agenda Agenda Java™ 2 Platform Java™ 2 Platform Java™ 2 Platform,Enterprise Edition(J2EE) Java™ 2 Platform,Enterprise Edition(J2EE)

J2EE API Summary

• J2SE 1.3

• JDBC 2.0

• RMI/IIOP 1.0

• EJB 1.1.x

• Servlet 2.2

• JSP 1.1

• J2SE 1.3

• JDBC 2.0

• RMI/IIOP 1.0

• EJB 1.1.x

• Servlet 2.2

• JSP 1.1

• JNDI 1.2

• JTA 1.0

• JMS 1.0

• JavaMail 1.1

• JAF 1.0

• JNDI 1.2

• JTA 1.0

• JMS 1.0

• JavaMail 1.1

• JAF 1.0

Page 21: Seminar: Enterprise JavaBeans. Agenda Agenda Java™ 2 Platform Java™ 2 Platform Java™ 2 Platform,Enterprise Edition(J2EE) Java™ 2 Platform,Enterprise Edition(J2EE)

J2EE Standard Services

• Web• Database• Naming and

Directory• Management• Email • Protocol• Transaction

• Web• Database• Naming and

Directory• Management• Email • Protocol• Transaction

Servlet/JSP(HTML/XML)

JDBCTM

JNDI

JMX

JavaMail TM

JavaIDL/RMI

OTS/JTS/JTA

Servlet/JSP(HTML/XML)

JDBCTM

JNDI

JMX

JavaMail TM

JavaIDL/RMI

OTS/JTS/JTA

Services Java Technology

Page 22: Seminar: Enterprise JavaBeans. Agenda Agenda Java™ 2 Platform Java™ 2 Platform Java™ 2 Platform,Enterprise Edition(J2EE) Java™ 2 Platform,Enterprise Edition(J2EE)

J2EE Platform

Page 23: Seminar: Enterprise JavaBeans. Agenda Agenda Java™ 2 Platform Java™ 2 Platform Java™ 2 Platform,Enterprise Edition(J2EE) Java™ 2 Platform,Enterprise Edition(J2EE)

J2EE is important

Integrated Application EnvironmentIntegrated Application Environment

Open platformOpen platform

Integrates with existing environmentsIntegrates with existing environments

Provides foundation for future developmentProvides foundation for future development

Page 24: Seminar: Enterprise JavaBeans. Agenda Agenda Java™ 2 Platform Java™ 2 Platform Java™ 2 Platform,Enterprise Edition(J2EE) Java™ 2 Platform,Enterprise Edition(J2EE)

AgendaAgenda

• Java™ 2 PlatformJava™ 2 Platform

• Java™ 2 Platform,Enterprise Edition(J2EE)Java™ 2 Platform,Enterprise Edition(J2EE)

• Enterprise JavaBeans ™ Enterprise JavaBeans ™

• Enterprise JavaBeans ™ ArchitectureEnterprise JavaBeans ™ Architecture

Page 25: Seminar: Enterprise JavaBeans. Agenda Agenda Java™ 2 Platform Java™ 2 Platform Java™ 2 Platform,Enterprise Edition(J2EE) Java™ 2 Platform,Enterprise Edition(J2EE)

Enterprise JavaBeans ™

Page 26: Seminar: Enterprise JavaBeans. Agenda Agenda Java™ 2 Platform Java™ 2 Platform Java™ 2 Platform,Enterprise Edition(J2EE) Java™ 2 Platform,Enterprise Edition(J2EE)

EJB Architecture

Page 27: Seminar: Enterprise JavaBeans. Agenda Agenda Java™ 2 Platform Java™ 2 Platform Java™ 2 Platform,Enterprise Edition(J2EE) Java™ 2 Platform,Enterprise Edition(J2EE)

EJB Design Goals Simplify development/deployment of Simplify development/deployment of

distributed applicationsdistributed applications Achieve broad industry acceptanceAchieve broad industry acceptance The right expert focuses on the right jobThe right expert focuses on the right job Platform independent and protocol Platform independent and protocol

neutralneutral Enable development of portable Enable development of portable

components - Truly enable reusecomponents - Truly enable reuse

Page 28: Seminar: Enterprise JavaBeans. Agenda Agenda Java™ 2 Platform Java™ 2 Platform Java™ 2 Platform,Enterprise Edition(J2EE) Java™ 2 Platform,Enterprise Edition(J2EE)

A server-side component architecture Model to enable efficient development

and deployment of Java applications :

– Transactional,Portable

– Distributed,Multi-tier

– Scalable

– Secure

Defining Enterprise JavaBeans

Page 29: Seminar: Enterprise JavaBeans. Agenda Agenda Java™ 2 Platform Java™ 2 Platform Java™ 2 Platform,Enterprise Edition(J2EE) Java™ 2 Platform,Enterprise Edition(J2EE)

Defining Enterprise JavaBeans EJB is not JavaBeansEJB is not JavaBeans

a Server Component specification for Javaa Server Component specification for Java

Separates business and system programminSeparates business and system programmin

gg

Portability of business objectsPortability of business objects

Extensibility through vendor featuresExtensibility through vendor features

Page 30: Seminar: Enterprise JavaBeans. Agenda Agenda Java™ 2 Platform Java™ 2 Platform Java™ 2 Platform,Enterprise Edition(J2EE) Java™ 2 Platform,Enterprise Edition(J2EE)

JavaBeans Versus Enterprise JavaBeans

Java Beans• Can be either visible or no

n-visible• Intended to be local to a si

ngle process on the client side

• Uses the BeanInfo classes, Property Editors & Customizers to describe itself

• Can also be deployed as an ActiveX control

Java Beans• Can be either visible or no

n-visible• Intended to be local to a si

ngle process on the client side

• Uses the BeanInfo classes, Property Editors & Customizers to describe itself

• Can also be deployed as an ActiveX control

Enterprise JavaBeans• Are decidedly Non-Visible,

remote objects• Remotely executable comp

onents deployed on the server

• Uses the Deployment Descriptor to describe itself

• Can not deployed as an ActiveX control since OCXs run on the desktop

Enterprise JavaBeans• Are decidedly Non-Visible,

remote objects• Remotely executable comp

onents deployed on the server

• Uses the Deployment Descriptor to describe itself

• Can not deployed as an ActiveX control since OCXs run on the desktop

Page 31: Seminar: Enterprise JavaBeans. Agenda Agenda Java™ 2 Platform Java™ 2 Platform Java™ 2 Platform,Enterprise Edition(J2EE) Java™ 2 Platform,Enterprise Edition(J2EE)

JavaBeans Versus Enterprise JavaBeans

Java Beans

Server

Client

Client Enterprise information Services

Enterprise information Services

Existingapplication

Database

EJB2

EJB3

EJB1Java Beans

Java Beans

Java Beans

Java Beans

Container

Server manages resources suchas threads, connection pooling,caching, and state management

Page 32: Seminar: Enterprise JavaBeans. Agenda Agenda Java™ 2 Platform Java™ 2 Platform Java™ 2 Platform,Enterprise Edition(J2EE) Java™ 2 Platform,Enterprise Edition(J2EE)

What Is Special About EJBs?

Learn onceLearn once Write Once, Run Anywhere Write Once, Run Anywhere TMTM

Portable and interoperablePortable and interoperable Flexible and extensibleFlexible and extensible ScalableScalable Easier to write distributed applicationsEasier to write distributed applications Transaction managementTransaction management CORBA compatibleCORBA compatible

Page 33: Seminar: Enterprise JavaBeans. Agenda Agenda Java™ 2 Platform Java™ 2 Platform Java™ 2 Platform,Enterprise Edition(J2EE) Java™ 2 Platform,Enterprise Edition(J2EE)

AgendaAgenda

• Java™ 2 PlatformJava™ 2 Platform

• Java™ 2 Platform,Enterprise Edition(J2EE)Java™ 2 Platform,Enterprise Edition(J2EE)

• Enterprise JavaBeans ™ Enterprise JavaBeans ™

• Enterprise JavaBeans ™ ArchitectureEnterprise JavaBeans ™ Architecture

Page 34: Seminar: Enterprise JavaBeans. Agenda Agenda Java™ 2 Platform Java™ 2 Platform Java™ 2 Platform,Enterprise Edition(J2EE) Java™ 2 Platform,Enterprise Edition(J2EE)

Enterprise JavaBeans ™Architecture

Page 35: Seminar: Enterprise JavaBeans. Agenda Agenda Java™ 2 Platform Java™ 2 Platform Java™ 2 Platform,Enterprise Edition(J2EE) Java™ 2 Platform,Enterprise Edition(J2EE)

Key Components in EJB

EJB ServerEJB Server

EJB containerEJB container

Home ObjectHome Object

EJBObjectEJBObject

Enterprise BeanEnterprise Bean

Page 36: Seminar: Enterprise JavaBeans. Agenda Agenda Java™ 2 Platform Java™ 2 Platform Java™ 2 Platform,Enterprise Edition(J2EE) Java™ 2 Platform,Enterprise Edition(J2EE)

EJB Architecture Overview

EJB HomeClass

EJB ObjectInterface

EJB HomeInterface

EJB ObjectClass

EJB ClassDeploymentDescriptor Manifest

EJB ServerEJB Server

EJB EJB ContainerContainer

Page 37: Seminar: Enterprise JavaBeans. Agenda Agenda Java™ 2 Platform Java™ 2 Platform Java™ 2 Platform,Enterprise Edition(J2EE) Java™ 2 Platform,Enterprise Edition(J2EE)

EJB Architecture Overview

ClientClientClientClient

Enterprise PropertiesEnterprise Properties

HomeHome

ObjectObjectHomeHome

ObjectObject

EJBEJB

ObjectObjectEJBEJB

ObjectObject

EJBEJBEJBEJB

JNDIJNDINamingNaming TransactionTransaction PersistencePersistence SecuritySecurity

ServicesServices

66

5544

33

22

11 11111010

99

88

77

Page 38: Seminar: Enterprise JavaBeans. Agenda Agenda Java™ 2 Platform Java™ 2 Platform Java™ 2 Platform,Enterprise Edition(J2EE) Java™ 2 Platform,Enterprise Edition(J2EE)

Application Life Cycle

Page 39: Seminar: Enterprise JavaBeans. Agenda Agenda Java™ 2 Platform Java™ 2 Platform Java™ 2 Platform,Enterprise Edition(J2EE) Java™ 2 Platform,Enterprise Edition(J2EE)

EJB Server Provides System ServicesProvides System Services

Transaction supportTransaction support Database accessDatabase access System resourceSystem resource NamespaceNamespace

ImplementationsImplementations Middleware serversMiddleware servers Application serversApplication servers Database serversDatabase servers

Page 40: Seminar: Enterprise JavaBeans. Agenda Agenda Java™ 2 Platform Java™ 2 Platform Java™ 2 Platform,Enterprise Edition(J2EE) Java™ 2 Platform,Enterprise Edition(J2EE)

EJB Server

Supplies containers for EJBsSupplies containers for EJBs

API between server and container is API between server and container is currently vendor specificcurrently vendor specific

Server could provide several container Server could provide several container types to provide various extended types to provide various extended services to different beansservices to different beans

Page 41: Seminar: Enterprise JavaBeans. Agenda Agenda Java™ 2 Platform Java™ 2 Platform Java™ 2 Platform,Enterprise Edition(J2EE) Java™ 2 Platform,Enterprise Edition(J2EE)

EJB Container

Currently provided by EJB ServerCurrently provided by EJB Server

EJB access to server resource through EJB access to server resource through standard API standard API

May Contain one or multiple classesMay Contain one or multiple classes

Tools for EJB creation and deploymentTools for EJB creation and deployment

Page 42: Seminar: Enterprise JavaBeans. Agenda Agenda Java™ 2 Platform Java™ 2 Platform Java™ 2 Platform,Enterprise Edition(J2EE) Java™ 2 Platform,Enterprise Edition(J2EE)

EJB Container Some standard servicesSome standard services

PersistencePersistence EJB instance creation & locationEJB instance creation & location NamespaceNamespace Transaction controlTransaction control SwappingSwapping SecuritySecurity

Custom servicesCustom services Application-specificApplication-specific Bridge to existing systems Bridge to existing systems

Page 43: Seminar: Enterprise JavaBeans. Agenda Agenda Java™ 2 Platform Java™ 2 Platform Java™ 2 Platform,Enterprise Edition(J2EE) Java™ 2 Platform,Enterprise Edition(J2EE)

Home Interface

Factory interface for the bean:Factory interface for the bean: Interface provided by EJB developerInterface provided by EJB developer Class generated by vendor toolClass generated by vendor tool

One factory class per bean class One factory class per bean class

Factory instance is installed into the Factory instance is installed into the server’s naming serviceserver’s naming service

Page 44: Seminar: Enterprise JavaBeans. Agenda Agenda Java™ 2 Platform Java™ 2 Platform Java™ 2 Platform,Enterprise Edition(J2EE) Java™ 2 Platform,Enterprise Edition(J2EE)

Home Interfaceimport java.io.Serializable;

import java.rmi.RemoteException;

import javax.ejb.CreateException;

import javax.ejb.EJBHome;

public interface ConverterHome extends EJBHome {

Converter create() throws RemoteException,

CreateException;

}

Page 45: Seminar: Enterprise JavaBeans. Agenda Agenda Java™ 2 Platform Java™ 2 Platform Java™ 2 Platform,Enterprise Edition(J2EE) Java™ 2 Platform,Enterprise Edition(J2EE)

Remote Interface

Interface is provided by bean developer Interface is provided by bean developer

Implementation is provided byImplementation is provided by container tools, which include container tools, which include

Stubs and SkeletonsStubs and Skeletons The EJB ObjectThe EJB Object

Page 46: Seminar: Enterprise JavaBeans. Agenda Agenda Java™ 2 Platform Java™ 2 Platform Java™ 2 Platform,Enterprise Edition(J2EE) Java™ 2 Platform,Enterprise Edition(J2EE)

Remote Interface

import javax.ejb.EJBObject;

import java.rmi.RemoteException;

public interface Converter extends EJBObject {

public double dollarToYen(double dollars)

throws RemoteException;

public double yenToEuro(double yen)

throws RemoteException;

}

Page 47: Seminar: Enterprise JavaBeans. Agenda Agenda Java™ 2 Platform Java™ 2 Platform Java™ 2 Platform,Enterprise Edition(J2EE) Java™ 2 Platform,Enterprise Edition(J2EE)

EJB Object The EJB Object is a wrapper object thatThe EJB Object is a wrapper object that

Acts as a proxy to the EJB instanceActs as a proxy to the EJB instance

Interface provided by Bean DeveloperInterface provided by Bean Developer Implementation class generated by tool Implementation class generated by tool

Each business method has a correspondingEach business method has a corresponding method in the EJB Object method in the EJB Object Wrapper method implements container-Wrapper method implements container- provided servicesprovided services

Page 48: Seminar: Enterprise JavaBeans. Agenda Agenda Java™ 2 Platform Java™ 2 Platform Java™ 2 Platform,Enterprise Edition(J2EE) Java™ 2 Platform,Enterprise Edition(J2EE)

EJB Architecture Overview

ClientClientClientClient

HomeHome

InterfaceInterfaceHomeHome

InterfaceInterface

RemoteRemote

InterfaceInterfaceRemoteRemote

InterfaceInterfaceEJBEJBEJBEJB

Home ObjectHome Object

EJB ObjectEJB Object BeanBean

RemoteRemote

InterfaceInterfaceRemoteRemote

InterfaceInterfaceEJBEJBEJBEJB

StubStubStubStub SkeletonSkeletonSkeletonSkeleton

Page 49: Seminar: Enterprise JavaBeans. Agenda Agenda Java™ 2 Platform Java™ 2 Platform Java™ 2 Platform,Enterprise Edition(J2EE) Java™ 2 Platform,Enterprise Edition(J2EE)

EJB Sourceimport java.rmi.RemoteException;

import javax.ejb.*;

public class ConverterEJB implements SessionBean {

public double dollarToYen(double dollars) {

return dollars * 121.6000;

}

public double yenToEuro(double yen) {

return yen * 0.0077;

}

public ConverterEJB() {}

public void ejbCreate() {}

public void ejbRemove() {}

public void ejbActivate() {}

public void ejbPassivate() {}

public void setSessionContext(SessionContext sc) {}

}

Page 50: Seminar: Enterprise JavaBeans. Agenda Agenda Java™ 2 Platform Java™ 2 Platform Java™ 2 Platform,Enterprise Edition(J2EE) Java™ 2 Platform,Enterprise Edition(J2EE)

Types of EJBs

Server

Client

ClientEnterprise information

ServicesEnterprise information

Services

Existingapplication

DatabaseEJB2

EJB3

EJB1

Container

Proxy

Proxy

Proxy

Session BeansClient state

Entity BeansState of data

Page 51: Seminar: Enterprise JavaBeans. Agenda Agenda Java™ 2 Platform Java™ 2 Platform Java™ 2 Platform,Enterprise Edition(J2EE) Java™ 2 Platform,Enterprise Edition(J2EE)

Session Beans Versus Entity Beans

Session BeansPrivate client resource

Bean carries client state

Bean is not persistent

Lifetime is controlled

by client

Transactional participant

Single-threaded

Mandatory since 1.0

Session BeansPrivate client resource

Bean carries client state

Bean is not persistent

Lifetime is controlled

by client

Transactional participant

Single-threaded

Mandatory since 1.0

Entity BeansAccess by multiple clients concurrently

Bean represents state of data in data store

Bean is persistent

Lifetime corresponds to its persistent

store

Transactional by nature

Single-threaded

Mandatory since 1.1

Entity BeansAccess by multiple clients concurrently

Bean represents state of data in data store

Bean is persistent

Lifetime corresponds to its persistent

store

Transactional by nature

Single-threaded

Mandatory since 1.1

Page 52: Seminar: Enterprise JavaBeans. Agenda Agenda Java™ 2 Platform Java™ 2 Platform Java™ 2 Platform,Enterprise Edition(J2EE) Java™ 2 Platform,Enterprise Edition(J2EE)

Client Sourceimport javax.naming.*;

import javax.rmi.PortableRemoteObject;

import Converter;

import ConverterHome;

public class ConverterClient {

public static void main(String[] args) {

try { Context initial = new InitialContext();

Object objref = initial.lookup("MyConverter");

ConverterHome home =

(ConverterHome)PortableRemoteObject.narrow(objref,ConverterHome.class);

Converter currencyConverter = home.create();

double amount = currencyConverter.dollarToYen(100.00);

System.out.println(String.valueOf(amount));

amount = currencyConverter.yenToEuro(100.00);

System.out.println(String.valueOf(amount));

} catch (Exception ex) { }

}

}

Page 53: Seminar: Enterprise JavaBeans. Agenda Agenda Java™ 2 Platform Java™ 2 Platform Java™ 2 Platform,Enterprise Edition(J2EE) Java™ 2 Platform,Enterprise Edition(J2EE)

Enterprise EJB Scenario

HTTP response

HTTP request

DB

Enterprise Application ServerEnterprise Application Server

JSPsJSPs BackOffice

JDBC

JDBC

JMS

JMS

EJBsEJBs

JSP/ServletJSP/Servlet Java BeansJava Beans