13 Copyright © 2004, Oracle. All rights reserved. Managing Persistent Data in the Business Tier Entity EJBs.

Slides:



Advertisements
Similar presentations
J0 1 Marco Ronchetti - Basi di Dati Web e Distribuite – Laurea Specialistica in Informatica – Università di Trento.
Advertisements

12 Copyright © 2005, Oracle. All rights reserved. Implementing Business Tasks with Session EJBs.
11 Copyright © 2005, Oracle. All rights reserved. Creating the Business Tier: Enterprise JavaBeans.
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.
6/1/20151 Luca Simone Software Engineering 2 a.a. 2001/2002.
1 Softsmith Open Learning - EJB 21-Nov Enterprise Java Beans Introduction –Application ServerApplication Server –Java 2 Enterprise EditionJava.
Overview of The Java Platform Solution for E-Business Applications : JSP, Servlet and EJB.
Copyright W. Howden1 Lecture 19: Intro to O/O Components.
J2EE Kenneth M. Anderson CSCI Web Technologies October 3, 2001.
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 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.
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.
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.
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.
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.
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.
©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.
Advanced Java Session 7 New York University School of Continuing and Professional Studies.
Enterprise JavaBeans™ Trademark of Sun Microsystems, Inc.
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.
Enterprise Java Beans Overview
Entity Bean Chuyên đề Lập trình Java & J2EE Chương 15
Structure of Enterprise Java Beans
Luca Simone Software Engineering 2 a.a. 2001/2002
Objectives In this lesson, you will learn to:
EJB Types Alessio Bechini June 2002.
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.
Knowledge Byte In this section, you will learn about:
Presentation transcript:

13 Copyright © 2004, Oracle. All rights reserved. Managing Persistent Data in the Business Tier Entity EJBs

13-2 Copyright © 2004, Oracle. All rights reserved. Objectives After completing this lesson, you should be able to do the following: Identify the features of an entity bean Distinguish between session beans and entity beans Decide when to use an entity bean Describe the various components of an entity bean Differentiate bean-managed persistent beans from container-managed persistent beans

13-3 Copyright © 2004, Oracle. All rights reserved. Entity Beans Are objects that can be stored in permanent storage Represent persistent data in the database Can be uniquely identified Do not contain complex business logic Do not model business processes but manage data for such processes Can serve multiple clients simultaneously

13-4 Copyright © 2004, Oracle. All rights reserved.

13-5 Copyright © 2004, Oracle. All rights reserved. Representing Data in Entity Beans Table Entity bean object int x String s float f int y double d

13-6 Copyright © 2004, Oracle. All rights reserved. When to Use Entity Beans You can use an entity bean in the following situations: To represent a business entity When the state of the bean must be persistent When you need to represent a relationship between entities

13-7 Copyright © 2004, Oracle. All rights reserved. Callback Methods to Load and Store Data ejbLoad() loads the data from the persistent storage to the bean. ejbStore() saves the data from the bean instance to the persistent storage.

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

13-9 Copyright © 2004, Oracle. All rights reserved. Session Beans Versus Entity Beans Session Beans: Are represented by verbs because they model workflow Are short-lived and have a lifetime of a client session Manage their state, but do not contain callback methods to manage data because they do not represent data in the persistent storage Entity Beans: Are represented by nouns because they model business data Are long-lived and do not depend on a client’s session Contain callback methods for managing data (create, retrieve, persist, and so on) in the persistent storage

13-10 Copyright © 2004, Oracle. All rights reserved.

13-11 Copyright © 2004, Oracle. All rights reserved. Types of Entity Beans Container-managed persistent (CMP) beans: The container provides the logic to search and manipulate the persistent data. Bean-managed persistent (BMP) beans: The bean provider codes the logic to search and manipulate the persistent data in the callback methods.

13-12 Copyright © 2004, Oracle. All rights reserved. BMP Beans Versus CMP Beans BMP beans: –Contain code for managing data persistence –Provide flexibility for bean developers to manage state –Are complicated to program CMP beans: –Do not contain code for managing persistence because the container manages the persistence –Use abstract persistence schema and define the data retrieval/manipulation logic in the deployment descriptor –Are easier to program and contain lesser code

13-13 Copyright © 2004, Oracle. All rights reserved.

13-14 Copyright © 2004, Oracle. All rights reserved. Components of an Entity Bean Home interface: Is used by clients to create, find, and destroy EJB objects Component interface: Contains the declaration of all business methods in the bean class that can be invoked by the client Bean class: Represents persistent data and contains methods to access or manipulate that data Primary key class: Is used to uniquely identify an entity bean instance Deployment descriptor: Contains information that is used by the container

13-15 Copyright © 2004, Oracle. All rights reserved. Creating, Removing, Finding, and Selecting Entity Beans ejbCreate() : Initializes the entity bean in memory. This method may also insert the corresponding data into the persistent storage. ejbRemove() : Removes the database data but does not remove the in-memory entity bean instance. The instance may return to the pool and release all resources in the ejbPassivate() method. Finder methods: Used to find an entity bean. Selector methods: Used to select entity beans and values of CMP fields.

13-16 Copyright © 2004, Oracle. All rights reserved.

13-17 Copyright © 2004, Oracle. All rights reserved. Home Interface of an Entity Bean Remote home interface: –Extends the javax.ejb.EJBHome interface –Can be accessed by remote clients by using Java Naming and Directory Interface (JNDI) –Allows client to create handles for later reference Local home interface: –Extends the javax.ejb.EJBLocalHome interface –Can be accessed by local clients Remote/local home interface: –Contains methods to create, find, or remove entity objects –Contains business methods that are not applicable to a specific instance (home methods)

13-18 Copyright © 2004, Oracle. All rights reserved. Creating a Bean Instance An entity bean can have one or more create() methods, or none defined in its home interface. The create() method: –Enables a client to create a row in the database table that corresponds to the entity bean –Contains parameters that initialize the state of the created entity object –Returns the remote/local interface reference of the entity beans –Throws CreateException and any user-defined exceptions –Throws RemoteException if it is part of a remote home interface

13-19 Copyright © 2004, Oracle. All rights reserved.

13-20 Copyright © 2004, Oracle. All rights reserved. Finding an Entity Bean Instance An entity bean: Can have one or more finder methods in home interface Must have a findByPrimaryKey(primarykey) method Has finder methods that: –Find row or rows in the database table –Contain parameters that locate the requested entity object –Return entity bean’s component interface reference or collection of objects of component interface type –Must throw FinderException –Must throw RemoteException in a remote home interface –Have find as a prefix in their names

13-21 Copyright © 2004, Oracle. All rights reserved.

13-22 Copyright © 2004, Oracle. All rights reserved. Removing an Entity Bean An entity bean with remote home interface: –Can have one or more remove() methods: remove(Handle handle) and remove(Object primarykey) –Throws RemoteException and RemoveException from remove() methods An entity bean with local home interface: –Can have one remove() method: remove(Object primarykey) –Throws RemoveException from the remove() method remove() methods remove the entity object and the row from the underlying database.

13-23 Copyright © 2004, Oracle. All rights reserved. Home Methods of Entity Beans Home methods are provided by a bean provider. Home methods contain business logic that is not specific to any bean instance. An entity bean can have one or more home methods, or none. The arguments and return types of remote home methods should be of RMI-IIOP type.

13-24 Copyright © 2004, Oracle. All rights reserved. Component Interfaces of an Entity Bean Component interfaces define: –Business methods that are accessible by clients –Accessor methods for the bean attributes Remote interfaces: –Are referenced by remote clients –Extend the javax.ejb.EJBObject interface Local interfaces: –Are referenced by local clients –Extend the javax.ejb.EJBLocalObject interface

13-25 Copyright © 2004, Oracle. All rights reserved. Primary Key Class of an Entity Bean Primary key: –Uniquely identifies each bean instance –Is used to find or remove an entity bean –Can be of any legal value type in RMI-IIOP The primary key class: –Should implement java.io.Serializable –Can have a single primary key (a single field) to identify the entity bean –Can have composite keys (multiple fields) to identify the entity bean

13-26 Copyright © 2004, Oracle. All rights reserved. Bean Class of an Entity Bean Initializes the bean instance through the ejbCreate() and ejbPostCreate() methods Implements: –Finder methods through ejbFindxxx() methods –Home methods through ejbHomexxx() methods –Callback methods from the EntityBean interface –Business and private methods

13-27 Copyright © 2004, Oracle. All rights reserved. Bean Class of an Entity Bean Contains ejbCreate() and ejbPostCreate() methods for each create() method. The ejbCreate() method: –Is invoked when a client invokes the create() method to initialize persistent fields –Has primary key as return type The ejbPostCreate() method: –Is invoked after the entity bean is created and before any other request from a client is processed –Has void as return type –Initializes any relationship fields for an entity bean

13-28 Copyright © 2004, Oracle. All rights reserved. javax.ejb.EntityBean Interface All entity bean classes should implement the javax.ejb.EntityBean interface. public interface javax.ejb.EntityBean implements javax.ejb.EnterpriseBean { public void ejbActivate(); public void ejbLoad(); public void ejbPassivate(); public void ejbRemove(); public void ejbStore(); public void setEntityContext(EntityContext ctx); public void unSetEntityContext(); }

13-29 Copyright © 2004, Oracle. All rights reserved.

13-30 Copyright © 2004, Oracle. All rights reserved. Life Cycle of an Entity Bean Does not exist newInstance() setEntityContext() Pooled unsetEntityContext() Ready ejbLoad() ejbStore() ejbCreate() ejbPostCreate() ejbActivate() ejbRemove() ejbPassivate() Clients invoke business methods

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

13-32 Copyright © 2004, Oracle. All rights reserved. Deployment Descriptor... False......

13-33 Copyright © 2004, Oracle. All rights reserved.

13-34 Copyright © 2004, Oracle. All rights reserved. Deployment Descriptor... Public PUBLIC Public methods PUBLIC... *

13-35 Copyright © 2004, Oracle. All rights reserved. Summary In this lesson, you should have learned how to: Identify features of an entity bean Use entity beans Distinguish between a session bean and an entity bean Develop components of an entity bean Differentiate BMP beans from CMP beans Describe the life cycle of an entity bean

13-36 Copyright © 2004, Oracle. All rights reserved. Practice 13-1: Overview This practice reviews entity bean concepts using paper-based questions.

13-37 Copyright © 2004, Oracle. All rights reserved.

13-38 Copyright © 2004, Oracle. All rights reserved.