Presentation is loading. Please wait.

Presentation is loading. Please wait.

11 Copyright © 2005, Oracle. All rights reserved. Creating the Business Tier: Enterprise JavaBeans.

Similar presentations


Presentation on theme: "11 Copyright © 2005, Oracle. All rights reserved. Creating the Business Tier: Enterprise JavaBeans."— Presentation transcript:

1 11 Copyright © 2005, Oracle. All rights reserved. Creating the Business Tier: Enterprise JavaBeans

2 11-2 Copyright © 2005, Oracle. All rights reserved. Objectives After completing this lesson, you should be able to do the following: Define an Enterprise JavaBean Describe the Enterprise JavaBeans (EJB) architecture Describe the types of EJBs and when they are used Explain EJB interfaces Define the steps to deploy an EJB to Oracle Application Server 10g

3 11-3 Copyright © 2005, Oracle. All rights reserved. Enterprise JavaBeans (EJB) Enterprise JavaBeans are portable components, which: Enable faster application development Allow reuse of business components Encapsulate business logic that can be invoked by clients Execute in a container that provides services such as support for transactions, persistence, and access control for the beans

4 11-4 Copyright © 2005, Oracle. All rights reserved. When to Use EJBs When developing a J2EE application, decide whether to use EJBs based on the following requirements: The applications are complex and would benefit from the system-level services that are provided by an EJB container. The applications must be portable and scalable. The applications must be accessed by different types of clients.

5 11-5 Copyright © 2005, Oracle. All rights reserved. Types of EJBs EJB TypePurpose Session BeansPerforms a task for a client Entity Beans Represents a business object that exists in a database Message-Driven Beans Receives asynchronous Java Message Service (JMS) messages

6 11-6 Copyright © 2005, Oracle. All rights reserved.

7 11-7 Copyright © 2005, Oracle. All rights reserved. Session Beans Session beans invoke methods for a single client. There are two types of session beans: Stateless Session Beans (SLSBs) –Conversation that spans a single method call –Single request business processes that do not maintain client-specific state Stateful Session Beans (SFSBs) –Conversation with one client that may invoke many methods –Business processes that span multiple method requests, thus maintaining state EJB container Client 1 Client 2 Pool of SLSBs EJB container Client 1 Client 2 SFSBs

8 11-8 Copyright © 2005, Oracle. All rights reserved.

9 11-9 Copyright © 2005, Oracle. All rights reserved. Entity Beans Entity beans represent a business object in the database. They are: Sharable across multiple clients Uniquely identifiable through a primary key Persistentthe state survives an EJB server crash There are two types of persistence in entity EJBs: Container-managed persistence (CMP) beans: –The state of the bean is maintained by the container. –The bean developer specifies the persistent fields. Bean-managed persistence (BMP) beans: –The state of the bean is maintained by the bean itself. –The bean developer writes the logic to manage persistence by using Java Database Connectivity (JDBC).

10 11-10 Copyright © 2005, Oracle. All rights reserved. Message-Driven Beans Provide a facility for asynchronous communication Exist within a pool, and receive and process incoming messages from a JMS queue or topic Are invoked by the container to handle each incoming message from the queue or topic Are similar to stateless session beans Clients EJB container Pool of MDBs JMS queue

11 11-11 Copyright © 2005, Oracle. All rights reserved. EJB Architecture EJB client EJB server Enterprise Services Naming, Transaction, Security, Messaging Deployment descriptor Database EJB container Remote/ local object Home/ local home object Remote/ local interface Home/local home interface EJB Class

12 11-12 Copyright © 2005, Oracle. All rights reserved. EJB Server Manages the EJB container Provides a deployment and execution platform for EJB components Provides system services to containers that in turn provide services to beans: –Transaction services –JNDI naming services Can provide vendor-specific features such as connection pooling

13 11-13 Copyright © 2005, Oracle. All rights reserved. EJB Container Manages the life cycle of the enterprise beans Isolates the enterprise beans from direct access by client applications Makes required services available to the EJB classes through well-defined interfaces Client EJB container EJB class home/local home object Home/local home interface Container generated remote/l ocal object Remote/ local interface

14 11-14 Copyright © 2005, Oracle. All rights reserved. Services Provided by the EJB Container Life-cycle management Bean instance pooling Client state management Database connection pooling Declarative transaction management Security Persistence

15 11-15 Copyright © 2005, Oracle. All rights reserved.

16 11-16 Copyright © 2005, Oracle. All rights reserved. EJB Client An EJB client is a stand-alone application, servlet, JSP, or another EJB that accesses the bean. It can be a: Local client: –Resides within the same Java virtual machine (JVM) as the bean –Passes arguments by reference to the bean –Interacts with the EJB through methods defined in the local interface Remote client: –Is location independent –Passes arguments by value to the bean –Interacts with the EJB through methods defined in the remote interface

17 11-17 Copyright © 2005, Oracle. All rights reserved. EJB Interfaces and Classes Interfaces: –Remote interface/Local interface –Home interface/Local home interface Classes: –Bean class –Primary key class (entity beans)

18 11-18 Copyright © 2005, Oracle. All rights reserved. Remote Interface and Remote Object Remote interface: –Extends the javax.ejb.EJBObject interface that extends the java.rmi.Remote interface –Describes the client view of an EJB –Declares the business methods that are accessible to remote clients EJB object: –Is a container-generated implementation of a remote interface –Is a reference object that a client receives –Delegates the method calls to a bean class after doing some infrastructure work The remote interface and remote object are used by session and entity beans.

19 11-19 Copyright © 2005, Oracle. All rights reserved. Home Interface and Home Object Home interface: –Extends the javax.ejb.EJBHome interface that extends the java.rmi.Remote interface –Contains the life-cycle methods for creating, removing, and locating the instances of a bean class –Contains home methods –Are accessed by remote clients Home object: –Is a container-generated implementation of the home interface –Uses callback methods on a bean class to perform its functions

20 11-20 Copyright © 2005, Oracle. All rights reserved. Local Interface and Local Home Interface Local interface: –Extends the javax.ejb.EJBLocalObject interface –Declares the business methods of the bean that are accessible by a local client –Improves performance because the bean resides in the same JVM, and parameters are passed by reference Local home interface: –Extends the javax.ejb.EJBLocalHome interface –Defines the life-cycle methods that are accessible by local clients These interfaces are used by session and entity beans. They enable relationships between entity beans.

21 11-21 Copyright © 2005, Oracle. All rights reserved. EJB Bean Class A bean class extends javax.ejb.EnterpriseBean. A session/entity bean class: –Implements javax.ejb.SessionBean / javax.ejb.EntityBean –Implements business/life-cycle methods –Contains methods to support container callbacks –Contains methods to set and unset the context of the bean A message-driven bean class: –Implements javax.ejb.MessageDrivenBean –Must implement the MessageListener interface –Contains business logic in the onMessage() method

22 11-22 Copyright © 2005, Oracle. All rights reserved. The EJB Deployment Process Jar command/ tool EJB JAR JNDI Component deployers responsibility Developers responsibility Home interface Remote interface Bean class Other classes Deployment descriptor Deployment tools/ commands Deployed EJB in the Server

23 11-23 Copyright © 2005, Oracle. All rights reserved. | | Say Hello HelloWorld lesson11.HelloWorldHome lesson11.HelloWorld lesson11.impl.HelloWorldBean | | ejb-jar.xml File

24 11-24 Copyright © 2005, Oracle. All rights reserved. orion-ejb-jar.xml File Oracle Application Server 10g uses the orion-ejb-jar.xml file for deployment. This file: Specifies run-time attributes of the bean for deployment to the container Enables customization of the run-time behavior of enterprise beans

25 11-25 Copyright © 2005, Oracle. All rights reserved. Creating an EJB in JDeveloper

26 11-26 Copyright © 2005, Oracle. All rights reserved. Using the EJB Wizard

27 11-27 Copyright © 2005, Oracle. All rights reserved. Using the EJB Wizard

28 11-28 Copyright © 2005, Oracle. All rights reserved. Adding Methods to the Bean To add methods to the bean, right-click and select Go To Bean Class:

29 11-29 Copyright © 2005, Oracle. All rights reserved. Deploying to Oracle Application Server 10g from JDeveloper

30 11-30 Copyright © 2005, Oracle. All rights reserved. Summary In this lesson, you should have learned how to: Define an EJB Describe the EJB architecture Describe the types of EJBs and when they are used Explain EJB interfaces Define the steps to deploy an EJB to Oracle Application Server 10g

31 11-31 Copyright © 2005, Oracle. All rights reserved. Practice 11-1: Overview This practice covers the following topics: Creating an EJB in JDeveloper Testing an EJB

32 11-32 Copyright © 2005, Oracle. All rights reserved.

33 11-33 Copyright © 2005, Oracle. All rights reserved.

34 11-34 Copyright © 2005, Oracle. All rights reserved.


Download ppt "11 Copyright © 2005, Oracle. All rights reserved. Creating the Business Tier: Enterprise JavaBeans."

Similar presentations


Ads by Google