D Copyright © 2004, Oracle. All rights reserved. BMP Entity EJBs J2EE Connector Architecture.

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.
5 Copyright © 2005, Oracle. All rights reserved. Accessing the Database with Servlets.
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.
Writing Enterprise Applications with J2EE (Third lesson) Alessio Bechini June 2002 (based on material by Monica Pawlan)
1 Build a Web Application on J2EE. 2 J2EE Scenario Client – Web Server – EIS Resources Client – Web Server – EIS Resources Client – Application Server.
Writing Enterprise Applications with J2EE (Seventh lesson) Alessio Bechini June 2002 (based on material by Monica Pawlan)
Enterprise JavaBeans Components. Objectives of This Chapter Introduce J2EE framework and EJB architecture Introduce the concepts of EJB component and.
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.
4-Tier Model Client Tier Web Tier Business Tier EIS Tier.
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)
JDBC Session 3 Tonight’s topics: 1.Connection Pooling 2.Transaction Processing Redux 3.Distributed Transactions 4.RowSets 5.Yet more lab time! (Design.
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.
Objektorienteret netværkskommuniation(ITONK1) Persistence.
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.
Connecting to the Enterprise Using VisiConnect David Lucas President Lucas Software Engineering, Inc
Enterprise JavaBeans Umer Farooq CS6704: Design Patterns & Component FrameworksFebruary 25, 2002.
Distributed Systems 1 Master of Information System Management Distributed Systems Persistence.
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.
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,
Session Beans Objectives Introduction to Session Beans Local and Remote Session Beans Stateless and Stateful Session Beans Session Bean Lifecycle Accessing.
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.
Copyright  Oracle Corporation, All rights reserved. 7 Accessing a Database Using SQLJ.
Creating competitive advantage Copyright © 2003 Enterprise Java Beans Presenter: Wickramanayake HMKSK Version:0.1 Last Updated:
JDBC. Java.sql.package The java.sql package contains various interfaces and classes used by the JDBC API. This collection of interfaces and classes enable.
 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.
JDBC and SQLJ CIS 612 Spring JDBC JDBC is an API that enables database access from Java programs JDBC for DB access provides ◦ Portability across.
Session Beans Objectives Introduction to Session Beans Local and Remote Session Beans Stateless and Stateful Session Beans Session Bean Lifecycle Accessing.
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.
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.
Advanced Java Session 7 New York University School of Continuing and Professional Studies.
Enterprise JavaBeans™ Trademark of Sun Microsystems, Inc.
Session Beans & Business Logic CS 486 Sagar Deshpande.
14 Copyright © 2004, Oracle. All rights reserved. Achieving State Management in the Business Tier.
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.
Structure of Enterprise Java Beans
null, true, and false are also reserved.
Objectives In this lesson, you will learn to:
Enterprise Java Beans Bina Ramamurthy 1/13/2019 B.Ramamurthy.
Understanding and Designing with EJB
Enterprise Java Beans Bina Ramamurthy 4/5/2019 B.Ramamurthy.
Presentation transcript:

D Copyright © 2004, Oracle. All rights reserved. BMP Entity EJBs J2EE Connector Architecture

D-2 Copyright © 2004, Oracle. All rights reserved. BMP Bean: Example The example in this lesson creates a BMP entity bean with the following components: –Remote interface: JobsBMP –Home interface: JobsBMPHome –Bean class: JobsBMPBean –Primary key class: JobsBMPPK –Exception class: JobSalException –Deployment descriptor: ejb-jar.xml Client for the JobsBMP bean : JobsBMPClient

D-3 Copyright © 2004, Oracle. All rights reserved. Remote Interface: JobsBMP... public interface JobsBMP extends EJBObject { void incrMinSal(double amt) throws JobSalException, RemoteException; void incrMaxSal(double amt) throws RemoteException; String getJobTitle()throws RemoteException; void setJobTitle(String title)throws RemoteException; double getMinSal()throws RemoteException; void setMinSal(double amt)throws RemoteException; double getMaxSal()throws RemoteException; void setMaxSal(double amt)throws RemoteException; }

D-4 Copyright © 2004, Oracle. All rights reserved. Home Interface: JobsBMPHome... public interface JobsBMPHome extends EJBHome { JobsBMP create() throws RemoteException, CreateException; JobsBMP create(String id, String title, double minSal, double maxSal) throws CreateException,RemoteException; JobsBMP findByPrimaryKey(JobsBMPPK primKey) throws FinderException, RemoteException; Collection findByMaxSalLimit (double salLimit) throws FinderException, RemoteException; double getAvgMaxSal() throws JobSalException, RemoteException; }

D-5 Copyright © 2004, Oracle. All rights reserved.

D-6 Copyright © 2004, Oracle. All rights reserved. Primary Key Class: JobsBMPPK import java.io.Serializable; public class JobsBMPPK implements Serializable { public String jobId; public JobsBMPPK(String id) { this.jobId = id; } public boolean equals(Object job) {...} public int hashCode() { return super.hashCode(); } public String toString() { return jobId; } }

D-7 Copyright © 2004, Oracle. All rights reserved. User-Defined Exception: JobSalException public class JobSalException extends Exception { public JobSalException() { super(); } public JobSalException(Exception e) { super(e.toString()); } public JobSalException(String s) { super(s); } }

D-8 Copyright © 2004, Oracle. All rights reserved. Bean Class: JobsBMPBean... public class JobsBMPBean implements EntityBean { public String id; public String jobTitle; public double maxSal; public double minSal; private Connection conn = null; private EntityContext context; private PreparedStatement ps = null; private ResultSet rset = null; public JobsBMPBean() { System.out.println("New bean instance created"); }...

D-9 Copyright © 2004, Oracle. All rights reserved. Bean Class: JobsBMPBean... public JobsBMPPK ejbCreate(String id, String title, double minSal, double maxSal) { try { this.id = id; this.jobTitle = title; this.minSal = minSal; this.maxSal = maxSal; conn = getConnection(); ps = conn.prepareStatement("INSERT INTO jobs VALUES(?,?,?,?)"); ps.setString(1, id); ps.setString(2, jobTitle); ps.setDouble(3, minSal); ps.setDouble(4, maxSal); ps.executeUpdate(); } catch (Exception e) { e.printStackTrace(); } finally { closeConnection(); } return new JobsBMPPK(id); }...

D-10 Copyright © 2004, Oracle. All rights reserved. create() and ejbCreate() Client Home object EJB object Entity Bean instance Table in database create() EJB Object ejbCreate() primary key EJB Container

D-11 Copyright © 2004, Oracle. All rights reserved. Bean Class: JobsBMPBean public void ejbPostCreate(String id, String title, double minSal, double maxSal) { } public JobsBMPPK ejbFindByPrimaryKey(JobsBMPPK primKey) { try { conn = getConnection(); ps = conn.prepareStatement( "SELECT job_id FROM jobs WHERE job_id = ?"); ps.setString(1, primKey.toString()); rset = ps.executeQuery(); if (!rset.next()) { throw new ObjectNotFoundException("no job with job ID " + primKey); } ps.close(); } catch (Exception e) {... } finally { closeConnection(); } return primKey; }

D-12 Copyright © 2004, Oracle. All rights reserved. Bean Class: JobsBMPBean public void ejbActivate() { } public void ejbPassivate() { } public void setEntityContext(EntityContext ctx) { this.context = ctx; } public void unsetEntityContext() { this.context = null; } public void ejbRemove(){ JobsBMPPK jobId = (JobsBMPPK)context.getPrimaryKey(); try { conn = getConnection(); ps = conn.prepareStatement("DELETE FROM jobs WHERE job_id = ?"); ps.setString(1, jobId.toString()); ps.executeUpdate(); } catch (Exception e1) {...} finally { closeConnection(); } }

D-13 Copyright © 2004, Oracle. All rights reserved. Bean Class: JobsBMPBean public void ejbLoad() { JobsBMPPK key=(JobsBMPPK)context.getPrimaryKey(); this.id = key.jobId; try { conn = getConnection(); ps = conn.prepareStatement( "SELECT job_title,min_salary, max_salary " + "FROM jobs WHERE job_id = ? "); ps.setString(1, id); rset = ps.executeQuery(); rset.next(); jobTitle = rset.getString("job_title"); minSal = rset.getDouble("min_salary"); maxSal = rset.getDouble("max_salary"); }... }

D-14 Copyright © 2004, Oracle. All rights reserved. Bean Class: JobsBMPBean public void ejbStore() { JobsBMPPK key= (JobsBMPPK)context.getPrimaryKey(); String id = key.jobId; try { conn = getConnection(); ps = conn.prepareStatement( "UPDATE jobs SET job_title=?, min_salary=?, max_salary=? WHERE job_id = ?"); ps.setString(1, jobTitle); ps.setDouble(2, minSal); ps.setDouble(3, maxSal); ps.setString(4, id); ps.executeUpdate(); }... }

D-15 Copyright © 2004, Oracle. All rights reserved. Bean Class: JobsBMPBean public void incrMinSal(double amt) throws JobSalException { if ((minSal + amt) > maxSal) { throw new JobSalException ("You cannot increase min salary to be more than " + maxSal);} else { minSal += amt; } } public void incrMaxSal(double amt) { maxSal += amt; } public String getJobTitle() { return jobTitle; } public void setJobTitle(String title) { this.jobTitle = title; } public double getMinSal() { return minSal; }

D-16 Copyright © 2004, Oracle. All rights reserved. Bean Class: JobsBMPBean public void setMinSal(double amt) { this.minSal = minSal; } public double getMaxSal() { return maxSal; } public void setMaxSal(double amt) { this.maxSal = maxSal; } private Connection getConnection() throws SQLException { DataSource ds=null; try { Context ctx = new InitialContext(); ds=(DataSource)ctx.lookup("java:comp/env/jdbc/hrDS"); } catch (NamingException e) { System.out.println("Could not get connection"); e.printStackTrace(); throw new SQLException(e.getMessage()); } return ds.getConnection(); }

D-17 Copyright © 2004, Oracle. All rights reserved. Bean Class: JobsBMPBean private void closeConnection () { try { if (rset != null) rset.close();} catch (Exception e) {...} try { if (ps != null) ps.close();} catch (Exception e) {...} try { if (conn != null) conn.close(); } catch (Exception e) {...} }

D-18 Copyright © 2004, Oracle. All rights reserved. Bean Class: JobsBMPBean public double ejbHomeGetAvgMaxSal() throws JobSalException { try { conn = getConnection(); ps = conn.prepareStatement ("SELECT AVG(max_salary) as AvgMax FROM jobs"); rset = ps.executeQuery(); if (rset.next()) return rset.getDouble("AvgMax"); } catch (Exception e) { e.printStackTrace(); throw new JobSalException(); } finally { closeConnection(); } throw new JobSalException ("Error in the method"); }

D-19 Copyright © 2004, Oracle. All rights reserved. Bean Class: JobsBMPBean public Collection ejbFindByMaxSalLimit (double salLimit) { Vector v = null; try { v = new Vector(); conn = getConnection(); ps = conn.prepareStatement ("SELECT job_id FROM jobs WHERE max_salary > ? "); ps.setDouble(1,salLimit); rset = ps.executeQuery(); while (rset.next()) { String id = rset.getString("job_id"); v.addElement(new JobsBMPPK(id)); } } catch (Exception e) {...} finally { closeConnection(); } return v; }

D-20 Copyright © 2004, Oracle. All rights reserved. Deployment Descriptor... JobsBMP demos.JobsBMPHome demos.JobsBMP demos.JobsBMPBean Bean demos.JobsBMPPK False jdbc/hrDS javax.sql.DataSource Application...

D-21 Copyright © 2004, Oracle. All rights reserved.... JobsBMP * Required Deployment Descriptor

D-22 Copyright © 2004, Oracle. All rights reserved.... <data-source class="com.evermind.sql.DriverManagerDataSource" name="OracleDS" location="jdbc/OracleCoreDS" xa-location="jdbc/xa/OracleXADS" ejb-location="jdbc/hrDS" connection- driver="oracle.jdbc.driver.OracleDriver" username="hr" password="hr" inactivity-timeout="30" /> Creating Data Source data-sources.xml

D-23 Copyright © 2004, Oracle. All rights reserved.

D-24 Copyright © 2004, Oracle. All rights reserved. Client Class: JobsBMPClient import javax.ejb.*; import java.rmi.RemoteException; import java.sql.*; import java.util.*; import javax.naming.*; public class JobsBMPClient { public static void main(String[] args) { JobsBMP jobs = null; try { Context context = getInitialContext(); JobsBMPHome jobsBMPHome = (JobsBMPHome) PortableRemoteObject.narrow (context.lookup("JobsBMP"),JobsBMPHome.class); JobsBMP jobsBMP; jobsBMP = jobsBMPHome.create ("job_dev", "Bean Developer", 3000, 5000);...

D-25 Copyright © 2004, Oracle. All rights reserved. Client Class: JobsBMPClient... jobsBMP.incrMinSal( ); System.out.println ("min_salary after incrementing " + jobsBMP.getMinSal( )); jobsBMP.incrMaxSal( ); System.out.println ("max_salary after incrementing " + jobsBMP.getMaxSal( )); System.out.println("printing job_title "+ jobsBMP.getJobTitle( )); Collection col=jobsBMPHome.findByMaxSalLimit(15000); Iterator it = col.iterator(); while (it.hasNext()) { JobsBMP jobSals = (JobsBMP)it.next(); System.out.println(jobSals.getMaxSal()); } } catch(Throwable ex) {...} }...

D-26 Copyright © 2004, Oracle. All rights reserved. Overview of J2EE Connector Architecture The J2EE Connector Architecture (JCA) enables J2EE components to interact with Enterprise Information Systems (EISs) such as: –Enterprise resource planning (ERP) –Mainframe transaction processing –Databases and nonrelational systems, and so on JCA simplifies the integration of diverse EISs. Adherence to the JCA specification makes an EIS implementation portable across compliant J2EE servers.

D-27 Copyright © 2004, Oracle. All rights reserved. OC4J J2EE Connector Architecture Basic J2EE Connector Architecture: OC4J J2EE Application Component Resource Adapter Enterprise Information System Application Contract System Contracts (Quality of Service)

D-28 Copyright © 2004, Oracle. All rights reserved. What Is a Resource Adapter? It is a driver used by a client application to connect to a specific EIS. OC4J provides support for two J2EE 1.3 types: –A stand-alone resource adapter, which is found in a Resource Adapter Archive (RAR) file for use by all deployed applications –An embedded resource adapter, which is bundled in an EAR file for a specific enterprise application Examples of resource adapters: –JDBC or SQL for Java (SQLJ) drivers for database connections –ERP adapter to connector a specific ERP

D-29 Copyright © 2004, Oracle. All rights reserved. Resource Adapter Deployment Descriptors OC4J provides the following deployment descriptors for resource adapters: ra.xml : A standard J2EE deployment descriptor for developing an adapter oc4j-ra.xml : Contains deployment configurations for deploying an adapter to OC4J oc4j-connectors.xml One oc4j-connectors.xml file: Contains a list of stand-alone resource adapters deployed. It is located in the ORACLEAS_HOME/j2ee/home/config directory.

D-30 Copyright © 2004, Oracle. All rights reserved. Deploying Stand-Alone Resource Adapters When deploying stand-alone adapters: Give the resource adapter a unique name, to simplify future operations such as removal of a deployed resource adapter Deploy in one of the following two ways: –Using the Admin command-line tool ( admin.jar ) –Manually through directory manipulation, by expanding the.rar file contents into a user- specified directory name below the ORACLEAS_HOME/j2ee/home/ (which defaults to ORACLEAS_HOME/j2ee/home/connectors )

D-31 Copyright © 2004, Oracle. All rights reserved. Deploying Embedded Resource Adapters Embedded resource adapters are packaged and deployed inside an Enterprise Application Archive (EAR) file. Each application (from an EAR file) has one oc4j- connectors.xml file. The application oc4j-connectors.xml file lists all the resource adapters deployed in the EAR file. The oc4j-connectors.xml file is automatically generated if not already included in the EAR file.

D-32 Copyright © 2004, Oracle. All rights reserved. Common Client Interface (CCI) API CCI is defined by the J2EE Connector Architecture specification as: A set of interfaces and classes to allow a J2EE component to perform data access operations with an EIS Main interfaces and classes are: – ConnectionFactory – Connection – Interaction – RecordFactory – Record (Use Sun’s Java J2EE Tutorial for more information.)