14 Copyright © 2004, Oracle. All rights reserved. Achieving State Management in the Business Tier.

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.
15 Copyright © 2005, Oracle. All rights reserved. Container-Managed Relationships (CMRs)
Technische universität dortmund Service Computing Service Computing Prof. Dr. Ramin Yahyapour IT & Medien Centrum 12. November 2009.
EJB Entity Beans. Entity Beans Data versus logic Used to represent an instance rather than a collection of data (depending on underlying storage) Represents.
Development and Deployment Roles Venugopal Pakanati.
Container Managed Persistence. General Guidelines Home and Remote interfaces are implemented the same as for bean managed persistence Entity Bean class.
Writing Enterprise Applications with J2EE (Third lesson) Alessio Bechini June 2002 (based on material by Monica Pawlan)
J2EE Security and Enterprise Java Beans Mrunal G. Dhond Department of Computing and Information Sciences Master of Science, Final Defense February 26,
Organizational Communication Technologies 1 Enterprise Java Beans Detail.
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.
15 - RMI/EJBCSC4071 Distributed Objects Java Remote Method Invocation Enterprise Java Beans.
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)
Distributed Object-Oriented Programming (3) – Enterprise JavaBeans SNU iDB Lab. Taewhi Lee May 14th, 2007.
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.
Distributed Systems 1 Master of Information System Management Distributed Systems Persistence.
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.
EJB Framework.  As we know, EJB is the center of the J2EE architecture that provides a sturdy framework for building enterprise applications. The major.
Enterprise Java Bean Computer Networks Natawut Nupairoj, Ph.D. Department of Computer Engineering Chulalongkorn University.
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.
© jGuru.com Enterprise JavaBeans Fundamentals.
Creating competitive advantage Copyright © 2003 Enterprise Java Beans Presenter: Wickramanayake HMKSK Version:0.1 Last Updated:
 2002 Prentice Hall. All rights reserved. Chapter 19 Enterprise Java Case Study: Business Logic Part 1 Outline 19.1 Introduction 19.2 EJB Architecture.
EJB Overview: Constraint Types and Enforcement in JBoss Elissa Newman Fluid Meeting 6/3/04.
Entity Beans & Persistence Chris Alexander CS 486 Spring 2001.
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.
D Copyright © 2004, Oracle. All rights reserved. BMP Entity EJBs J2EE Connector Architecture.
Enterprise JavaBeans. Lesson 1: Introduction to Server-Side Component Software.
Middleware Technology (J2EE/EJB) EJB Fundamentals.
Enterprise JavaBeans™ Trademark of Sun Microsystems, Inc.
17 Copyright © 2004, Oracle. All rights reserved. Integrating J2EE Components.
JAVA & J2EE UNIT – 8 ENTERPRISE JAVA BEAN - EJB 28-Jun-16 Prepared by: SANTHIYA.M & GANGA V. C. Department: Computer Science & Engineering Course code:
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.
Entity Bean Chuyên đề Lập trình Java & J2EE Chương 15
Structure of Enterprise Java Beans
Objectives In this lesson, you will learn to:
Understanding and Designing with EJB
Enterprise Java Beans Bina Ramamurthy 1/13/2019 B.Ramamurthy.
Entity Beans B.Ramamurthy 2/17/2019 BR.
Knowledge Byte In this section, you will learn about:
Understanding and Designing with EJB
Enterprise Java Beans Bina Ramamurthy 4/5/2019 B.Ramamurthy.
Presentation transcript:

14 Copyright © 2004, Oracle. All rights reserved. Achieving State Management in the Business Tier

14-2 Copyright © 2004, Oracle. All rights reserved. Objectives After completing this lesson, you should be able to do the following: Describe the features of bean-managed persistent (BMP) entity beans Identify the features of a container-managed persistent (CMP) entity bean Describe the benefits of a CMP bean as compared with a BMP bean Develop and deploy a CMP bean Develop a client for a CMP bean

14-3 Copyright © 2004, Oracle. All rights reserved. Features of BMP Entity Beans The Bean provider provides the code for persistence management. BMP beans provide more flexibility in managing persistent data. The bean class of a BMP entity bean contains code for data access and manipulation. Callback methods contain code to map the entity bean instance to the data, load the data, and store the data in persistent storage. BMP beans are less portable.

14-4 Copyright © 2004, Oracle. All rights reserved. Developing a BMP Entity Bean To develop a BMP entity bean, you must create the following: A remote interface for the bean A home interface The primary key class The bean class implementation Support classes, such as exceptions Necessary database tables The J2EE deployment descriptor A client application to access the EJB

14-5 Copyright © 2004, Oracle. All rights reserved. Features of CMP Entity Beans Developers need not code the persistence logic in the bean because the containers provide it. CMP beans provide: –Portability across all EJB-compliant containers –A layer of data independence –Container-managed fields, which represent the persistent fields in the database Bean developers concentrate on the business logic and provide empty implementations of the callback methods.

14-6 Copyright © 2004, Oracle. All rights reserved.

14-7 Copyright © 2004, Oracle. All rights reserved. Implementing Methods in CMP Beans and BMP Beans ejbStore() ejbLoad() ejbcreate() setXXX() and getXXX() ejbFind() CMPBMPMethod abstract

14-8 Copyright © 2004, Oracle. All rights reserved.

14-9 Copyright © 2004, Oracle. All rights reserved. Developing a CMP Entity Bean To develop a CMP entity bean, you must: Create a component interface Create a home interface Define a primary key for the bean Create the bean class implementation Create optional support classes such as exceptions Create the bean deployment descriptor Ensure that the correct database table exists for the bean

14-10 Copyright © 2004, Oracle. All rights reserved. CMP Bean: Example The example in this lesson creates a CMP entity bean to represent the DEPARTMENTS table with the following components: –Remote interface: Departments –Home interface: DepartmentsHome –Bean class: DepartmentsBean –Deployment descriptor: ejb-jar.xml Client for Departments bean: DepartmentsClient

14-11 Copyright © 2004, Oracle. All rights reserved. Bean Class of a CMP EJB: CMP Fields The bean class of a CMP EJB is an abstract class because it does not implement persistence logic. CMP fields in the deployment descriptor: –Correspond to columns of the persistent data table –Have names starting with a lowercase letter –Must be Java primitive types or Java serializable objects CMP field accessor methods in the bean instance: –Must be abstract public methods; the container implements these methods –Must have names in the following form: getFieldname() or setFieldname()

14-12 Copyright © 2004, Oracle. All rights reserved. Remote Interface: Departments... import javax.ejb.EJBObject; import java.rmi.RemoteException; public interface Departments extends EJBObject { // set and get methods for CMP fields Long getDepartment_id() throws RemoteException; void setDepartment_id(Long newDepartment_id) throws RemoteException; String getDepartment_name()throws RemoteException; void setDepartment_name(String newDepartment_name) throws RemoteException;... }

14-13 Copyright © 2004, Oracle. All rights reserved. Home Interface: DepartmentsHome import javax.ejb.EJBHome; import java.rmi.RemoteException; import javax.ejb.CreateException; import javax.ejb.FinderException; import java.util.Collection; public interface DepartmentsHome extends EJBHome { Departments create() throws RemoteException, CreateException; Departments findByPrimaryKey(Long primaryKey) throws RemoteException, FinderException; Collection findAll() throws RemoteException, FinderException; Departments create(Long department_id, String department_name) throws RemoteException, CreateException; }

14-14 Copyright © 2004, Oracle. All rights reserved. Bean Class: DepartmentsBean... import javax.ejb.EntityBean; import javax.ejb.EntityContext; public abstract class DepartmentsBean implements EntityBean { private EntityContext context; public void setEntityContext(EntityContext ctx) { context = ctx; } public void unsetEntityContext() { context = null; } public abstract Long getDepartment_id(); public abstract void setDepartment_id(Long newDepartment_id);...

14-15 Copyright © 2004, Oracle. All rights reserved. Bean Class: DepartmentsBean... public Long ejbCreate() { return null; } public void ejbPostCreate() { } public Long ejbCreate(Long department_id, String department_name) { setDepartment_id(department_id); setDepartment_name(department_name); return department_id; } public void ejbPostCreate(Long department_id, String department_name) { }...

14-16 Copyright © 2004, Oracle. All rights reserved. Bean Class: DepartmentsBean... public void ejbActivate() { } public void ejbLoad() { } public void ejbPassivate() { } public void ejbRemove() { } public void ejbStore() { } }

14-17 Copyright © 2004, Oracle. All rights reserved. Deployment Descriptor ejb-jar.xml The main tags of the deployment descriptor for a CMP bean are: : Type of primary key : Container : CMP 1.1 or 2.0 (default) : For each entity bean : List of CMP field names

14-18 Copyright © 2004, Oracle. All rights reserved.

14-19 Copyright © 2004, Oracle. All rights reserved. Deployment Descriptor ejb-jar.xml... Entity Bean ( CMP ) Departments mypackage1.DepartmentsHome mypackage1.Departments mypackage1.impl.DepartmentsBean Container java.lang.Long False 2.x...

14-20 Copyright © 2004, Oracle. All rights reserved. Deployment Descriptor ejb-jar.xml department_id department_name manager_id location_id department_id

14-21 Copyright © 2004, Oracle. All rights reserved. Mapping CMP Fields to Database Table Columns Accept the defaults that are supplied by the container. Map explicitly to the columns in a database table by using the orion-ejb-jar.xml file: –Deploy the application by using only ejb-jar.xml –Modify the generated orion-ejb-jar.xml file with the custom database, table, and column details –Use for more complex data representation of a bean JDeveloper provides easy mapping of the persistent fields to database tables.

14-22 Copyright © 2004, Oracle. All rights reserved. Default Mapping of CMP Fields to Database Table Columns Database: Default database as specified in the data-sources.xml file, which can be customized Table: Default table is created by a container with a unique name that combines the following: –EJB name defined in the deployment descriptor –JAR file name including.jar extension –Application name defined during deployment –An underscore and five-character hash code –Example: DeptBean_dept_jar_dept_xxxxx Column: With the same name as the CMP fields defined in the deployment descriptor; Java data types are translated to database data types in oracle.xml

14-23 Copyright © 2004, Oracle. All rights reserved. Explicit Mapping of CMP Fields to Database Table Columns...

14-24 Copyright © 2004, Oracle. All rights reserved.

14-25 Copyright © 2004, Oracle. All rights reserved. Client for Departments Bean import java.util.Hashtable; import javax.naming.Context; import javax.naming.InitialContext; import javax.rmi.PortableRemoteObject;... public class DepartmentsClient { public static void main(String [] args) { DepartmentsClient departmentsClient = new DepartmentsClient(); try { Context context = getInitialContext(); DepartmentsHome departmentsHome = (DepartmentsHome)PortableRemoteObject.narrow (context.lookup("Departments"), DepartmentsHome.class); Departments departments;...

14-26 Copyright © 2004, Oracle. All rights reserved. Client for Departments Bean System.out.println(" CREATING A NEW DEPARTMENT WITH ID ") ; departments =departmentsHome.create(new Long(404), "Security"); System.out.println(" SUCCESSFUL "); System.out.println("Get the DEPARTMENT_NAME " + departments.getDepartment_name()); System.out.println("Changing the DEPARTMENT_NAME to Security Services " ); departments.setDepartment_name("Security Services"); System.out.println("PRINTING THE DEPARTMENT_ID AND DEPARTMENT_NAME"); System.out.println(departments.getDepartment_id() + " " + departments.getDepartment_name());...

14-27 Copyright © 2004, Oracle. All rights reserved. Client for Departments Bean // Retrieve all instances using the findAll() method Collection coll = departmentsHome.findAll(); Iterator iter = coll.iterator(); while (iter.hasNext()) { departments = (Departments)iter.next(); System.out.println("department_id = " + departments.getDepartment_id()); System.out.println("department_name = " + departments.getDepartment_name()); System.out.println("manager_id = " + departments.getManager_id()); System.out.println("location_id = " + departments.getLocation_id()); System.out.println(); } } catch(Throwable ex) {...

14-28 Copyright © 2004, Oracle. All rights reserved. Summary In this lesson, you should have learned how to: Describe the features of a BMP entity bean List the components that have to be created to develop a BMP bean Describe the features of a CMP entity bean List the steps in developing a CMP bean Develop and deploy a CMP bean Develop a client for CMP EJB

14-29 Copyright © 2004, Oracle. All rights reserved. Practice 14-1: Overview This practice covers the following topics: Developing a CMP entity bean to represent and update the EMPLOYEES table Creating a remote interface, and a home interface for a CMP entity bean by using Oracle JDeveloper 10g Implementing the create() methods, callback methods, and methods of the remote interface in the entity bean class Testing the entity bean with a client application

14-30 Copyright © 2004, Oracle. All rights reserved.

14-31 Copyright © 2004, Oracle. All rights reserved.

14-32 Copyright © 2004, Oracle. All rights reserved.