Presentation is loading. Please wait.

Presentation is loading. Please wait.

©1996-2000 jGuru.com Enterprise JavaBeans Fundamentals.

Similar presentations


Presentation on theme: "©1996-2000 jGuru.com Enterprise JavaBeans Fundamentals."— Presentation transcript:

1 ©1996-2000 jGuru.com Enterprise JavaBeans Fundamentals

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

3 ©1996-2000 jGuru.com Enterprise JavaBeans: Defined

4 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 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 ©1996-2000 jGuru.com Distributed Computing

7 7 Two-Tier Computing

8 8 Client: Presentation and Application logic –Text, Graphs, Widgets –Business logic –Data Access Backend: Database –Data –Security, Transactions –Resource Management

9 9 Multitier Computing

10 10 3-Tier Computing Client: Presentation Logic –Text, Graphs, Widgets Middle-Tier: Application Logic –Business Logic –Security, Transactions –Resource Management –Data Access Backend: Database –Data

11 11 Motivations for using 3-tier over 2-tier Quality of Service –Scalability –Availability –Performance Versatility –Flexibility –Extensibility

12 12 COM+ Simple Programming Model –Attribute based programming –Focus on Business Logic –Simple API –Well defined Lifecycle Limited Portability –Only on Windows Platform –One vendor: Microsoft

13 13 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

14 14 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

15 ©1996-2000 jGuru.com EJB Architecture

16 16 Foundation of EJB The EJB Container Enterprise bean components

17 17 The EJB Container Containers host enterprise beans Containers isolate beans from clients Containers manage enterprise beans Bean-Container interface –callback methods –EJBContext –JNDI ENC

18 18

19 19 Enterprise Bean Components Implements the EJB API Defined by an XML Deployment Descriptor Adheres to the EJB specification. Packaged in a JAR file

20 20 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

21 21

22 22 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; }

23 23 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; }

24 24

25 25 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; }... }

26 26

27 27 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

28 ©1996-2000 jGuru.com Entity Beans

29 29 Characteristics of 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 –Two Kinds of Persistence Container-Managed Persistence Bean-Managed Persistence

30 30 Container-Managed Persistence (CMP) Persistence is automatic –inserts, updates, and deletes are automatic –transactions managed automatically Focus on business logic, not persistence Components more portable –not backend specific –shrink wrapped components Requires sophisticated data mapping tools

31 31 public interface javax.ejb.EntityBean { public void setEntityContext(); public void unsetEntityContext(); public void ejbLoad(); public void ejbStore(); public void ejbActivate(); public void ejbPassivate(); public void ejbRemove(); } import javax.ejb.EntityBean; public class CustomerBean implements EntityBean { Address myAddress; Name myName; CreditCard myCreditCard;... public void setEntityContext(){} public void unsetEntityContext(){} public void ejbLoad(){} public void ejbStore(){} public void ejbActivate(){} public void ejbPassivate(){} public void ejbRemove(){} }

32 32 Callback Methods in CMP setEntityContext() / unserEntityContext() –EntityContext is an interface to container client identity, transactions, self ejbLoad() / ejbStore( ) –database synchronization notifications ejbLoad() just after bean fields refreshed from database ejbStore() just prior to database write

33 33 Callback Methods in CMP (cont..) ejbCreate()/ ejbRemove() –In response to client invocations –ejbCreate() just before inserting a new record(s) –ejbRemove() just before deleting record(s) ejbActivate( ) / ejbPassivate( ) –Resource Conservation Passivated instances are evicted or pooled Most container pool entity beans –Notify bean when passivation is occurring ejbPassivate() just before passivation ejbActivate() just after bean is restored

34 34 Bean-Managed Persistence Persistence is not automatic –Database access coded directly into bean Callback methods dictate when to insert, update, delete Database connections managed automatically Transactions and connections managed automatically Focus on business logic and persistence More control over persistence Don’t need Sophisticated data mapping tools

35 35 Callback Methods in BMP ejbLoad() / ejbStore( ) –Database synchronization notifications ejbLoad() tells bean to write state to database ejbStore() tells bean to read state from database ejbCreate()/ ejbRemove() –In response to client invocations –ejbCreate() tells bean to insert a new record(s) –ejbRemove() tells bean to delete record(s)

36 36 Callback method in BMP (cont.…) setEntityContext() / unserEntityContext() –Same as CMP ejbActivate( ) / ejbPassivate( ) –Same as CMP

37 37 Characteristics of 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 Two Kinds of Session beans –Stateless –Stateful

38 38 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

39 39 Callback methods in stateless beans setSessionContext() –SessionContext is an interface to container Client identity, transactions, self ejbCreate()/ ejbRemove() –Not in response to client invocations –ejbCreate() beginning of bean instance life –ejbRemove() end of bean instance life (before eviction) ejbPassivate()/ejbActivate() –Not used in stateless beans

40 40 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

41 41 Callback methods in stateful beans setSessionContext() –SessionContext is an interface to container Client identity, transactions, self ejbCreate()/ ejbRemove() –In response to client invocations –ejbCreate() initialize conversational state –ejbRemove() just before bean is destroyed

42 42 Callback methods in stateful beans (cont.…) ejbPassivate()/ejbActivate() –Passivation to secondary storage –ejbPassivate() just before passivation –ejbActivate() just after passivation

43 ©1996-2000 jGuru.com EJB Deployment

44 44 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

45 45 XML Deployment Descriptors XML Document –uses a DTD to verify structure –text document can view with any text editor –mark-up language start and end tags similar to HTML DTD (Document Type Definition) –defines all valid tags –defines nesting of tags

46 ©1996-2000 jGuru.com EJB Clients

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

48 48 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);

49 49 Java RMI-IIOP EJB 1.1 clients use the Java RMI-IIOP API Underlying protocol doesn’t have to be IIOP EJB 2.0 will require IIOP as the protocol Requirement smoothes transition to EJB 2.0 PortableRemoteObject.narrow( ) because CORBA doesn’t support native casting.

50 50 Topic Review Defined Enterprise JavaBeans EJB and Distributed Computing EJB Architecture Entity beans Session bean Deployment EJB Clients

51 51 Online Resources jGuru EJB FAQ –http://www.jguru.com/faq/EJB Sun EJB Page –http://java.sun.com/products/EJB EJBNow –http://www.ejbnow.com/


Download ppt "©1996-2000 jGuru.com Enterprise JavaBeans Fundamentals."

Similar presentations


Ads by Google