95-702 Distributed Systems 1 Master of Information System Management 95-702 Distributed Systems Persistence.

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.
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.
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.
OCT 1 Master of Information System Management Organizational Communications and Distributed Object Technologies Lecture 14:Enterprise Java Beans.
Enterprise JavaBeans 2.0 Wu Lu (Cont’d). EJB2.0 Query Language EJB QL is a declarative language similar in many respects to SQL Is intended to be portable.
Overview of The Java Platform Solution for E-Business Applications : JSP, Servlet and EJB.
Copyright W. Howden1 Lecture 19: Intro to O/O Components.
Organizational Communication Technologies 1 Enterprise Java Beans Detail.
Chapter 10 EJB Concepts of EJB Three Components in Creating an EJB Starting/Stopping J2EE Server and Deployment Tool Installation and Configuration of.
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)
EJB Enterprise Java Bean.
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.
1 SOA and Enterprise Computing Enterprise Java Beans.
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.
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.
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.
OCT 1 Master of Information System Management Distributed Systems Lecture 19: Enterprise Java Beans.
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.
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.
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.
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
Luca Simone Software Engineering 2 a.a. 2001/2002
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.
Enterprise Java Beans: an introduction
Knowledge Byte In this section, you will learn about:
Presentation transcript:

Distributed Systems 1 Master of Information System Management Distributed Systems Persistence

Distributed Systems Recall Four Styles of Integration RPC/RMI Shared File Messaging Share database  And, we want to interact with databases even when we are not intent on integration. 2 Master of Information System Management

Distributed Systems Accessing Databases The Java Persistence API is meant to replace EJB Entity Beans. Entity beans are heavyweight and require an EJB container. Why not use JDBC? Separation of concerns: separate the integration logic from the business logic. 3 Master of Information System Management

Distributed Systems 4 Master of Information System Management Java EE Tutorial (OLD) Servlets JSP’s Axis2 HTML Session beans Entity beans Message Driven Beans

Distributed Systems 5 Master of Information System Management From The Java EE Tutorial

Distributed Systems 6 Master of Information System Management SOAP and Java EE Slide from JAXM/JMS tutorial at Sun Microsystems Replaced by JPA.

Distributed Systems 7 Master of Information System Management Slide from JAXM/JMS tutorial at Sun Microsystems Replaced by JPA.

Distributed Systems 8 Master of Information System Management EJB Types (Old) Entity Beans Session Beans Message-Driven Beans

Distributed Systems 9 Master of Information System Management EJB Types (Old) Entity Beans Session Beans Message-Driven Beans } } RMI-based server side components Accessed using distributed object Protocols (RMI IIOP) New since EJB 2.0 Asynchronous server side component that responds to JMS asynchronous messages (Think provider like JAXM)

Distributed Systems 10 Master of Information System Management EJB Entity Beans Represent real world entities (customers, orders, etc.). Persistent objects typically stored in a relational database using CMP (Container Managed Persistence) or BMP (Bean Managed Persistence). The client sees no difference between CMP and BMP beans. CMP promotes component portability (more reliant on the container to handle detail). CMP uses its own Query Language EJB QL. CMP relies on an Abstract Schema in the deployment descriptor.

Distributed Systems 11 Master of Information System Management Implementing Entity and Session Beans Defining the component interfaces: – You may choose to define all or only some of these depending on how you want your bean used. – local interfaces do not require RMI overhead. Define a bean class. For entity beans define a primary key.

Distributed Systems 12 Master of Information System Management Implementing Entity and Session Beans Define the component interfaces –The remote interface specifies how the outside world can access the bean’s business methods –The remote home interface specifies how the outside world can access the bean’s life- cycle methods (for creating, removing and finding) –The local interface specifies how the inside world (same EJB container) can access the bean’s business methods –The local home interface specifies how the inside world can access the bean’s life-cycle methods

Distributed Systems 13 Master of Information System Management Implementing Entity and Session Beans Implement the bean –Fill in the code for the business and life- cycle methods. –It’s not normal to directly implement the interfaces as we do in standard Java (though you must provide many of the methods). The calls to methods are not normal Java calls. They first go through the container. –Session beans implement javax.ejb.SessionBean. –Entity beans implement javax.ejb.EntityBean. –Both beans extend javax.ejb.EnterpriseBean

Distributed Systems 14 Master of Information System Management For Entity Beans Define a primary key class: –Required for entity beans. –Provides a pointer into the database. –Must implement Java.io.Serializable. The EJB instance represents a particular row in the corresponding database table. The home interface for the entity EJB represents the table as a whole (has finder methods.)

Distributed Systems 15 Master of Information System Management Entity Beans Each entity bean has a unique identifier called its primary key The primary key can be used by the client to locate the bean Each bean represents a row in its table Rows may have columns that reference other entity beans (students take courses) These relationships may be managed by the bean or by the container (container managed relationships)

Distributed Systems 16 Master of Information System Management Entity Bean Relationships OrderEJB CusomerEJB 1 Many 1 Many LineItemEJB ProductEJB Many 1 A relationship field is like a foreign key in a database. If a b then a “knows about” or “holds a pointer to” b.

Distributed Systems 17 Master of Information System Management Entity Bean Life Cycle (From Sun) Does not exist Pool of available instances -- Ready to have business methods called -- Has an identity setEntityContext unsetEntityContext ejbActivate ejbPassivate Client calls create and container calls ejbCreate and ejbPostCreate Client calls remove and container calls ejbRemove Client initiates Container initiates

Distributed Systems 18 Master of Information System Management A Typical Entity Bean Needs: A Home interface defining the create and finder methods. A Component interface defining the business methods a client may call. An implementation of the Component interface. Deployment descriptors.

Distributed Systems 19 Master of Information System Management A Home Interface import javax.ejb.*; // From Eckel import java.util.Collection; import java.rmi.RemoteException; public interface MovieHome extends EJBHome { public Movie create(Integer id, String title) throws RemoteException, CreateException; public Movie findByPrimaryKey(Integer id) throws RemoteException, FinderException; }

Distributed Systems 20 Master of Information System Management A Component Interface import javax.ejb.*; // From Eckel import java.rmi.RemoteException; /** * A movie, with id and title. * * Note that there is no setId() method in the * interface, to prevent clients from arbitrarily * changing a movie's primary key. */ public interface Movie extends EJBObject { public Integer getId() throws RemoteException; public String getTitle() throws RemoteException; public void setTitle(String title) throws RemoteException; }

Distributed Systems 21 Master of Information System Management The Container Implements the component interface (From Eckel)

Distributed Systems 22 Master of Information System Management import javax.ejb.CreateException; // From Eckel import javax.ejb.EntityBean; import javax.ejb.EntityContext; public abstract class MovieBean implements EntityBean { // Container notifications methods public Integer ejbCreate(Integer id, String title) throws CreateException { if (id == null) throw new CreateException("Primary key cannot be null"); if (id.intValue() == 0) throw new CreateException("Primary key cannot be zero"); setId(id); setTitle(title); return null; }

Distributed Systems 23 Master of Information System Management public void ejbPostCreate(Integer id, String title) {} // Called by public void ejbLoad() {} // container public void ejbStore() {} public void ejbRemove() {} public void ejbActivate() {} public void ejbPassivate() {} public void setEntityContext(EntityContext ctx) {} public void unsetEntityContext() {} // Business methods provided by container public abstract void setId(Integer id); public abstract String getTitle(); public abstract void setTitle(String title); public abstract Integer getId(); } // From Eckel

Distributed Systems 24 Master of Information System Management Deployment Descriptor // From Eckel Movie javatheater.ejb.MovieHome javatheater.ejb.Movie javatheater.ejb.implementation.MovieBean Container java.lang.Integer False 2.x Movie id - title - id

Distributed Systems 25 Master of Information System Management Client (From Eckel) import javax.naming.*; import javatheater.ejb.*; public class MovieClient { public static void main(String[] args) throws Exception { javax.naming.Context initial = new javax.naming.InitialContext(); Object objRef = initial.lookup("javatheater/Movie"); MovieHome movieHome = (MovieHome) javax.rmi.PortableRemoteObject.narrow( objRef, MovieHome.class);

Distributed Systems 26 Master of Information System Management // Generate a primary key value int pkValue = (int) System.currentTimeMillis() % Integer.MAX_VALUE; // Create a new Movie entity Movie movie = movieHome.create( new Integer(pkValue), "A Bug’s Life" ); // As a test, locate the newly created entity movie = movieHome.findByPrimaryKey(new Integer(pkValue)); // Access the bean properties System.out.println(movie.getId()); System.out.println(movie.getTitle()); // Remove the entity movie.remove(); }

Distributed Systems Entity Beans Are A Lot Of Work The JPA 2.0 specification was released in Implemented by: Hibernate EclipseLink Open JPA Object DB TopLink and many others 27 Master of Information System Management

Distributed Systems JPA Notes From Oracle JPA simplifies the programming model for entity persistence: - Requires fewer classes and interfaces - Virtually eliminates lengthy deployment descriptors through annotations - Eliminates the need for lookup code - Adds support for named (static) and dynamic queries. - Provides a Java Persistence query language -- an enhanced EJB QL Makes it easier to test entities outside of the EJB container. - Can be used outside of the container - Can be used with pluggable, third-party persistence providers 28 Master of Information System Management

Distributed Systems In Class Exercise Using Netbeans 7.0 Using EclipseLink default JPA 2.0 Implementation See course schedule for link. 29 Master of Information System Management