Entity Beans & Persistence Chris Alexander CS 486 Spring 2001.

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.
Copyright W. Howden1 Lecture 19: Intro to O/O Components.
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.
J2EE Part 2: Enterprise JavaBeans CSCI 4300 Images and code samples from jGuru EJB tutorial,
Enterprise Java Beans - (EJB)
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.
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.
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.
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.
Java Server Pages A JSP page is a text-based document that contains two types of text: static template data, which can be expressed in any text-based format,
PHP meets MySQL.
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
1 Architectural Overview For application developers, assembling enterprise beans requires little or no expertise in the complex system-level issues that.
© jGuru.com Enterprise JavaBeans Fundamentals.
Creating competitive advantage Copyright © 2003 Enterprise Java Beans Presenter: Wickramanayake HMKSK Version:0.1 Last Updated:
Class Builder Tutorial Presented By- Amit Singh & Sylendra Prasad.
EJB Overview: Constraint Types and Enforcement in JBoss Elissa Newman Fluid Meeting 6/3/04.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
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.
When the program is first started a wizard will start to setup your Lemming App. Enter your company name and owner in the fields designated “Company Name”
Enterprise JavaBeans. Lesson 1: Introduction to Server-Side Component Software.
Middleware Technology (J2EE/EJB) EJB Fundamentals.
Access Module Implementing a Database with Microsoft Access A Great Module on Your CD.
Bayu Priyambadha, S.Kom. Static content  Web Server delivers contents of a file (html) 1. Browser sends request to Web Server 3. Web Server sends HTML.
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.
Spell Checker web service (you build a web client that interacts with the service) The client uses a servlet class and a JSP page. The user passes information.
CS 440 Database Management Systems Stored procedures & OR mapping 1.
©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
J2EE Application Development
Understanding and Designing with EJB
Objectives In this lesson, you will learn to:
Understanding and Designing with EJB
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.
Knowledge Byte In this section, you will learn about:
Objectives In this lesson, you will learn about:
Presentation transcript:

Entity Beans & Persistence Chris Alexander CS 486 Spring 2001

Completing the Sports Team Example n Begins on pg 998 n The Remote Interface does not change whether the Entity Bean has Container or Bean Managed Persistence –This is good because the bean developer needs to write only to one specification n The Remote Interface should never be directly implemented –The remote interface is used by an application client or a servlet and contains the stubs for the business methods

Sports Team Continued n The implementation of the Entity Bean class (from javax.ejb.EntityBean) is the one that actually implements the business methods of the remote interface. n A name mapping automatically occurs from the remote interface through the container to your entity bean class.

Sports Team n The client code for testing the Entity Bean is on pg n Pseudo-code: –Set initial properties for JNDI context (Orion specific) –Look up the Bean’s home interface –Create a new Sports Team –Add more data –Find record by an owner name –Print the record if found or a message otherwise

Sports Team Notes n The table in the underlying DB must be present if BMP is used n For CMP, it is container implementation specific if a table is required or not. n Many EJB containers create the table on the fly if one doesn’t exist (for CMP). n Deploytool for J2EE creates and drops the tables upon deployment and undeployment of the application (this is customizable though)

Notes cont. n There is a section on how to deploy EJB’s with the Orion application server (pg 1002) (

Relationships n The technique that models DB records in objects is called Object/Relational mapping. n For BMP, it is up to the Bean developer anyway to implement all DB accessing code. n For CMP, the spec says that the container should handle one-to-one relationships at a bare minimum n There is no standard way of handling relationships (EJB 2.0 tries to fix this though)

Completing the Manufacturing Example n The Order Bean –Pg –It has another reference to another EJB public Product productOrdered; This is no problem The Order and Product beans are related one- to-one

Order Bean n There are five static variables –Entity Beans only allow static variables if they are Read-Only –Since many clients can access Entity Beans, Read-Write static vars would result in some synchronization by the container which it doesn’t do.

Order Bean n The Order Bean has a public key made up of two ints, a sales division and an order # n The public key class must have a manditory no arg constructor and provide an implementation of hashCode() and equals() methods n The two keys must be public so the container can directly access them without going through accessor methods (which you can still have if you want)

Remote Interface ( ) n Any Remote Interface must extend EJBObject and not be directly implemented n All business method stubs that the client can call go here n All Business methods must throw at least RemoteException because any application client that calls these will probably use RMI n RemoteException is thrown when any network problems occur

OrderEJB class ( ) n The OrderEJB class is the class that implements the business methods of the Order Remote Interface and also the callback methods of the Bean’s lifecycle. n There are 2 create() methods –The create() methods that are implemented follow a naming convention ejbCreate() ejbPostCreate()

ejbCreate() n The ejbCreate() method will return the Bean’s public key (either a class if two or more key components, or any serializable class if one key component) n The ejbPostCreate() is called after the ejbCreate() method –It is used for any specialized work that may need performed after an Entity Bean is created –Normally not used and returns void

ejbCreate() n In this specific example –One takes a String for a product and one takes a Remote Interface The String version is used to find an EJB that has its primary key equal to the String. The Remote Interface version is a convenience method in case the client already has a reference to the Product Bean

The Home Interface ( ) n This declares both create() methods which are called “create” instead of ejbCreate() n Also declared 3 “finder” methods for looking up Entity Beans from the DB (just like a query). –The finder methods are declared implementation specific for the container –For the Orion server, the finder method has an entry in the Deployment Descriptor

The Product Bean (1014) n Note this contains a linked list of RoutingInstructions class –To be spec compliant, RoutingInstructions and the liked list class must be serializable

The Remote Interface (1016) n Again, must extend EJBObject and throw RemoteException n There are seven business methods

ProductEJB class ( ) n The only life cycle method of importance is ebjCreate() n The others let the container manage the persistence by itself n Reminder: If BMP was used, all the DB accessing SQL (JDBC) code would go into the lifecycle methods of the Entity Bean

Deployment Descriptor Highlights ( ) n All Beans (Session and Entity) are enclosed in tags n Session Beans are enclosed in tags n The Session Type (Stateful or Stateless) are enclosed in tags n Entity Beans are enclosed in tags n Entity Bean Persistence Types are enclosed in tags

Execution n The execution of the Manufacturing Example requires the Orion application server. n The details of how to run the example occur on pages

Recap n Remember where we are in the model

Recap n Remember, the EJB programmer’s main responsibility is to write business logic. n The EJB specification tries to relieve us of any system level tasks. n It does this in exchange for the programmer to structure their code in a particular way. –Naming conventions –Argument lists –Deployment Descriptors –Container Callbacks

What the bean programmer has to do n There are three Java files that the Bean programmer must create –The Home Interface –The Remote Interface –Your Bean class(es) that contain the business logic and the required container callbacks In the case of Entity Beans, your class will implement javax.ejb.EntityBean

Entity Beans n Remember, Entity Beans provide an object oriented representation of data. n They are a shared, transactional state verses a private, conversational state in Session Beans –What this means is that Entity Beans provide a single access point for data that all clients will use compared to Session Beans where they are accessible only to a single client

Entity Beans are just rows in a DB n Entity Beans can be thought of as a proxy to the database data. n The create() method of the Home Interface for an Entity Bean essentially inserts a record into the DB n The create() method for a Session Bean creates an instance of that Bean in the container’s temporary storage

create() n The create() method of the Home Interface returns the Remote Interface of the Bean where as the ejbCreate() method in the Bean implementation returns the Primary Key of the Bean. n The create() method of the Home Interface must throw java.rmi.RemoteException and javax.ejb.CreateException

create() n Entity Beans need not have any create() methods at all. n This would be the case if no new data will be inserted into the DB.

CRUD callbacks n In order for the container to manage persistence, the CRUD callbacks are used –CreateejbCreate() –ReadejbLoad() –UpdateejbStore() –DeleteejbRemove()

ejbRemove() n An important note to realize is the client should NOT call remove() on an Entity Bean unless they want to remove that record from the DB. n This differs from a Stateful Session Bean’s remove() method where the container discards the Session Bean instance from its temporary storage thus ending the session.

BMP/CMP n BMP Callbacks are used to allow the Bean developer to control all the persistence manually n CMP Callbacks (with the exception of ejbCreate()) are used only to fine tune the container’s operations n Persistence is greatly improved in the EJB 2.0 specification

Creating an Entity Bean in deploytool n Assuming… – you have created an application by clicking on File -> New -> Application and running through the wizard –You have the source code for the Home, Remote, and Entity Bean compiled into class files

Creating an Entity Bean in deploytool n Click on Enterprise Bean button on the tool bar n The wizard will pop up n Enter the name of the JAR (can be anything) into the JAR display name field n Click on add that is to the right of the window and select the Home, Remote, and Bean.class files to add them to the JAR

Continued n Click next n In the bean type area, click on Entity n Select the Home, Remote, and Bean classes in the appropriate pull down menus n Give your entity bean a name also here n Click Next

Continued n This screen is where you will select either BMP, CMP 1.1, or CMP 2.0 n Since we are talking about CMP 1.1, click that n Check all the fields you want persisted into the DB n Enter the primary key class type (any standard serializable object or one of your own) and select the primary key field of your bean

Continued n The next few windows deal with outside references to other EJBs or environment issues such as security, these can be left blank for now n In the Transaction Management window, select Required for all the business and finder methods in your bean. The other methods can be left as Not Supported (per documentation)

Continued n In the next window is where the magic occurs. No deployment descriptor is needed to be written by you. It is taken care of by deploytool. n This significantly decreases deployment time and takes away any errors that might be introduced if the deployment descriptor is written by hand.

Finishing n The only thing the developer needs to provide is the SQL code that the container will use to access the DB. n Most of this is done for you also –Click on the bean in the left window and then click on the Entity tab on the right –Click Deployment Settings… –Click on Database Settings and enter jdbc/Cloudscape for the JNDI name

Finishing n Make sure Cloudscape is running then hit OK n Then click on Generate Default SQL… n This will generate almost all SQL code for the bean n The only thing needed is for you to provide the WHERE clauses for the finder methods –ex: SELECT “name” FROM “myTable” WHERE “phone” = ?1 –The ?1 corresponds to the 1st parameter in the finder method

Finishing n Remember to re-save the application. n This takes a lot of the hassle out of the programmers hands by generating the deployment descriptor on the fly. n Either a servlet or an application client can be added into deploytool to test the EJB.

Thank You Questions...