Enterprise JavaBeans™ Trademark of Sun Microsystems, Inc.

Slides:



Advertisements
Similar presentations
12 Copyright © 2005, Oracle. All rights reserved. Implementing Business Tasks with Session EJBs.
Advertisements

Technische universität dortmund Service Computing Service Computing Prof. Dr. Ramin Yahyapour IT & Medien Centrum 12. November 2009.
EJB Entity Beans. Entity Beans Data versus logic Used to represent an instance rather than a collection of data (depending on underlying storage) Represents.
Development and Deployment Roles Venugopal Pakanati.
Overview of The Java Platform Solution for E-Business Applications : JSP, Servlet and EJB.
Writing Enterprise Applications with J2EE (Third lesson) Alessio Bechini June 2002 (based on material by Monica Pawlan)
SEI/CBS Initiative Software Engineering Institute Carnegie Mellon University Pittsburgh, PA Sponsored by the U.S. Department of Defense © 1999.
J2EE Kenneth M. Anderson CSCI Web Technologies October 3, 2001.
A Case Study on the J2EE Platform CPSC550 Graduate Student Seminar Presentation by Jeffrey A. Brown.
Chapter 10 EJB Concepts of EJB Three Components in Creating an EJB Starting/Stopping J2EE Server and Deployment Tool Installation and Configuration of.
EJB Fundamentals Celsina Bignoli
EJB. Component Characteristics An enterprise Bean typically contains business logic that operates on the enterprise’s data. An enterprise Bean’s instances.
4-Tier Model Client Tier Web Tier Business Tier EIS Tier.
Brad Rippe Fullerton College. What you need to get started? JDK 1.3 standard for compilation J2EE - SDK1.2.1 App Server - An EJB Container/Web Container.
15 - RMI/EJBCSC4071 Distributed Objects Java Remote Method Invocation Enterprise Java Beans.
1 Session Bean Chuyên đề Lập trình Java & J2EE Chương 14 Biên soạn: Th.S Nguyễn văn Lành.
J2EE Part 2: Enterprise JavaBeans CSCI 4300 Images and code samples from jGuru EJB tutorial,
Enterprise Java Beans - (EJB)
Seminar: Enterprise JavaBeans. Agenda Agenda Java™ 2 Platform Java™ 2 Platform Java™ 2 Platform,Enterprise Edition(J2EE) Java™ 2 Platform,Enterprise Edition(J2EE)
Writing Enterprise Applications with J2EE (Second lesson) Alessio Bechini June 2002 (based on material by Monica Pawlan)
Distributed Object-Oriented Programming (3) – Enterprise JavaBeans SNU iDB Lab. Taewhi Lee May 14th, 2007.
第十四章 J2EE 介绍 1.Java 2 Platform Enterprise Edition (J2EE) 1.3 API 2.J2EE Architecture 3.J2EE Application Development Lifecycle 4.JSP 5.Servlet 6.JavaBean.
Entity Beans BMP Celsina Bignoli
Middleware Technology (J2EE/EJB) Entity Bean. 2 Introduction to Entity Beans Persistence Concepts Entity beans are persistent objects that can be stored.
© jGuru.com Enterprise JavaBeans Fundamentals.
Container-Managed Persistence (CMP) Entity Beans Lesson 3A / Slide 1 of 42J2EE Server Components Objectives In this lesson, you will learn to: Identify.
Enterprise JavaBeans Umer Farooq CS6704: Design Patterns & Component FrameworksFebruary 25, 2002.
Distributed Systems 1 Master of Information System Management Distributed Systems Persistence.
The Triad of Beans I Oleh: Dini Addiati ( ) Fahrurrozi Rahman ( Y) Irfan Hilmy ( ) Salman Azis A ( ) Aziiz Surahman.
Presented By Pradeep K Sahu. What will be the Contents of the Seminar ? What is EJB ? EJB Architecture Types of EJB Session Entity Why EJB ? Writing a.
Enterprise JavaBeans. Lesson 1: Introduction to Server-Side Component Software.
Enterprise JavaBeans. What is EJB? l An EJB is a specialized, non-visual JavaBean that runs on a server. l EJB technology supports application development.
EJB Framework.  As we know, EJB is the center of the J2EE architecture that provides a sturdy framework for building enterprise applications. The major.
Enterprise Java Bean Computer Networks Natawut Nupairoj, Ph.D. Department of Computer Engineering Chulalongkorn University.
Session Beans Objectives Introduction to Session Beans Local and Remote Session Beans Stateless and Stateful Session Beans Session Bean Lifecycle Accessing.
Session Beans -) stateless -) stateful. Session Beans A session bean represents a single client inside the J2EE server. To access an application that.
A TUTORIAL TO USING EJBs by SHREERAM IYER 09/17/2001.
Enterprise JavaBeans Understanding EJB Components Version 0.1 Kamal Wickramanayake
1 Session Beans and Business Logic Presented By: Sethu Ram Kettimuthu.
© jGuru.com Enterprise JavaBeans Fundamentals.
Creating competitive advantage Copyright © 2003 Enterprise Java Beans Presenter: Wickramanayake HMKSK Version:0.1 Last Updated:
EJB Overview: Constraint Types and Enforcement in JBoss Elissa Newman Fluid Meeting 6/3/04.
Entity Beans & Persistence Chris Alexander CS 486 Spring 2001.
Enterprise Java Bean Technology Briefing Markus Hebach.
Session Beans Based on: Patel, Brose, Silverman, Mastering Enterprise JavaBeans 3.0.
Session Beans Objectives Introduction to Session Beans Local and Remote Session Beans Stateless and Stateful Session Beans Session Bean Lifecycle Accessing.
Java Programming: Advanced Topics 1 Enterprise JavaBeans Chapter 14.
Enterprise Java Beans N.V.RAJASEKHAR REDDY. Definition of EJB EJBs are the components that are the set of classes and interfaces deployed within a container.
Copyright © 2002 ProsoftTraining. All rights reserved. Enterprise JavaBeans.
Enterprise Java Beans Ye Zhou CS6704 Presentation Virginia Tech.
13 Copyright © 2004, Oracle. All rights reserved. Managing Persistent Data in the Business Tier Entity EJBs.
©NIIT Introducing Enterprise JavaBeans (EJB) Lesson 1A / Slide 1 of 43J2EE Server Components Objectives In this lesson, you will learn about: The features.
Enterprise JavaBeans: Fundamentals. EJB Fundamentals(c)CDAC(Formerly NCST)2 Contents Introduction Technology Overview EJB Architecture EJB Specification.
D Copyright © 2004, Oracle. All rights reserved. BMP Entity EJBs J2EE Connector Architecture.
Enterprise JavaBeans. Lesson 1: Introduction to Server-Side Component Software.
Middleware Technology (J2EE/EJB) EJB Fundamentals.
Session Beans & Business Logic CS 486 Sagar Deshpande.
14 Copyright © 2004, Oracle. All rights reserved. Achieving State Management in the Business Tier.
JAVA & J2EE UNIT – 8 ENTERPRISE JAVA BEAN - EJB 28-Jun-16 Prepared by: SANTHIYA.M & GANGA V. C. Department: Computer Science & Engineering Course code:
©NIIT Session Beans Lesson 1B/ Slide 1 of 37J2EE Server Components Objectives In this lesson, you will learn to: Describe the characteristics of session.
Enterprise Java Beans Overview
Structure of Enterprise Java Beans
Objectives In this lesson, you will learn to:
Understanding and Designing with EJB
Enterprise Java Beans Bina Ramamurthy 1/13/2019 B.Ramamurthy.
Understanding and Designing with EJB
Enterprise Java Beans Bina Ramamurthy 4/5/2019 B.Ramamurthy.
Enterprise Java Beans: an introduction
Enterprise Java Beans.
Introduction to Session beans
Presentation transcript:

Enterprise JavaBeans™ Trademark of Sun Microsystems, Inc.

Agenda " Review " Interfaces " Deployment Descriptors " Using Beans " Homework 5

Review – need development and runtime environment " J2EE SDK " development environment from tool vendor like Together, Inprise " runtime environment from Sun, IBM, BEA, Inprise, etc. – beans are server-side components " entity beans model real-world objects – persistent in nature, can be externally manipulated " session beans manage processes or tasks – transient in nature, though have side effects that perist " message-driven beans increase reliability and efficiency – transient in nature, process messages sent to message server

Interface Review " remote interface: defines business methods; EJBObject extension " home interface: defines life cycle methods; EJBHome extension " bean class: implements business methods " implements EntityBean or SessionBean " MessageDrivenBean is a different story, left untold " primary key: for entity beans; DB reference

Clients and Containers Review " client uses home and remote interfaces " not bean class itself " bean and server/infrastructure interactions managed by "container" " container creates instances, manages storage, etc. " tools support container, doing things like: " mapping between entity beans and DB records " generating code from interfaces " etc.

Remote Interface just the business methods not used by message-driven beans import java.rmi.RemoteException; public interface xxx extends javax.ejb.EJBObject { public... throws RemoteException: } By convention, xxx is name of business object or process “…” means any method signature

Remote Interface Example package account; import java.rmi.RemoteException; public interface Account extends javax.ejb.EJBObject { public void debit(MoneyAmount amount) throws RemoteException, InsufficientFundsException; public void credit(MoneyAmount amount) throws RemoteException; }

Home Interface life cycle and bean look-up methods not used by message-driven beans import java.rmi.RemoteException; import java.ejb.CreateException; import java.ejb.FinderException; // BMP entity bean only public interface xxxHome extends javax.ejb.EJBHome { public xxx create(...) throws RemoteException, CreateException; // BMP entity bean only below public xxxPK findByPrimaryKey(...) throws RemoteException, FinderException; }

Home Interface Example package account; import java.rmi.RemoteException; import javax.ejb.CreateException; import javax.ejb.FinderException; public interface AccountHome extends javax.ejb.EJBHome { public Account create(String name, String ssNumber, MoneyAmount initialBalance) throws RemoteException, CreateException; public findByPrimaryKey(AccountPK pk) throws RemoteException, FinderException; }

Generic Enterprise Bean Class public class xxxBean implements javax.ejb.zzzBean { // … >>> business methods here <<<… public … ejbCreate(…) {…} public void ejbRemove() {} // context setting public void setzzzContext(javax.ejb.zzzContext ctx) {} // etc. }

EntityBean Class public class xxxBean implements javax.ejb.EntityBean { // …>>> public instance variables from persisted storage <<<… // … >>> business methods here <<<… public xxxPK ejbCreate(…some key...) {…; return null;} public void ejbPostCreate(…some key...) {} public void ejbActivate() {} public void ejbPassivate() {} public void ejbRemove() {} public void setEntityContext(javax.ejb.EntityContext ctx) {} public void unsetEntityContext() {} public void ejbLoad() {} public void ejbStore() {} }

EntityBean Example, Part 0 // AccountPK.java: package account; public class AccountPK implements java.io.Serializable { public String id; public int hashCode( ){ return // integer hash of id; } public boolean equals(Object obj){ if(obj instanceof AccountPK){ return (id == ((AccountPK)obj).id); } return false; } public String toString(){ return id; }

EntityBean Example, Part 1 // AccountBean.java: package account: public class AccountBean implements javax.ejb.EntityBean { private static int count=0; public String id; public String name; public String ssNumber; public MoneyAmount balance; public void debit(BigDecimal amount) throws RemoteException, InsufficientFundsException { if (balance.compareTo(amount) > 0) balance.Decrement(amount); else raise InsufficientFundsException; } //…continued

EntityBean Example, Part 2 public void credit(MoneyAmount amount) throws RemoteException { balance.Increment(amount); } public AccountPK ejbCreate(String name, String ssNumber, MoneyAmount initialBalance) { this.name = name; // check for errors??? this.ssNumber = ssNumber; balance = new MoneyAmount(initialBalance); count += 1; // ??? id = “ ” + count; // ??? return null; } public void ejbPostCreate(String name, String ssNumber, MoneyAmount initialBalance) {} //…continued

EntityBean Example, Part 3 public void ejbActivate() {} public void ejbPassivate() {} public void ejbRemove() {} public void setEntityContext(javax.ejb.EntityContext ctx) {} public void unsetEntityContext() {} public void ejbLoad() {} public void ejbStore() {} }

SessionBean Class public class xxxBean implements javax.ejb.SessionBean { // … >>> business methods here <<<… public... ejbCreate(...) {…; return null;} public void ejbActivate() {} public void ejbPassivate() {} public void ejbRemove() {} public void setSessionContext(javax.ejb.SessionContext ctx) {} }

SessionBean Example, Part 0 from: Enterprise JavaBeans, R. Monson-Haefel, O’Reilly, // TravelAgent.java: // imports... public interface TravelAgent extends javax.ejb.EJBObject{ public String [] listCabins(int shipID, int bedCount) throws RemoteException; } // TravelAgent???.java: // imports... public interface TravelAgent??? extends javax.ejb.EJB???{ public TravelAgent create() throws RemoteException, CreateException; }

SessionBean Example, Part 1 from: Enterprise JavaBeans, R. Monson-Haefel, O’Reilly, // TravelAgentBean.java // imports... public class TravelAgentBean implements javax.ejb.SessionBean { public String [] listCabins(int shipID, int bedCount) { try{ javax.naming.Context jc = new InitialContext(); CabinHome home = (CabinHome) javax.rmi.PortbleRemoteObject.narrow( (Object) jc.lookup(“CabinHome”), CabinHome.class); Vector list = new Vector(); CabinPK pk = new CabinPK(); Cabin cabin; // continued...

SessionBean Example, Part 2 for (int i=0; ; i++) pk.id = i; try{ cabin = home.findByPrimaryKey(pk); } catch (javax.ejb.FinderException fe) {break;} if (cabin.getShip() == shipID && cabin.getBedCount() == bedCount) { list.addElement((String) i+”, ” +cabin.getName() + “, “ + cabin.getDeckLevel()); } String [] strings = new String[list.size()]; list.copyInto(strings); return strings; } catch (Exception e) {throw new EJBException(e);} } // continued...

SessionBean Example, Part 3 public TravelAgent ejbCreate() {return null;} public void ejbActivate() {} public void ejbPassivate() {} public void ejbRemove() {} public void setSessionContext(javax.ejb.SessionContext ctx) {} }

MessageDrivenBean Class public class xxxBean implements javax.ejb.MessageDrivenBean, javax.jms.MessageListener { public void ejbCreate(...) {…} public void ejbRemove() {} public void onMessage(javax.jms.Message message) {…} public void setMessageDrivenContext( javax.ejb.MessageDrivenContext mdc) {} }

Deployment Descriptors " as of EJB 1.1, tags in XML files (ejb-jar.xml) " part of a jar file, which defines a bean " declares behavior externally vs. inside code " allows deployer to change way code works by changing environment, including naming " lists dependencies " groups beans

Deployment Descriptors: EntityBean Example, Part 1 from: Enterprise JavaBeans, R. Monson-Haefel, O’Reilly, This Cabin enterprise bean entity represents a cabin on a cruise ship. CabinBean com.titan.cabin.CabinHome com.titan.cabin.Cabin com.titan.cabin.CabinBean Container com.titan.cabin.CabinPK False id name deckLevel ship bedCount

Deployment Descriptors: EntityBean Example, Part 2 This role represents everyone who is allowed full access to the cabin bean. everyone everyone CabinBean *

Deployment Descriptors: EntityBean Example, Part 3 CabinBean * Required

Deployment Descriptors: SessionBean Example, Part 1 from: Enterprise JavaBeans, R. Monson-Haefel, O’Reilly, TravelAgentBean com.titan.travelagent.TravelAgentHome com.titan.travelagent.TravelAgent com.titan.travelagent.TravelAgentBean Stateless Container ejb/CabinHome Entity com.titan.cabin.CabinHome com.titan.cabin.Cabin

Deployment Descriptors: SessionBean Example, Part 2 This role represents everyone who is allowed full access to the cabin bean. everyone everyone TravelAgentBean *

Deployment Descriptors: SessionBean Example, Part 3 TravelAgentBean * Required

Deployment – put all class files and bean descriptors in a jar file " make a folder called META-INF at root of source tree " copy ejb-jar.xml to META-INF " then: jar cf com\titan\com\travelagent\*.class META-INF\ejb-jar.xml – Use the deployment tool provided by the EJB server vendor to configure the environment " For Sun’s J2EE Reference Implementation: – deploytool: generates.ear file which includes server-specific descriptor (sun-j2ee-ri.xml) and application-specific descriptor " Fill in the fields with information pertinent to the bean " deploy to your EJB server host

Client Application " uses the bean(s) " via the remote and home interfaces " never via the bean class " steps " find the naming service " find the bean(s) " use home and business methods as desired

Client Application: Example, Part 1 from: Enterprise JavaBeans, R. Monson-Haefel, O’Reilly, package com.titan.travelagent; import com.titan.cabin.CabinHome; import com.titan.cabin.Cabin; import com.titan.cabin.CabinPK; import javax.naming.InitialContext; import javax.naming.Context; import javax.naming.NamingException; import javax.ejb.CreateException; import java.rmi.RemoteException; import java.util.Properties; // continued...

Client Application: Example, Part 2 public class Client_1 { public static int SHIP_ID = 1; public static int BED_COUNT = 3; public static void main(String [] args){ try { Context jndiContext = getInitialContext(); Object obj = jndiContext.lookup("ejb/TravelAgentHome"); TravelAgentHome home = (TravelAgentHome) javax.rmi.PortableRemoteObject.narrow(obj, TravelAgentHome.class); TravelAgent reserve = home.create(); // continued...

Client Application: Example, Part 3 // Get a list of all cabins on ship 1 with a bed count of 3. String list [] = reserve.listCabins(SHIP_ID,BED_COUNT); for(int i = 0; i < list.length; i++){ System.out.println(list[i]); } } catch(java.rmi.RemoteException re){re.printStackTrace();} catch(Throwable t){t.printStackTrace();} } static public Context getInitialContext() throws Exception { Properties p = new Properties(); //... Specify the JNDI properties specific to the vendor. return new InitialContext(); }

Homework 5 " Programming assignment #2 – tasks " implement Account beans for savings and checking accounts; use student id for account number prefix " implement transferMoney bean " implement client to transfer money from one account to another " deploy (don’t create/delete table) & run – use container-managed persistence – use JNDI for databases: jndi/SavingsAccountDB and jndi/CheckingAccountDB