1 Architectural Overview For application developers, assembling enterprise beans requires little or no expertise in the complex system-level issues that.

Slides:



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

11 Copyright © 2005, Oracle. All rights reserved. Creating the Business Tier: Enterprise JavaBeans.
Apache Struts Technology
Approaches to EJB Replication. Overview J2EE architecture –EJB, components, services Replication –Clustering, container, application Conclusions –Advantages.
Sapana Mehta (CS-6V81) Overview Of J2EE & JBoss Sapana Mehta.
Introduction to Enterprise JavaBeans. Integrating Software Development Server-side Component Model Distributed Object Architecture –CORBA –DCOM –Java.
Entities and Persistence. Entity Beans Topics to be Covered: Entities are POJOs Managed/Unmanaged Entities Persistence Unit EntityManager Basic Relational.
Overview of The Java Platform Solution for E-Business Applications : JSP, Servlet and EJB.
EJB Development and Support Services. EJB Development and Support Services Topics to be Covered: EJB Design Bean/Container Interaction Java Naming and.
Enterprise Applications & Java/J2EE Technologies Dr. Douglas C. Schmidt Professor of EECS.
EJB Design. Server-side components Perform –complex algorithms –high volume transactions Run in –highly available environment (365 days/year) –fault tolerant.
J2EE Java 2 Enterprise Edition. Relevant Topics in The Java Tutorial Topic Web Page JDBC orial/jdbc
Enterprise Java Beans (EJB)
J2EE Kenneth M. Anderson CSCI Web Technologies October 3, 2001.
Emmanuel Cecchet et al.  Performance Scalability of J2EE application servers.  Test effect of: ◦ Application Implementation Methods ◦ Container Design.
Distributed System Using Java 2 Enterprise Edition (J2EE)
Struts 2.0 an Overview ( )
Chapter 10 EJB Concepts of EJB Three Components in Creating an EJB Starting/Stopping J2EE Server and Deployment Tool Installation and Configuration of.
1 J2EE Components. 2 Application Servers relieve the programming burden for business distributed components. They provide support for system level services.
Enterprise Java Beans CS-422. Application Servers In the late 1980s and though the mid 1990s a number of corporations (Broadvision, Netscape…) marketed.
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.
Ing. Ignacio Roqueta ARTech GeneXus and J2EE.
Entity Beans BMP Celsina Bignoli
Enterprise Java Beans Part I Kyungmin Cho 2001/04/10.
September 16, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser
1 Stateful Session Beans Stateless Session Beans Michael Brockway Sajjad Shami Northumbria University School of Computing, Engineering & Information Sciences.
Enterprise Java Bean Matt. 2 J2EE 3 J2EE Overview.
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.
JBoss at Work JAW Motors Application Chapter 1-3 Jeff Schmitt October 9, 2006.
JBoss Seam Presented by Andy Nguyen Truc Pham. What is JBoss Seam? Created by Gavin King Created by Gavin King A lightweight framework for Java EE 5.0.
1 HKU CSIS DB Seminar: HKU CSIS DB Seminar: Web Services Oriented Data Processing and Integration Speaker: Eric Lo.
J2EE Structure & Definitions Catie Welsh CSE 432
Source: Peter Eeles, Kelli Houston, and Wojtek Kozaczynsky, Building J2EE Applicationa with the Rational Unified Process, Addison Wesley, 2003 Prepared.
Ch 2 – Application Assembly and Deployment COSC 617 Jeff Schmitt September 14, 2006.
Enterprise JavaBeans Understanding EJB Components Version 0.1 Kamal Wickramanayake
Hibernate Persistence. What is Persistence Persist data to database or other storage.  In OO world, persistence means persist object to external storage.
Assignment of JAVA id : BSSE-F10-M-10-JAVA1 Overview of J2EE/Session 2/Slide 1 of 38.
EJB Overview: Constraint Types and Enforcement in JBoss Elissa Newman Fluid Meeting 6/3/04.
Entity Beans & Persistence Chris Alexander CS 486 Spring 2001.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
J2EE Chris Hundersmarck Maria Baron Jeff Webb.  Java 2 Platform, Micro Edition (J2ME)  Java 2 Platform, Standard Edition (J2SE)  Java 2 Platform, Enterprise.
Enterprise JavaBeans Session Beans. Session beans are a type of Enterprise JavaBean component designed to implement business logic responsible for managing.
Session Beans Based on: Patel, Brose, Silverman, Mastering Enterprise JavaBeans 3.0.
Component Patterns – Architecture and Applications with EJB copyright © 2001, MATHEMA AG Component Patterns Architecture and Applications with EJB Markus.
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.
v110912Java Persistence: EntityManager2 Overview Earlier versions of EJB Specification defined the persistence layer –javax.ejb.EntityBean Java EE 5 moved.
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.
©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. Lesson 1: Introduction to Server-Side Component Software.
IS-907 Java EE Introduction to JPA. Java Persistence API A framework for using relational databases in Java programs mapping between tables and classes,
Middleware Technology (J2EE/EJB) EJB Fundamentals.
EJB Enterprise Java Beans JAVA Enterprise Edition
DEVELOPING WEB SERVICES WITH JAVA DESIGN WEB SERVICE ENDPOINT.
EJB. Introduction Enterprise Java Beans is a specification for creating server- side scalable, transactional, multi-user secure enterprise-level applications.
A service Oriented Architecture & Web Service Technology.
Enterprise Java Beans. Contents  Understanding EJBs  Practice Section.
EJB (Enterprise Java Beans)
Introduction to J2EE Architecture
Introduction to Enterprise JavaBean
Distributed System Using Java 2 Enterprise Edition (J2EE)
Understanding and Designing with EJB
Component-based Applications
Component Technology Bina Ramamurthy 2/25/2019 B.Ramamurthy.
Developing and testing enterprise Java applications
Enterprise Java Beans.
Knowledge Byte In this section, you will learn about:
Presentation transcript:

1 Architectural Overview For application developers, assembling enterprise beans requires little or no expertise in the complex system-level issues that often plague three-tier development efforts. For application developers, assembling enterprise beans requires little or no expertise in the complex system-level issues that often plague three-tier development efforts. While EJB makes the process easier for application developers, it also provides EJB server developers with a great deal of flexibility in how they support the EJB specification. While EJB makes the process easier for application developers, it also provides EJB server developers with a great deal of flexibility in how they support the EJB specification.

2 Architectural Overview Java Persistence also makes it fairly easy for developers to write objects that can be persisted to a relational database. Java Persistence also makes it fairly easy for developers to write objects that can be persisted to a relational database. Writing a persistent entity bean can be as easy as using a few strategically placed annotations with little to no information about the database. Writing a persistent entity bean can be as easy as using a few strategically placed annotations with little to no information about the database.

3 The Entity Bean Entity beans in the Java Persistence 1.0 specification are available only as plain old Java objects (POJOs), and are mapped to tables in a relational database. Entity beans in the Java Persistence 1.0 specification are available only as plain old Java objects (POJOs), and are mapped to tables in a relational database. Unlike other EJB types, entities can be allocated, serialized, and sent across the network like any other POJO. Unlike other EJB types, entities can be allocated, serialized, and sent across the network like any other POJO.

4 The Entity Bean To implement an entity bean, you need to define a bean class and decide what field you will use as the identifier (primary key) of that bean class: To implement an entity bean, you need to define a bean class and decide what field you will use as the identifier (primary key) of that bean class:

5 Primary key The primary key is something that provides a pointer into the database. It gives the entity bean class's identity both in memory as an object and in the database as a row in a table. The primary key can be a class or a primitive type. The primary key is something that provides a pointer into the database. It gives the entity bean class's identity both in memory as an object and in the database as a row in a table. The primary key can be a class or a primitive type.

6 Bean class The bean class is a POJO that does not have to implement any interface or even be serializable. It must be tagged with annotation and have at least one field or getter method that is designated as the primary key of the entity bean class in the database. The bean class is a POJO that does not have to implement any interface or even be serializable. It must be tagged with annotation and have at least one field or getter method that is designated as the primary key of the entity bean class in the database.

7 Bean class This is usually done with annotation. Entities have other annotations available to define a full object-relational database mapping as well. This is usually done with annotation. Entities have other annotations available to define a full object-relational database mapping as well. In Java Persistence, entity beans are not components like their EJB 2.1 counterparts are. In Java Persistence, entity beans are not components like their EJB 2.1 counterparts are.

8 Bean class Application code works directly with the entity bean classes and does not interact with the entity through a component interface, as you would with an EJB session bean. To interact with entity beans, Java Persistence provides a new service called the EntityManager. Application code works directly with the entity bean classes and does not interact with the entity through a component interface, as you would with an EJB session bean. To interact with entity beans, Java Persistence provides a new service called the EntityManager.

9 Bean class All access to an entity goes through this service. It provides a query API and life cycle methods for the entity. No magic. No bytecode manipulation. No special proxies. Just plain Java. All access to an entity goes through this service. It provides a query API and life cycle methods for the entity. No magic. No bytecode manipulation. No special proxies. Just plain Java.

10 The Entity Bean Class To define an entity bean, all we'll need to do is define the bean class and annotate it: To define an entity bean, all we'll need to do is define the bean class and annotate it: import public class Cabin { private int id; private String name; private int deckLevel;

11 The Entity @Column(name="CABIN_ID") public int getId( ) { return id; } public void setId(int pk) { this.id = pk; public String getName( ) { return name; } public void setName(String str) { this.name = str; public int getDeckLevel( ) { return deckLevel; } public void setDeckLevel(int level) { this.deckLevel = level } }

12 The Entity Bean Class Unlike EJB 2.1, in which entity beans were implemented as abstract classes, Java Persistence entity beans are real objects. Java Persistence defines a relatively complete object-to-relational database mapping (ORM) Unlike EJB 2.1, in which entity beans were implemented as abstract classes, Java Persistence entity beans are real objects. Java Persistence defines a relatively complete object-to-relational database mapping (ORM)

13 XML Deployment Descriptors and JAR Files Once you have written your entity bean classes, you need to be able to deploy them in your environment. Entity beans are grouped into a finite set of classes called a persistence unit. Once you have written your entity bean classes, you need to be able to deploy them in your environment. Entity beans are grouped into a finite set of classes called a persistence unit. There is an EntityManager service that manages a persistence unit, and it must be identified so that it can be referenced in application code. There is an EntityManager service that manages a persistence unit, and it must be identified so that it can be referenced in application code. Also, each persistence unit must be associated to a particular database so that the persistence provider knows where, how, and with what kind of database it is interacting. Also, each persistence unit must be associated to a particular database so that the persistence provider knows where, how, and with what kind of database it is interacting.

14 This information is stored in an XML deployment descriptor named persistence.xml and is a required artifact. This information is stored in an XML deployment descriptor named persistence.xml and is a required artifact. Once you have defined your XML deployment descriptors and entity bean classes, you must package them all in a Java Archive (JAR) file. The JAR file is used as both a library at runtime and a holder for deployment information. Once you have defined your XML deployment descriptors and entity bean classes, you must package them all in a Java Archive (JAR) file. The JAR file is used as both a library at runtime and a holder for deployment information. XML Deployment Descriptors and JAR Files

15 The Enterprise Bean Component Enterprise JavaBeans server-side components come in two fundamentally different types: session beans and message- driven beans. Enterprise JavaBeans server-side components come in two fundamentally different types: session beans and message- driven beans. Session beans are server-side components that can be accessed using a variety of distributed object protocols. Session beans are server-side components that can be accessed using a variety of distributed object protocols. Message-driven beans process messages asynchronously from systems like the JMS, legacy systems, and web services. Message-driven beans process messages asynchronously from systems like the JMS, legacy systems, and web services.

16 The Enterprise Bean Component All EJB servers must at least support a JMS- based message-driven bean, but they may also support other types of message-driven beans. All EJB servers must at least support a JMS- based message-driven bean, but they may also support other types of message-driven beans. The activity that a session or message-driven bean represents is fundamentally transient: you start making a reservation, you do a bunch of work, and then it's finished. The activity that a session or message-driven bean represents is fundamentally transient: you start making a reservation, you do a bunch of work, and then it's finished. The session and message-driven beans do not represent things in the database. The session and message-driven beans do not represent things in the database.

17 Classes and Interfaces A good way to understand the design of enterprise beans is to look at how you'd go about implementing one. A good way to understand the design of enterprise beans is to look at how you'd go about implementing one. To implement session and message- driven enterprise beans, you need to define their component interfaces, and a bean class: To implement session and message- driven enterprise beans, you need to define their component interfaces, and a bean class:

18 Remote interface The remote interface defines a session bean's business methods, which can be accessed from applications outside the EJB container: the business methods a bean presents to the outside world to do its work. The remote interface defines a session bean's business methods, which can be accessed from applications outside the EJB container: the business methods a bean presents to the outside world to do its work. The remote interface is a plain Java interface. It is tagged with annotation to identify that it is a remote interface. The remote interface is a plain Java interface. It is tagged with annotation to identify that it is a remote interface.

19 Local interface The local interface defines a session bean's business methods that can be used by other beans in the same EJB container: the business methods a bean presents to other beans running in the same JVM. The local interface defines a session bean's business methods that can be used by other beans in the same EJB container: the business methods a bean presents to other beans running in the same JVM.

20 Local interface It allows beans to interact without the overhead of a distributed object protocol, which improves their performance. It allows beans to interact without the overhead of a distributed object protocol, which improves their performance. The local interface is a plain Java interface. It is tagged with annotation to identify that it is a local interface. The local interface is a plain Java interface. It is tagged with annotation to identify that it is a local interface.

21 Endpoint interface The endpoint interface defines business methods that can be accessed from applications outside the EJB container via SOAP. The endpoint interface defines business methods that can be accessed from applications outside the EJB container via SOAP. The endpoint interface is based on Java API for XML-RPC (JAX-RPC) and is designed to adhere to the SOAP and WSDL standards. The endpoint interface is based on Java API for XML-RPC (JAX-RPC) and is designed to adhere to the SOAP and WSDL standards. The endpoint interface is a plain Java interface that is annotated with annotation. The endpoint interface is a plain Java interface that is annotated with annotation.

22 Message interface Message-driven beans implement the message interface, which defines the methods by which messaging systems, such as the JMS, can deliver messages to the bean. Message-driven beans implement the message interface, which defines the methods by which messaging systems, such as the JMS, can deliver messages to the bean.

23 Bean class The session bean class contains business logic and must have at least one remote, local, or endpoint interface. The session bean class contains business logic and must have at least one remote, local, or endpoint interface. It usually implements these interfaces, but it is not required to. It usually implements these interfaces, but it is not required to. A bean class may also have more than one interface of a given type. A bean class may also have more than one interface of a given type. The EJB container usually determines whether a session bean is remote and/or local by the interfaces it implements. The EJB container usually determines whether a session bean is remote and/or local by the interfaces it implements.

24 Bean class The session bean class must also be tagged with annotation so that the EJB container knows what session bean type it is. The session bean class must also be tagged with annotation so that the EJB container knows what session bean type it is.

25 The remote interface Having introduced the machinery, let's look at how to build a very simple stateless session bean with a remote component interface. Having introduced the machinery, let's look at how to build a very simple stateless session bean with a remote component interface. Now we will examine the Calculator EJB, a session bean that exposes basic calculator functions as a service. Let's start with its remote interface. Now we will examine the Calculator EJB, a session bean that exposes basic calculator functions as a service. Let's start with its remote interface.

26 The remote interface We'll define the remote interface for the Calculator bean using the CalculatorRemote interface, which defines arithmetic operations. We'll define the remote interface for the Calculator bean using the CalculatorRemote interface, which defines arithmetic operations. Remote interfaces are denoted by annotation: Remote interfaces are denoted by annotation:

27 The remote interface import public interface CalculatorRemote { public int add(int x, int y); public int subtract(int x, int y); } You'll notice that even though this is the remote interface of the EJB, there is no reference to Java RMI interfaces or APIs. You'll notice that even though this is the remote interface of the EJB, there is no reference to Java RMI interfaces or APIs. This is a big change in the EJB 3.0 specification compared to older versions. This is a big change in the EJB 3.0 specification compared to older versions.

28 The bean class Now let's look at an actual stateless session bean class. Now let's look at an actual stateless session bean class. Here's the code for the CalculatorBean class; it's a sparse implementation, but it shows how the pieces fit together: Here's the code for the CalculatorBean class; it's a sparse implementation, but it shows how the pieces fit together:

29 The bean class import public class CalculatorBean implements CalculatorRemote { public int add(int x, int y) { return x + y; } public int subtract(int x, int y) { return x - y; }

30 The bean class The CalculatorBean class is required to implement at least one remote or local interface and to be annotated The CalculatorBean class is required to implement at least one remote or local interface and to be annotated Those familiar with earlier EJB specifications will notice that session beans do not have to implement an EJB- specific interface or any of the callback notifications. Those familiar with earlier EJB specifications will notice that session beans do not have to implement an EJB- specific interface or any of the callback notifications.

31 Message-Driven Beans Message-driven beans also have a bean class that implements a message interface; they don't implement remote, local, or endpoint interfaces. Message-driven beans also have a bean class that implements a message interface; they don't implement remote, local, or endpoint interfaces. This bean class is annotated using annotation. Message-driven beans are integration points for other applications interested in working with EJB applications. This bean class is annotated using annotation. Message-driven beans are integration points for other applications interested in working with EJB applications.

32 Message-Driven Beans Java applications or legacy systems that need to access EJB applications can send messages to message-driven beans via JMS. Java applications or legacy systems that need to access EJB applications can send messages to message-driven beans via JMS. These beans process those messages and perform the required tasks using other entity and session beans. These beans process those messages and perform the required tasks using other entity and session beans.

33 Message-Driven Beans EJB 3.0 is not limited to JMS-based message-driven beans: message-driven beans can support any messaging system that implements the correct JCA 1.5 contracts. EJB 3.0 is not limited to JMS-based message-driven beans: message-driven beans can support any messaging system that implements the correct JCA 1.5 contracts. However, support for JMS-based message-driven beans (JMS-MDBs) in EJB 3.0 is mandatory. However, support for JMS-based message-driven beans (JMS-MDBs) in EJB 3.0 is mandatory.

34 Stateful and statelessl session beans Session beans can be either stateful or stateless. Session beans can be either stateful or stateless. Stateful session beans maintain conversational state when used by a client. Stateful session beans maintain conversational state when used by a client. Conversational state is not written to a database; it's information that is kept in memory while a client carries on a conversation with an enterprise bean, and it is lost when the conversation ends or the EJB container crashes. Conversational state is not written to a database; it's information that is kept in memory while a client carries on a conversation with an enterprise bean, and it is lost when the conversation ends or the EJB container crashes.

35 Stateful and statelessl session beans Stateful session beans are not shared among clients; they are dedicated to the same client for the life of the enterprise bean. Stateful session beans are not shared among clients; they are dedicated to the same client for the life of the enterprise bean. Stateless session beans do not maintain any conversational state. Each method is completely independent and uses only data passed in its parameters. Stateless session beans do not maintain any conversational state. Each method is completely independent and uses only data passed in its parameters.

36 The Bean-Container Contract The environment that surrounds the beans on the EJB server is often called the container. The environment that surrounds the beans on the EJB server is often called the container. The container is more a concept than a physical construct. It acts as an intermediary between the bean and the EJB server. The container is more a concept than a physical construct. It acts as an intermediary between the bean and the EJB server. It manages the EJB objects and helps these constructs manage bean resources and provide services such as transactions, security, concurrency, and naming at runtime. It manages the EJB objects and helps these constructs manage bean resources and provide services such as transactions, security, concurrency, and naming at runtime.

37 The Bean-Container Contract The distinction between the container and the server is not clearly defined, but the EJB specification defines the component model in terms of the container's responsibilities, so we will follow that convention here. The distinction between the container and the server is not clearly defined, but the EJB specification defines the component model in terms of the container's responsibilities, so we will follow that convention here.