EJB Framework.  As we know, EJB is the center of the J2EE architecture that provides a sturdy framework for building enterprise applications. The major.

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.
Development and Deployment Roles Venugopal Pakanati.
Enterprise Java Beans Adam, Engels, Josh, Marc, Tim.
Copyright W. Howden1 Lecture 19: Intro to O/O Components.
Writing Enterprise Applications with J2EE (Third lesson) Alessio Bechini June 2002 (based on material by Monica Pawlan)
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.
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.
1 3. Implementing Web Services 1.Create SOAP proxy interfaces and WSDL based service descriptions 2.Register/publish services 3.Stores service descriptions.
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)
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.
Advanced Java Session 7 New York University School of Continuing and Professional Studies.
Entity Java Beans Jorg Janke Open Source ERP & CRM.
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.
1 Stateful Session Beans Stateless Session Beans Michael Brockway Sajjad Shami Northumbria University School of Computing, Engineering & Information Sciences.
Distributed Systems 1 Master of Information System Management Distributed Systems Persistence.
Enterprise Java Beans Part II Kyungmin Cho 2001/04/13.
Enterprise Java Bean Matt. 2 J2EE 3 J2EE Overview.
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.
Message-Driven Beans and EJB Security Lesson 4B / Slide 1 of 37 J2EE Server Components Objectives In this lesson, you will learn about: Identify features.
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
RMI-IIOP.  RMI-IIOP combines RMI-style ease of use with CORBA cross-language interoperability  Java™ Remote Method Invocation (RMI) provides a simple.
© 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.
J2EE Chris Hundersmarck Maria Baron Jeff Webb.  Java 2 Platform, Micro Edition (J2ME)  Java 2 Platform, Standard Edition (J2SE)  Java 2 Platform, Enterprise.
Enterprise JavaBeans Session Beans. Session beans are a type of Enterprise JavaBean component designed to implement business logic responsible for managing.
Session Beans Based on: Patel, Brose, Silverman, Mastering Enterprise JavaBeans 3.0.
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.
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.
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.
Enterprise JavaBeans™ Trademark of Sun Microsystems, Inc.
EJB Enterprise Java Beans JAVA Enterprise Edition
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.
1 EJB 3.0: There’s Something Different About You Martin Jäkle, TSBU Middleware.
©NIIT Session Beans Lesson 1B/ Slide 1 of 37J2EE Server Components Objectives In this lesson, you will learn to: Describe the characteristics of session.
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.
Introduction to Session beans
Knowledge Byte In this section, you will learn about:
Objectives In this lesson, you will learn about:
Enterprise Java Beans.
Presentation transcript:

EJB Framework

 As we know, EJB is the center of the J2EE architecture that provides a sturdy framework for building enterprise applications. The major elements of the EJB framework include EJB server, EJB container, EJB components, and EJB client.  EJB or J2EE server - EJB server stores the container and offers system-level services.  EJB container - EJB container provides runtime services such as memory allocation and database connectivity to a bean. It also manages the life cycle of the beans. It acts as an interface between the EJB components and the outside world.  EJB components – EJB architecture defines three types of EJB components, session beans, entity beans, and message-driven beans. Every EJB component is associated with two interfaces, a home interface and a component interface.

EJB Types  Session Beans Represents business processing performed in an application  Entity Beans Persistence data in an application is represented by Entity Beans  Message Driven Beans Represents business processing to be carried out in asynchronous way

EJB Components EJB Application consists of following main components Home interface - EJBHome is the home interface that provides methods for creating, removing, and locating instances. An EJB developer defines the home interface, and the EJBHome object is generated by the tools provided by the container vendor. An instance of the class that implements the home interface is called a Home object. Component or Remote interface - EJBObject is the component interface that provides the business methods present in EJB. An EJB developer defines the remote interface, and EJBobject is generated by the tools provided by the container vendor. An instance of a class that implements the component interface is called EJBObject. Enterprise Bean - Bean class provides the implementation of business methods declared in Home or Component interface. Container instantiates the bean (life-cycle) and makes it available to server client’s requests. EJB client – A client for an EJB could be a java program, or another enterprise bean or can be a web module also. A client cannot call methods on a bean directly. It has to invoke the method on the EJBObject. The component interface exposes the business methods of the bean and the EJBObject is an instance of the class implementing the component interface.

Session Beans  Stateless Session Beans does not maintain any conversation state of a client E.g. : Whether monitoring system  Stateful Session Beans conversation state of a client is maintained for the duration of the session E.g. : Banking Application

Entity Beans  Bean Managed Persistence  Container Managed Persistence Entity Bean Instance An Entity

Contd…  An entity bean is a type of enterprise bean that represents data saved in persistent stores.  A persistent store can be a database table or a flat file.  An entity bean instance represents a particular row or data in a particular table or multiple tables. For example, if employee is an entity in a problem specification, a specific employee represents an instance of an entity bean. The information about an employee can spread across multiple tables too. The tables could provide information on personal details, professional details, project details.  Thus the instances of entity bean may engage themselves in some or other kind of relationships. This is similar to the foreign key-primary key relationships in the RDBMS.  Entity beans can be of two types, bean-managed persistence or BMP and container-managed persistence or CMP. A BMP manages its own state in a data store where as a CMP assigns saving its state to the EJB container.

Coding Example package mypack.Hello; import javax.ejb.*; public class HelloBean implements SessionBean { public void ejbCreate() { System.out.println("ejbCreate()"); } public void ejbRemove() { System.out.println("ejbRemove()"); } public void ejbActivate() { System.out.println("ejbActivate()"); } public void ejbPassivate() { System.out.println("ejbPassivate()"); } public void setSessionContext(SessionContext ctx) { System.out.println("setSessionContext()"); } public String SayHello() { return "Hello, World!"; } Call Back Methods Business Method Bean Name Bean type

Bean Class  In this code, we have only one business method called “SayHello”.  This method displays a message “Hello World”. When developing enterprise beans, we follow a naming convention that states that the name of the bean class must contain an application-specific name followed by the word “Bean”.  Here, the bean is called “HelloBean”.  Notice the statement “HelloBean implements SessionBean”. This merely indicates that we are creating a session bean and doesn’t provide any information on the type of session bean.  This information is configured externally. Also, notice that in addition to the business method, the bean also contains several other methods called container call-back methods. These methods are defined in the session bean interface.

Coding Example  Component Interface package mypack.Hello; import javax.ejb.*; import java.rmi.RemoteException; import java.rmi.Remote; public interface Hello extends EJBObject{ public String SayHello() throws RemoteException; }

Component Interface  This interface extends from a base interface called EJBObject. The methods in the component interface expose the business methods inside a bean. This base interface inherits from java.rmi.Remote. Hence, the component interface, Hello, also inherits from java.rmi.Remote. Therefore, methods in the component interface are remote methods and so throw RemoteException. The container creates a class that implements the methods in the component interface and its stub. It should also implement the methods as defined in EJBObject.  While defining a component interface, you need to follow some rules. Component interface should extend from EJBObject All business methods declared in component interface should throw RemoteException All the arguments passed and return values of these business methods must be RMI-IIOP compatible

Coding Example  Home Interface package mypack.Hello; import javax.ejb.*; import java.rmi.RemoteException; public interface HelloHome extends EJBHome { Hello create() throws RemoteException, CreateException; }

Home Interface  The home interface is the entry point for the client to gain access to the EJBObject that represents the actual EJB. In this sample code, we have a home interface called HelloHome. The code defines a single method named create(). This method returns a reference of type component interface i.e. EJBObject. This method is executed by an instance of a class automatically generated by the container from the home interface of your application. The object is called EJBHome object. The EJBHome object serves as a factory to generate EJBObjects for the requesting clients. There is just one instance of type EJBHome created by a container corresponding to an EJB. This single home object instance is accessed by all clients of that EJB.  The home interface is also responsible for the lifecycle management of beans. When a client requests for a bean, the EJBHome object instantiates the bean. When the client request is serviced and wants to remove the bean, the EJBHome object removes the bean from the container.

package mypack.Hello; import javax.ejb.*; import javax.naming.*; import java.rmi.*; import java.util.Properties; public class HelloClient { public static void main(String[] args) { try { /* Get System properties for JNDI initialization */ Context ictx=new InitialContext(); Object objref=ictx.lookup(“java:comp/env/ejb/HelloTeller”); HelloHome home= (HelloHome) PortableRemoteObject.narrow(objref,HelloHome.class); Hello helloref = home.create(); System.out.println(helloref.SayHello()); helloref.remove(); } catch (Exception e) {e.printStackTrace();} } EJB Client

 The code is a simple Java application called HelloClient.  A new instance of InitialContext has been created to search (lookup) for a Home object.  Next line of code looks for the location of the home object.  Notice that the initial context begins “java:comp/env/”, which is the initial context for JNDI.  In the code, ejb is the subcontext under the initial context, where all the ejb references are stored and HelloTeller is the nick name of bean. The object that we look for is stored in a variable called objref, which is of the datatype Object.  Object is a super class of any class in Java. Any object or application written in Java is a child of a super parent called Java. Next, the generic datatype is narrowed to a more specific datatype by using an API in Java called reflection.  This API takes two parameters, source and destination, which are object and hellohome respectively.  This is then typecased to hellohome. Then, the create method in the home object is executed and the value is returned/stored in a component object, helloref. helloref is of the datatype hello, which in turn is the datatype of the component interface.  The return value is printed on the console. Finally, the object helloref is eliminated using the remove method.

 The client views the container that contains the home object and remote object.  Client view consist of the following Container Home Object Remote Object Client’s View (1 of 2)