EJB. Component Characteristics An enterprise Bean typically contains business logic that operates on the enterprise’s data. An enterprise Bean’s instances.

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.
EJB Entity Beans. Entity Beans Data versus logic Used to represent an instance rather than a collection of data (depending on underlying storage) Represents.
Approaches to EJB Replication. Overview J2EE architecture –EJB, components, services Replication –Clustering, container, application Conclusions –Advantages.
June 1999 EJB1 EJB and CHAIMS Dorothea Beringer Enterprise Java Beans and how to build a CHAIMS infrastructure using the EJB paradigm.
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.
Java 2 Platform, Enterprise Edition (J2EE). Source: Computer, August 2000 J2EE and Other Java 2 Platform Editions.
J2EE Kenneth M. Anderson CSCI Web Technologies October 3, 2001.
CS 483 Enterprise and Web Application Programming
Chapter 10 EJB Concepts of EJB Three Components in Creating an EJB Starting/Stopping J2EE Server and Deployment Tool Installation and Configuration of.
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.
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)
Entity Beans BMP Celsina Bignoli
Advanced Java Session 7 New York University School of Continuing and Professional Studies.
Entity Java Beans Jorg Janke Open Source ERP & CRM.
Enterprise Java Beans Part I Kyungmin Cho 2001/04/10.
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.
Replication & EJB Graham Morgan. EJB goals Ease development of applications –Hide low-level details such as transactions. Provide framework defining the.
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.
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.
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 -) 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.
J2EE Overview ver 1.0Page 1 © Wipro Technologies Talent Transformation J2EE Overview.
Enterprise JavaBeans Understanding EJB Components Version 0.1 Kamal Wickramanayake
© 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.
Entity Beans & Persistence Chris Alexander CS 486 Spring 2001.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
Enterprise Java Bean Technology Briefing Markus Hebach.
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.
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 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.
©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
Distribution and components
Introduction to J2EE Architecture
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
Understanding and Designing with EJB
Enterprise Java Beans Bina Ramamurthy 4/5/2019 B.Ramamurthy.
Enterprise Java Beans.
Introduction to Session beans
Knowledge Byte In this section, you will learn about:
Objectives In this lesson, you will learn about:
Presentation transcript:

EJB

Component Characteristics An enterprise Bean typically contains business logic that operates on the enterprise’s data. An enterprise Bean’s instances are created and managed at runtime by a Container. An enterprise Bean can be customized at deployment time by editing its environment entries.

Components Various metadata, such as a transaction and security attributes, are separate from the enterprise Bean class. This allows the metadata to be managed by tools during application assembly or deployment (or both). Client access is mediated by the Container in which the enterprise Bean is deployed.

Components An enterprise Bean can be included in an assembled application without requiring source code changes or recompilation of the enterprise Bean. A client view of an enterprise Bean is defined by the Bean Provider. The client view can be manually defined by the Bean developer, or generated automatically by application development tools. The client view is unaffected by the container and server in which the Bean is deployed. This ensures that both the Beans and their clients can be deployed in multiple execution environments without changes or recompilation.

EJB use Tier 1: Client Tier 2: EJB server –EJB container (provides transaction management, security, remote connectivity, concurrency, life cycle management) Enterprise beans Tier 3: Databases, legacy code

Session beans Model business processes such as checking, canceling, shipping orders. Run by code on a remote client: locates bean through JNDI (Java Naming and Directory Interface) EJB container creates copy of session bean on client

Session Beans Four pieces of code you need to write –remote interface: methods client can use –home interface: used to create remote copy –session bean: does most of the work –client code that calls the bean

Remote Interface public interface Hello extends EJBObject { String sayHello() throws RemoteException; Client will call only one method Follow RMI rules: must throw RemoteException, return types primitive or...

Home Interface public interface HelloHome extends EJBHome { Hello create(String str) throws RemoteException, …; }

Session Bean Implementation public class HelloEJB implements SessionBean { String str; public ejbCreate(String str) {this.str = str; } public String sayHello() throws RemoteException {return str;}…}

Session bean Also: ejbRemove(), ejbActivate(), ejbPassivate() ejbCreate corresponds to create method in home interface

Client: main method Context ic = new InitialContext(); Object obj = ic.lookup(“helloapp/Hello”); HelloHome hhome = (HelloHome) PortableRemoteObject.narrow (obj, HelloHome.class);

Client: main method Hello hobj = hhome.create(“Hello World”); String hstr = hobj.sayHello(); System.out.println(hstr);

Entity Beans Persistent: can be container managed using deployment descriptor container also provides transaction management –Remote interface –Home interface –Entity bean class

Example Tier 1: WebBrowser: Applet Tier 2: –WebServer: Servlet –EJB Server EJB Container –Product Entity Bean –Order Entity Bean –Customer Entity Bean Tier 3: Data Base Server

Entity Bean Class business methods create methods remove methods finder methods load and store methods activation, passivation methods

EJB Session beans –represents a client in the server. Client calls methods (e.g., enterOrder). Is transient: terminates when client terminates. Entity beans –represents a business object (persistent). –Persistence can be beans or container managed

Enterprise Java Beans (EJB) and Aspectual components EJB: a hot Java component technology from SUN/IBM Aspectual components: a conceptual tool for the design of enterprise Java beans (and other components)

Enterprise JavaBeans (EJB) Addresses aspectual decomposition. An enterprise Bean provider usually does not program transactions, concurrency, security, distribution and other services into the enterprise Beans. An enterprise Bean provider relies on an EJB container provider for these services.

EJB Beans Containers: to manage and adapt the beans. Intercept messages sent to beans and can execute additional code. Similar to reimplementation of expected interface in aspectual component.

Aspectual components for EJB design/implementation Use ACs to model transactions, concurrency, security, distribution and other system level issues. Translate ACs to deployment descriptors (manually, or by tool). Use ACs to model beans in reusable form. Generate (manually or by tool) Java classes from ACs and connectors.

Example: Use AC for EJB persistence As an example we consider how persistence is handled by EJB containers. The deployment descriptor of a bean contains an instance variable ContainerManagedFields defining the instance variables that need to be read or written. This will be used to generate the database access code automatically and protects the bean from database specific code.

Aspectual component: Persistence component Persistence { PerMem p; participant Source { expect Target[] targets; expect void writeOp();} // for all targets:writeOp participant Target expect void writeOp(); replace void writeOp() { // write to persistent memory p expected();}}

Deployment connector PersistenceConn1 { ClassGraph g = ; // from Company to * Company is Persistence.Source; Nodes(g) is Persistence.Target; with {writeOp = write*}; // must be the same writeOp for both // Source and Target }

Generate deployment descriptor Connector contains information about ContainerManagedFields Connector localizes information; it is not spread through several classes

Discussion of session bean and entity bean distinction interesting modeling is done in session beans; initially only session beans entity beans: dumb objects? Enterprise beans components are intended to be relatively coarse-grained business objects (e.g. purchase order, employee record). Fine-grained objects (e.g. line item on a purchase order, employee’s address) should not be modeled as enterprise bean components.

Ejb and aop deployment descriptors :=: APPC session beans :=: “session” APPC –session beans are extensions of clients entity beans :=: “base” participants –key participants regular classes :=: define through APPC

Terminology Building block = BB Participants (classes at basic level) = BB of type 1 APPC = BB of type 2 = consisting of set of generic BB of type 1. Connectors = map generic BB

AOP components = building blocks type 1 whatever does not fit into one building block of type 1 is expressed as one building block type 2 that consists of a set of generic building blocks of type 1. generic building blocks of a building block of type 2 are mapped to building blocks of type 1.

Generic BB A building block with holes

AOP Properties of mapping –one generic building block is mapped to one or more building blocks –building blocks may have parts. One part of generic building block is mapped to one or more parts of corresponding generic building block.

Exceptions in EJB An application exception is an exception defined in the throws clause of a method of the enterprise Bean’s home and remote interface, other than the java.rmi.RemoteException. An enterprise bean business method may encounter various system exceptions or errors that prevent the method from successful completion.

Examples Application exception: account has insufficient balance System exception: failure to obtain a database connection, JNDI exceptions, unexpected RemoteException from invocation of other enterprise beans, unexpected RuntimeException, JVM errors, etc.

Use of application level exceptions Application exceptions are intended to be handled by the client, and not by the system administrator. They should be used only for reporting business logic exceptions, not for reporting system level problems.

Application exception Because an application exception does not automatically result in marking the transaction for rollback, the Bean Provider must do one of the following to ensure data integrity before throwing an application exception from an enterprise bean instance: –no loss of data integrity –mark for rollback before throwing application exception, prevents commit

System exception guidelines If the bean method encounters a RuntimeException or error, it should simply propagate the error from the bean method to the Container (i.e. the bean method does not have to catchthe exception). Any other unexpected error conditions should be reported using the javax.ejb.EJBException.

What the container does catches a non-application exception, logs it (which can result in alerting the System Administrator), and throws the java.rmi.RemoteException (or subclass thereof) to the client.

What container does The Bean Provider can rely on the Container to perform to following tasks when catching a non-application exception: –The transaction in which the bean method participated will be rolled back. –No other method will be invoked on an instance that threw a non-application exception.

What container does This means that the Bean Provider does not have to perform any cleanup actions before throwing a non-application exception. It is the Container that is responsible for the cleanup.

AOP and Law of Demeter ? Only talk to friends