©1996-2000 jGuru.com Enterprise JavaBeans Fundamentals.

Slides:



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

11 Copyright © 2005, Oracle. All rights reserved. Creating the Business Tier: Enterprise JavaBeans.
Enterprise JavaBeans Ruslana Svidzinska CSE690. What is EJB? l An EJB is a specialized, non-visual JavaBean that runs on a server. l EJB technology supports.
6/1/20151 Luca Simone Software Engineering 2 a.a. 2001/2002.
1 Softsmith Open Learning - EJB 21-Nov Enterprise Java Beans Introduction –Application ServerApplication Server –Java 2 Enterprise EditionJava.
Universität Bonn, Seminar Softwaretechnologie SS 2003, Duc Luu 1 Topics: Java Remote Method Invocation (RMI) Enterprise JavaBeans (EJB) Overview.
June 1999 EJB1 EJB and CHAIMS Dorothea Beringer Enterprise Java Beans and how to build a CHAIMS infrastructure using the EJB paradigm.
Introduction to Enterprise JavaBeans. Integrating Software Development Server-side Component Model Distributed Object Architecture –CORBA –DCOM –Java.
Overview of The Java Platform Solution for E-Business Applications : JSP, Servlet and EJB.
Enterprise Java Beans Welcome to the world of “Distributed System” Presented By: Sameer Nanda Date: 12/17/03.
Application Server Lecture Paulo Barroso Kris Carver Todd Kitterman Eric Silva.
Copyright W. Howden1 Lecture 19: Intro to O/O Components.
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.
Emmanuel Cecchet et al.  Performance Scalability of J2EE application servers.  Test effect of: ◦ Application Implementation Methods ◦ Container Design.
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.
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.
1 J2EE Components. 2 Application Servers relieve the programming burden for business distributed components. They provide support for system level services.
Enterprise Java Beans CS-422. Application Servers In the late 1980s and though the mid 1990s a number of corporations (Broadvision, Netscape…) marketed.
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)
EJB Enterprise Java Bean.
Seminar: Enterprise JavaBeans. Agenda Agenda Java™ 2 Platform Java™ 2 Platform Java™ 2 Platform,Enterprise Edition(J2EE) Java™ 2 Platform,Enterprise Edition(J2EE)
Entity Beans BMP Celsina Bignoli
Advanced Java Session 7 New York University School of Continuing and Professional Studies.
Enterprise Java Beans Part I Kyungmin Cho 2001/04/10.
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.
Introduction to J2EE Architecture Portions by Kunal Mehta.
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.
第十四章 J2EE 入门 Introduction What is J2EE ?
Enterprise Java Beans Java for the Enterprise Server-based platform for Enterprise Applications Designed for “medium-to-large scale business, enterprise-wide.
Enterprise Java Beans Alex Chaffee, slides originally created by Dave Orchard
Enterprise JavaBeans Understanding EJB Components Version 0.1 Kamal Wickramanayake
© jGuru.com Enterprise JavaBeans Fundamentals.
© jGuru.com Enterprise JavaBeans Fundamentals.
Introduction to Enterprise JavaBeans Topics In Systems Architecture Barry Herbold
Assignment of JAVA id : BSSE-F10-M-10-JAVA1 Overview of J2EE/Session 2/Slide 1 of 38.
EJB Overview: Constraint Types and Enforcement in JBoss Elissa Newman Fluid Meeting 6/3/04.
Enterprise Java Bean Technology Briefing Markus Hebach.
Introduction to EJB. What is an EJB ?  An enterprise java bean is a server-side component that encapsulates the business logic of an application. By.
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.
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.
Enterprise JavaBeans. Lesson 1: Introduction to Server-Side Component Software.
Middleware Technology (J2EE/EJB) EJB Fundamentals.
Advanced Java Session 7 New York University School of Continuing and Professional Studies.
EJB. Introduction Enterprise Java Beans is a specification for creating server- side scalable, transactional, multi-user secure enterprise-level applications.
14 Copyright © 2004, Oracle. All rights reserved. Achieving State Management in the Business Tier.
©NIIT Session Beans Lesson 1B/ Slide 1 of 37J2EE Server Components Objectives In this lesson, you will learn to: Describe the characteristics of session.
Entity Bean Chuyên đề Lập trình Java & J2EE Chương 15
Introduction to J2EE Architecture
Ruslana Svidzinska CSE690
Structure of Enterprise Java Beans
Objectives In this lesson, you will learn to:
Enterprise Java Beans Bina Ramamurthy 1/13/2019 B.Ramamurthy.
Component-based Applications
Component Technology Bina Ramamurthy 2/25/2019 B.Ramamurthy.
Understanding and Designing with EJB
Enterprise Java Beans Bina Ramamurthy 4/5/2019 B.Ramamurthy.
Enterprise Java Beans.
Presentation transcript:

© jGuru.com Enterprise JavaBeans Fundamentals

2 Agenda Enterprise JavaBeans defined EJB and Distributed Computing EJB Architecture Entity beans Session bean Deployment EJB Clients

© jGuru.com Enterprise JavaBeans: Defined

4 What is Enterprise JavaBeans The Enterprise JavaBeans architecture is a component architecture for the development and deployment of object-oriented distributed enterprise-level applications. Applications written using the Enterprise JavaBeans architecture is scalable, transactional and multi-user secure. These applications may be written once, and deployed on any server platform that supports the Enterprise JavaBeans specification Sun Microsystems Enterprise JavaBeans™ Specification, v1.1, Copyright 1999 by Sun Microsystems, Inc.

5 In English Please! Enterprise JavaBeans is a specification –(a piece of paper) not a product –As is XML, CORBA, TCP/IP Enterprise JavaBeans is Java based –Defined by Sun Microsystems –Applications are written in Java Enterprise JavaBeans is distributed objects –Similar to CORBA | Java RMI (JRMP) | Microsoft MTS Enterprise JavaBeans is components –Similar to regular JavaBeans (similar but not the same) –Similar to COM/DCOM/COM+ Enterprise JavaBeans products are Transactional Monitors –Similar to CICS | TUXEDO –A complete environment for a distributed object

6 Enterprise JavaBeans Simple Programming Model –Attribute based programming –Focus on Business Logic –Simple API –Well defined Lifecycle Portable –Specification ensures basic services –Component Packaging (JARs and XML DD) –Java

7 WORA Write-Once, Run Anywhere within Middleware Middleware provides all services –Instance management, transactions, concurrency, persistence Beans stay simple!

8 EJB Spec Spec developed by Sun and dozens of competing vendors –IBM, Oracle, BEA, WebLogic,... –Interoperable -- a miracle! Why did they cooperate? –See next slide...

9 The Common Enemy Phenomenon

10 EJB Advantages With EJB, you can write a business object and easily make it –Persistent –Distributed –Transactional –Secure –Multithreaded

11 Persistent Beans need to load and store data You can let the server do it –(Container-Managed Persistence) You can do it yourself –(Bean-Managed Persistence)

12 Transactional Support for distributed transactions You can let the Server manage all transactions –You will if you know what’s good for you –You can give it hints in deployment descriptor

13 Secure SSL/RMI protects transmitted data Client-Server architecture protects –proprietary code –backend database SSL authenicates client, server ACLs provide fine-grained control of access to objects, methods, services

14 Multithreaded Programmer delegates all responsibility for multithreading to server –Programmer literally can’t spawn a thread Program designer and/or sysadmin establishes multithreading policies Server enforces them invisibly

15 Naming Services JNDI Wrapper for many naming services –CORBA, RMI, etc.

16 CORBA: Sorta Porta(ble) CORBA: Complex Programming Model –Different API for each Service –Explicit use of service APIs –Lifecycle depends on services used Fairly Portable –Many Languages, many platforms (pro and con) –Non-Uniform support of Services

17 CORBA and EJB Transport –EJB uses RMI interface, RMI uses IIOP CORBA 3.0 promises object compatibility with EJB –Not quite sure what that means Some EJB Servers contain an ORB –All EJB Objects are also CORBA objects

18 CORBA and EJB (Cont.) All EJB Servers use CORBA Transactions (via JTS) –That means that any client can make a distributed transaction that includes both CORBA and EJB Objects Not an either-or decision –You can have both EJB and CORBA working together in a single system

19 What’s in a name? Enterprise Java Beans has absolutely nothing to do with JavaBeans –Except that both are Java-based component architectures EJB is server-side, JB is client-side –EJB has no GUI, JB usually has GUI JB is basically naming conventions for fully powered Java classes EJB rules are much more rigid EJB classes are less powerful on their own, but more powerful in a container

20 ’Tis but thy name that is my enemy EJB is all about really poor names Architecture makes sense, object names don’t –“Home” is a factory –“Container” is a helper or wrapper –“EJB Object” is an object but is not an EJB –"Enterprise JavaBean" is not a JavaBean

21 Disadvantages of N-Tier Architecture Learning curve $$ cost of products $$ cost of extra servers to achieve performance time + $$ cost of maintenance Object-relational mapping Basically, app servers are good for large, general solutions (e.g. multiple data sources, multiple applications)

© jGuru.com EJB Architecture

23 EJB Roles Bean developer: creates JAR with: –Remote interface with business functions –Home for accessing instances of bean –Bean itself –Properties and descriptor Assembler: integrates beans into clients Deployer: modifies and deploys beans –Organization-specifics, ie security

24 EJB Roles (cont.) Server provider provides Server run-time Container provider: provides tools and containers –Creates container classes that wrap bean –Manage installed beans

25 The EJB Container Think of the container as the server, holding your objects Containers host enterprise beans Containers isolate beans from clients –Intercept client requests –Set up transactions, security, persistence, etc. before and after calling EJB methods –Beans can also call methods of the container interface to get services Containers provide JNDI services too

26

27 Component API: Interfaces and Classes Home Interface –Extends javax.ejb.EJBHome –Provides remote access to create, find, remove beans Remote Interface –Extends javax.ejb.EJBObject –Provides remote access to business methods Bean Class –Extends a javax.ejb.EnterpriseBean type –Implements business logic and other functionality

28 Implements Invokes Creates / uses EJB Architecture Client Server Home Interface (Factory) EJB Object (Wrapper) Enterprise Java Bean (Biz Logic) Remote Interface Container RMI Naming Service You write this

29 Bean provider: What to write? Remote Interface –extend EJBObject interface –Define business method signatures Home Interface –extend EJBHome interface –Define create signatures –May define findBy signatures for entities

30 What to write (cont.)? Enterprise Bean Class –implement EntityBean or SessionBean –Implement business method signatures –Does not need to implement Remote Interface –not abstract –Implement ejbCreate methods matching Home create 1 ejbCreate for every Home.create N.B.: “create” in home interface, “ejbCreate” in Bean

31 Remote Interface import javax.ejb.EJBObject; import java.rmi.RemoteException; public interface Customer extends EJBObject { public Name getName() throws RemoteException; public void setName(Name name) throws RemoteException; public Address getAddress() throws RemoteException; public void setAddress(Address address) throws RemoteException; }

32 Home Interface import javax.ejb.EJBHome; import javax.ejb.CreateException; import javax.ejb.FinderException; import java.rmi.RemoteException; public interface CustomerHome extends EJBHome { public Customer create(Integer customerNumber) throws RemoteException, CreateException; public Customer findByPrimaryKey(Integer customerNumber) throws RemoteException, FinderException; public Enumeration findByZipCode(int zipCode) throws RemoteException, FinderException; }

33 Bean Class import javax.ejb.EntityBean; public class CustomerBean implements EntityBean { Address myAddress; Name myName; CreditCard myCreditCard; public Name getName() { return myName; } public void setName(Name name) { myName = name; } public Address getAddress() { return myAddress; } public void setAddress(Address address) { myAddress = address; }... }

34 Types of Beans Entity Beans –Represent data in the database –Include behavior (business methods) Session Beans –Represent tasks or processes –Do not represent data, but can access data –Manage the interactions of other beans

35 Home Interface Defined by Bean developer Implemented by server tools (autogenerated) Must extend interface EJBHome –EJBMetaData getEJBMetaData() –void remove(Handle ejbHandle) –void remove(Object primaryKey) Must provide your own create() methods –Foo create() –Foo create(Bar b, Baz z)…

36 Home Interface: Entity Beans Entity Beans are persistent, therefore they need more than a “create” method Need findXXX methods –public Foo findByPrimaryKey(Object key); –public Foo findByBar(Bar bar); –public Enumeration findOverdrawnAccounts(); Implement ejbFindXXX methods in bean –N.B.: “find” in home interface, “ejbFind” in Bean

37 Remote Interface Written by developer Defines methods accessible by client –Your business methods go here extends javax.ejb.EJBObject –standard methods provided by all EJBs –getEJBHome(), getPrimaryKey(), getHandle(), remove(), isIdentical(EJBObject obj)

38 Remote Interface vs. EJBObject vs. EJB Developer writes Remote Interface Tool uses RI to automatically generate the EJBObject class Developer writes the EJB source file N.B.: The EJB does not implement the Remote Interface –However, you still must implement all the business methods –Lame-o-rama: no type safety provided by compiler –Better: if EJB tool auto-created a new interface for the EJBObject (oh well)

39 Implementing the EJB Implements all your business methods Must also implement –ejbCreate() methods –ejbFind() methods (for Entity Beans) Also callback methods –ejbRemove() –ejbActivate() –ejbPassivate() Implement which interface? –javax.ejb.SessionBean –javax.ejb.EntityBean

40 Interfaces and Implementations EJBObject getEJBHome() getPrimaryKey() getHandle() isIdentical() remove() deposit() getBalance() Remote Interface deposit() getBalance() EJB ejbCreate() ejbRemove() ejbActivate() ejbPassivate() deposit() getBalance() Home Interface create() remove()

© jGuru.com Beans and Persistence

42 Persistence Container-ManagedPersistence –Server reads values from your bean –Server stores/loads data for you –Very easy to write - just define data and server magically takes care of persistence

43 Container-Managed Persistence (CMP) Persistence is automatic –inserts, updates, and deletes are automatic –transactions managed automatically –server reads/writes your bean instance variables –Server also informs you before/after it's done something you implement callback methods

44 Container-Managed Persistence (CMP) cont. Easier to write beans –Focus on business logic, not persistence –But, requires sophisticated, vendor-specific data mapping tools Components more portable –not backend-specific –shrink-wrapped components

45 Bean-Managed Persistence –You code access database directly –Callback methods dictate when to insert, update, delete More control over persistence, performance Much harder to write Don’t need sophisticated data mapping tools

46 Entity Beans Model entities in a system –represent their data and associated behavior one or many relational database tables an object in an object database an entity in a legacy system –Nouns: People, Places or Things Customer, Employee, Student City, Building, Hotel Room Order, Organization, Health Benefit

47 Session Beans Not persistent, but can access database Model tasks, process or agents –Charge a credit card –Process a stock purchase –Perform hotel reservations Manage interactions of other beans

48 Stateless Session Beans Perform transitive tasks Independent business methods –Act on method arguments, not bean state –Similar to procedures in traditional TPM systems Most performant bean type Not dedicated to one client

49 Stateful Session Beans Act on behalf of one client –Extension of the client –Agent that performs work for the client Interdependent business methods –Bean has conversational state –Method depend on conversational state Dedicated to exactly one client

© jGuru.com EJB Deployment

51 Function of a Deployment Descriptor Describe bean(s) to the container –interfaces and class –type of bean (entity or session) –identify primary key & container-managed fields Declare runtime behavior –transaction attributes of methods –authorization access to method –persistence type (BMP vs. CMP) Written in XML

© jGuru.com EJB Clients

53 Types of Clients Enterprise beans J2EE Application Components Java Applications Java Applets Servlets JSP

54 Example: J2EE Application Component CustomerHome home; Object ref; // Obtain a reference to the CustomerHome ref = jndiContext.lookup("java:comp/env/ejb/Customer"); // Cast object returned by the JNDI lookup to the // appropriate datatype home = PortableRemoteObject.narrow(ref, CustomerHome.class); // Use the home interface to create a // new instance of the Customer bean. Customer customer = home.create(customerID); // Use a business method on the Customer. customer.setName(someName);

55 Messaging Beans New with EJB 2.0 Use JMS for asynchronous message queue services Allows asynchronous response –I will gladly pay you Tuesday for a hamburger today –Get some of the missing Thread functionality back Not completely supported yet –Must sit on a message queue product

56 Value Objects Fact: –EJBs are RMI remote objects Problem: –Calling each setter or getter goes across the network –Slow if you're accessing more than one value at once Solution: –Value object which mimics the EJB, only it isn't remote –EJB has methods to get and set value object –Client sets/gets values locally, sends/receives en masse

57 Online Resources jGuru EJB FAQ – Sun EJB Page – EJBNow –

58 Thanks To Richard Monson-Haefel Dave Orchard Random Walk Computing