Enterprise Java Beans II CS-422 Steflik. EJB Development The EJB Specification define six roles that are involved in the development and deployment of.

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.
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 Adam, Engels, Josh, Marc, Tim.
J2EE Security and Enterprise Java Beans Mrunal G. Dhond Department of Computing and Information Sciences Master of Science, Final Defense February 26,
SEI/CBS Initiative Software Engineering Institute Carnegie Mellon University Pittsburgh, PA Sponsored by the U.S. Department of Defense © 1999.
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.
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.
Lecture 8 Advanced Topics in Enterprise JavaBeans.
Advanced Java Session 7 New York University School of Continuing and Professional Studies.
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.
Enterprise Java Beans Part II Kyungmin Cho 2001/04/13.
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.
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.
J2EE Structure & Definitions Catie Welsh CSE 432
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
© 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.
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.
Enterprise Java Beans Ye Zhou CS6704 Presentation Virginia Tech.
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.
Java Object-Relational Layer Sharon Diskin GUS 3.0 Workshop June 18-21, 2002.
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
EJB Architecture and Design
Introduction to J2EE Architecture
Ruslana Svidzinska CSE690
Structure of Enterprise Java Beans
J2EE Application Development
Objectives In this lesson, you will learn to:
Enterprise Java Beans Bina Ramamurthy 1/13/2019 B.Ramamurthy.
Knowledge Byte In this section, you will learn about:
Introduction to Web Services
Understanding and Designing with EJB
Enterprise Java Beans Bina Ramamurthy 4/5/2019 B.Ramamurthy.
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:

Enterprise Java Beans II CS-422 Steflik

EJB Development The EJB Specification define six roles that are involved in the development and deployment of EJB applications –Enterprise Bean Provider –Application Assembler –Deployer –System Administrator –EJB Server Provider –EJB Container Provider

Enterprise Bean Provider A programmer type, who codes the EJB functions done by the Enterprise Bean Provider –write a home interface for the bean –write a component interface for the bean that declares various methods required by the application –write an implementation class that implements the various business methods declared in the remote interface –write a deployment descriptor describing the resources required by the bean and various other parameters –Package the interfaces and implementation class along with the deployment descriptor into an EJB JAR file

Application Assembler A person with the domain knowledge and expertise to be able to gather together the beans written by several Bean Providers (including vendors) and by modifying the deployment descriptors assemble them into an applications that will represent a complete business solution. This assembly activity is usually done via GUI based tools provided by the application server OEM. The assembler should be able to understand the various interfaces declared by the Bean Providers Into pulling together the various Beans the assembler will allso collect together other components, such as JSP, HTML and graphics files.

The Deployer The deployer takes an assembled application and deployes it to a specific environment the deployer need to have the detail knowledge required for the specific EJB server to be used and be familiar with the development procedures for that server the deployer must map the resources required for the application onto the current infrastructure (map data sources on the data bases…) the deployer is also responsible for mapping security requirements onto the infrastructure (creating userids, password, user groups…)

System Administrator The System Administrator is responsible for the overall operational well being of the installation –Insure the availability of the application at all times –Configure and administer the entire installation –Support the networking infrastructure at the installation –Create groups and users for the system to be used by the deployer while deploying the application –Monitor the application performance using tools provided by the server provider –Fine-tune the use of various resources required by the application

EJB Server Provider A system level expert with expertise in providing low-level support services for distributed object applications and distributed transaction management. Typically an OS vendor or middleware vendor can be assumed thast the same party plays the role of the EJB Container Provider

EJB Container Provider A system level expert that implements a secure, transaction enabled, and scaleable container that can be integrated with an EJB Server. The container provider is responsible for: –run-time environment for the deployed EJBs –deployment Tool for deploying EJBs on the container

Developing an Enterprise Bean At it simplest an EJB consists of four elements: –a home interface –a component interface –a bean implementation class –a deployment descripter we’ll develop a simple bean that calculates our monthly net salarybased on annual salary,pension contributions and income tax. –It will be a stateless session bean

Developing the Home Interface The Home Interface is responsible for managing the life-cycle operations upon a bean; creating, removing and locating the bean. The Home interface is the first point of contact that a client has with a bean A client will obtain a reference to the the bean’s Home Interface via JNDI. You will see that each bean is registered in a JNDI server that can be used at run-time to get a reference to the bean’s Home Interface Once a client has a reference to the bean’s home interface it can perform operations on the bean through this interface: these operations are: –create a new instance or find an existing instance (local and remote) –access the EJBMetaData interface (remote only) –get a serializable reference to a bean instance (remote only) –remove the bean instance –execute home business methods (remote entity beans only)

Basic EJBHomeInterface package javax.ejb; import java.rmi.Remote; import java.rmi.RemoteExecption; public interface EJBHome extends Remote { // get a reference to the EJBMetaData object; can later be used to retrieve data about the bean public abstract EJBMetaData getEJBMetaData( ) throws RemoteExecption; // get a Handle to the home object; basically a persistent reference to the object public abstract HomeHandle getHomeHandle( ) throws RemoteExecption; // remove the bean instance ; in the case of en entity bean this is like deleting a row from the data store public abstract void remove (Object obj) throws RemoteExecption, RemoveExecption; public abstract void remove (Handle handle) throws RemoteExecption, RemoveExecption; }

Basic EJBLocalHome Interface package javax.ejb; public interface EJBLocalHome { public abstract void remove (Object obj ) throws RemoveException, EJBException; }

the SalaryHome Interface package simpleBean; public interface SalaryHome extends javax.ejb.EJBHome{ Salary create() throws java.rmi.RemoteException, javax.ejb.CreateException; }

the Component Interface package javax.ejb; import java.rmi.Remote; import java.rmi.RemoteException; public interface EJBObject extends Remote { // get a referenct to the home object public abstract EJBHome getEJBHome( ) throws RemoteException; // get a Handle to the home object public abstract Handle getHandle( ) throws RemoteException; // for entity beans: get the beans Primary Key public abstract Object getPrimaryKey( ) throws RemoteException; public abstract boolean isIdentical (EJBObject ejbobject) throws RemoteException; public abstract void remove( ) throws RemoteException, RemoveException; }

the Salary Interface package simpleBean; public interface Salary extends javax.ejb.EJBObject { double calculateSalary ( int annualSalary, int pensionContrib, double bonus) throws hava.rmi.RemoteException; }

SalaryEJB Implementation package simpleBean; import javax.ejb.*; public class SalaryEJB implements SessionBean { public void ejbCreate( ) { } public void ejbRemove( ) { } public void ejbActivate( ) { } public void ejbPassivate( ) { } public void Ct( SessionContext ctx ) { } private static double taxRate = 28; public double calculateSalary (int annualSalary, int pensionContrib, double bonus) { double monthly = 0; monthly = annualSalary/12; monthly - monthlu - (monthly * (pensionContrib/100)); monthly = monthly - (monthly * (taxrate/100)); return monthly; } }

Limitations to the EJB Model Bean must not use read/write static fields bean can’t use threads or the Threading API bean can’t use AWT for input or output bean cannot act as a network server, by listening,accepting or multicasting on a socket bean cannot use java.io package bean can’t load a native driver bean can’t use “this” as an argument or return value bean can’t modify the class loader, stop the JVM, or change the input, output or error streams bean can’t access or modify security settings bean must not attempt to define a class in a package bean must not use the subclass and object substitution features of the serialization protocol

EJB Context In the SalaryBean implementation we had to invoke setSessionContext –there are similar methods required for other bean types ex. setEntityContext for Entity Beans –each of these methods accepts a subclass of an EJBContext to provide the bean instance with information about the container - the bean’s context –The EJBContext interface: package javax.ejb; import java.security.Identity; import java.security.Principle; import java.util.Properties; import javax.transaction,UserTransaction; public interface EJBContext { public abstract Identy getCallerIdentity( ); public abstract Principal getCallerPrincipal( ); public abstract EJBHome getEJBHome( ); public abstract Properties getEnvironment( ); public abstract boolean getRollbackOnly( ) throws IllegalStateException public abstract UserTransaction getUserTransaction( ) throws IllegalStateException; public abstract boolean isCallInRole( String s); public abstract boolean isCallerInRole (Identity identity); public abstract void setRollbackOnly( ) throws IllegalStateException }

EJBContext Interface Additionally SessionContext and EntityContext (but not MessageDrivenContext) define: public abstract EJBLocalObject getEJBLocalObject( ) throws IllegalStateException; public abstract EJBObject getEJBObject( ) throws IllegalStateException;

Deployment Descriptors In the original EJB Specification the deployment descriptor was written as a Java object, in the EJB 1.1 Specification that was changed to be an XML Document. DTD ElementOptionalPurpose the root element of the deployment descriptor, all other elements are children of this Yestextual description of the parent element, many other elements can have their own description elements Yesa name that the deployment tool can use to display the name Yesrelative path to a small (16x16) jpeg or GIF to be used by deployment tools Yes relative path to a large (32x32) jpeg or GIF to be used by deployment tools The parent element that contains the declarations for all beans within this application Yesthe parent element that contains application assembly instructions for the EJB application (includes; transaction attributes, method permissions, security roles and excluded methods) Yesa JAR file that contains the classes necessary for a client to access the bean

An EJB Deployment Descriptor <!DOCTYPE ejb-jar PUBLIC --//Sun Microsystems, Inc // DTD Enterprise JavaBeans 1.1//EN’ ‘ Single stateless bean to calculate Monthly Salary Simple Bean Simple Salary Bean</description Salary Bean Salary simpleBean.SalaryHome simpleBean.Salary simpleBean.SalaryEJB Stateless Container

A Salary Client import javax.ejb.*; import simpleBean.* import javax.naming.InitialContext; class SalaryClient { public static void main (String[ ] args) { try { InitialContext ctx = new InitialContext( ); Object objRef = ctx.lookup(“Salary”); SalaryHome home = (SalaryHome) javax.rmi.PortableRemoteObject.narrow(objRef, SalaryHome.class); Salary bean = home.create( ); System.out.println ( “Monthly net salary = “ + bean.calculateSalary(28000, 2, 500)); } catch (javax.namingException ne) { System.out.println(“ naming exception caught”) } catch (javax.ejb.CreateException) { System.out.println(“ EJC Ceration Exception caught); } catch (java.rmi.RemoteExecption) { System.out.println(“rmi RemoteExceprion caught”); } }

Entity Beans ( ver 1.1) Entity beans represent data in a datastore as a Java object, this usually means that the bean represents a row in a relational table. Since the bean and the database record are synonymous, any change in the bean must be synchronized with the database record; this is called persistence there are two types of Entity beans, they are differentiated by how they handle persistence –Container-Managed Persistence (CMP) the synchronization (persistence) is handled automatically by the container –Bean-Managed Persistence (BMP) we manage the synchronization (persistence) in code in the bean and tell the container to keep its hands off

CMP or BMP One of the services offered by the EJB container is to have the container manage the persistence, at deployment time the container will generate all of the code needed to synchronize the bean with the database. –This lets the programmer focus on business logic and not have to be concerned over persistance –by using CMP the bean becomes more independent of the database, this can make them easier to re-deploy using another database With BMP we must provide all of the SQL to manage the persistence as part of the bean, its more work but some EJB containers are not fully compliant with the EJB specification as relates to CMP; so, the only option may be to use BMP. –This may be only option when trying to use legacy databases (IBM/IMS) that are not SQL oriented –to get finer graind control than what CMP provides

Primary Keys The identity of an entity bean is its primary key primary key is represented by a primary key class that is defined by the developer, this class contains everthing necessary to find the entity in the datastore for BMP the primary key class must –the primary key can be any legal value type in RMI/IIOP, must be serializable –must provide suitable implementations of the hashCode( ) and equals( ) methods –must have a unique value within the set of all beans of a particular type for CMP these additional rules apply –key class must have a no-arguments public constructor –must be able to map the beans state to the primary key and vice-versa