Middleware Technology (J2EE/EJB) Entity Bean. 2 Introduction to Entity Beans Persistence Concepts Entity beans are persistent objects that can be stored.

Slides:



Advertisements
Similar presentations
12 Copyright © 2005, Oracle. All rights reserved. Implementing Business Tasks with Session EJBs.
Advertisements

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.
Distributed System Using Java 2 Enterprise Edition (J2EE) B.Ramamurthy.
Application Server Lecture Paulo Barroso Kris Carver Todd Kitterman Eric Silva.
Copyright W. Howden1 Lecture 19: Intro to O/O Components.
CS 483 Enterprise and Web Application Programming
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. 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)
Enterprise JavaBeans EJB Container Services. EJB container Enterprise JavaBeans are deployed in an EJB container within the application server EJB container.
Entity Beans BMP Celsina Bignoli
Lecture 8 Advanced Topics in Enterprise JavaBeans.
Objektorienteret netværkskommuniation(ITONK1) Persistence.
© D. Wong  Indexes  JDBC  JDBC in J2EE (Java 2 Enterprise Edition)
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.
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.
Middleware Technology (J2EE/EJB) Stateful Session Bean.
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.
Andrew S. Budarevsky Adaptive Application Data Management Overview.
© jGuru.com Enterprise JavaBeans Fundamentals.
Creating competitive advantage Copyright © 2003 Enterprise Java Beans Presenter: Wickramanayake HMKSK Version:0.1 Last Updated:
JPA / HIBERNATE CSCI 6370 Nilayan Bhattacharya Sanket Sable.
UNIT III - JDBC JDBC Overview – JDBC implementation – Connection class – Statements - Catching Database Results, handling database Queries. Networking–
Topic : Hibernate 1 Kaster Nurmukan. An ORM tool The problem fixed by ORM Advantage Hibernate Hibernate Basic –Hibernate sessionFactory –Hibernate Session.
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.
Enterprise Java Bean Technology Briefing Markus Hebach.
Basics of JDBC Session 14.
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.
13 Copyright © 2004, Oracle. All rights reserved. Managing Persistent Data in the Business Tier Entity EJBs.
Topic : Hibernate 1 Kaster Nurmukan. An ORM tool Used in data layer of applications Implements JPA.
©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.
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.
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.
©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
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
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:
Presentation transcript:

Middleware Technology (J2EE/EJB) Entity Bean

2 Introduction to Entity Beans Persistence Concepts Entity beans are persistent objects that can be stored in permanent storage. 3 popular ways to persists objects  Java Object Serialization object graphbyte stream Marshalling Unmarshalling We can push the stream over network or save the stream to storage, such as a file system, database, or JNDI tree.

3 Persistence Concepts Problem: The stream is not relevant to content. It’s expensive and cumbersome to query objects stored using object serialization. Example: bank account  Object-Relational Mapping When saving Java objects, we use JDBC to map the object data into a relational database. Java classDatabase table definition instance of that classa row in that table fields in that instancecells in that row

4 Persistence Concepts When we want to load our objects from the database, we could instantiate an object from that class, read the data in from the database, and then populate that object instance’s fields with the relational data read in. Mapping of objects to relational data can be done in two ways.  hand-craft database access API: JDBC or SQL/J  automation mapping product: WebGain’s TOPLink, SUN’s JavaBlend

5 An example of object-relational mapping (Bank Account)

6 Persistence Concepts  Object Databases Java objects are stored as whole objects in the ODBMS (Object DataBase Management System). There is no O/R mapping layer. We program to the object database’s API, not the relational database API. OQL (Object Query Language) rather than SQL (Structured Query Language, SELECT, DELETE, INSERT, UPDATE) Certain applications, for instance, geospatial, CAD/CAM, are complete unfit for relational databases, which go really well with object databases. Vendors: ObjectStore, Versant, POET

7 Entity Bean Two different kinds of components deployed  Application Logic Component Session Bean method provider, action(verb), handle business processes  Persistent Data Component Entity Bean data, handle business data, using some persistence mechanism to render themselves into persistent storage.

8 Entity Bean Why we need such persistent data components instead of the database data 1 、 Objects can be easily handled and managed 2 、 We can group related data in a unified object. (view from multiple tables) 3 、 We can associate methods with data (get/set) 4 、 We can gain implicit middleware services from application server Entity Bean Files (2.x)  remote/local interface (.java)  home/local home interface (.java)  enterprise bean class (.java)

9 Features of Entity Beans Entity Bean Survive Failures Entity beans are persistent objects which can survive critical failures, such as application server crashing, or machine crashing. Entity beans are just representations of data in a permanent, fault-tolerant underlying storage. If a machine crashes, all we need to do is read the data back in from the permanent database and instantiate an entity bean Java object instance whose fields contain the data read in from the database.

10 Features of Entity Beans Entity Bean Instances Are a View into a Database This means if you update the in-memory entity bean instance, the database should automatically be updated as well. (Synchronization) So there must be a mechanism to transfer information back and forth between the Java objects and the database. Entity bean class must implement two special methods, ejbStore and ejbLoad. ejbStore: saving bean instance’s current fields to the underlying data storage ejbLoad: reading data in from persistent storage into the entity bean’s in-memory fields

11 Features of Entity Beans The EJB container is in charge of the above methods invocations. This is one of the value-adds of the container.

12 Features of Entity Beans Several Entity Bean Instances May Represent the Same Underlying Data To facilitate many clients accessing the same data, one possibility is to allow many clients to share the same entity bean instance. Unfortunately, it is not very appropriate for EJB. First, writing thread-safe code is difficult and error prone. Second, having multiple threads of execution makes transactions almost impossible to control. All bean instances are single-threaded in EJB. (Session, Entity, Message-Driven)

13 Features of Entity Beans To boost performance, we could allow container to instantiate multiple instances of the same entity bean class so that many clients could concurrently interact with separate instances, each representing the same underlying entity data. Having multiple bean instances represent the same data, a new problem should be resolved: data corruption. Each entity bean instance needs to be routinely synchronized with the underlying storage. Transactions allow each client request to be isolated from every other request.

14 Instance 1 Instance 2 Instance 3 Storage the same underlying data transaction Client 1 Client 2 Client 3 the same entity bean class instances representing the same underlying data, such as back account (find the same ID) Container

15 Features of Entity Beans Entity Bean Instances Can Be Pooled The container may pool and reuse entity bean instances to represent different instances of the same type of data in an underlying storage. The container performs this by dynamically assigning the entity bean instance to different client-specific EJB objects. Entity bean class must implement two callback methods, ejbPassivate() and ejbActivate(). ejbActivate(): associating bean instance with a specific EJB object and a specific primary key, and required resource as well (socket)ejbLoad after activation ejbPassivate(): disassociating bean instance from a specific EJB object and a specific primary key, and required resource as well (socket) ejbStore() before passivation

16

17 Instance 1 Instance 2 Instance 3 Storage different rows in storage Client 1 Client 2 Client 3 the same entity bean class instances representing the different underlying data, such as back account (the same ID) Container

18 instance pool Client 1 Client 2 Client 3 Client 4 Bean Instance 1 Bean Instance 2 Bean Instance 3 data 1 data 2 data 3 data 4 poolSize=3

19 Features of Entity Beans Two ways to persist Entity Beans (2.x)  BMP (bean-managed persistence) We must write code to handle the persistent operations, including saving, loading, finding, creating and removing. (UPDATE, SELECT, INSERT, DELETE) JDBC API  CMP (container-managed persistence) The container perform the persistent operations for us. We could just inform the container about how we’d like to do by using SQL, or EJB QL.

20 Features of Entity Beans Creation and Removal of Entity Beans  ejbCreate() This method is responsible for creating database data. For each ejbCreate() defined in the bean class, we must define a corresponding ejbPostCreate() in the bean class and a corresponding create() in the home interface. We could define several overloaded ejbCreate() and create() methods if needed. Bean Class: (primary key  container) public AccountPK ejbCreate(String accountID, String owner) Home interface: (EJB object  client) public Account create(String accountID, String owner)

21 Create an Entity Bean

22 Creation and Removal of Entity Beans  ejbRemove() This method is responsible for removing database data. Note that, there is only one form of ejbRemove() method without any parameters. And ejbRemove() does not mean the in-memory entity bean instance is going to be destroyed, ejbRemove() destroys only database data. Both Home object and EJB object provide the remove() method which could be called by client. (See also: J2EE/EJB API)

23 Features of Entity Beans Entity Beans Can Be Found Because entity beans are permanent objects, they can be found rather than created. This is a great difference between session beans and entity beans. We can define the finder methods in our home interface. And the same as create() method, there should be the corresponding ejbFindXXX() methods in our bean class. Bean Class: ejbFindByBalance() Home interface findByBalance()

24 Entity Context All enterprise beans have a context object that identifies the environment of the bean. (SessionContext, EntityContext, MessageDrivenContext) EJBContext, EntityContext, setEntityContext() (See also: J2EE/EJB API) getEJBLocalObject()/getEJBObject() to retrieve the current,client-specific EJB object that is associated with the entity bean. getPrimaryKey() to retrieves the primary key that is currently associated with this entity bean instance. (ejbLoad(), ejbRemove())

25 Bean-Managed Persistent Entity Beans Entity Bean Coding Basics javax.ejb.EnterpriseBean javax.ejb.EntityBean

26 BMP Object Model

27 BMP Lifecycle

28 Entity Bean Coding Basics Required Methods in Entity Bean Class setEntityContext()ejbLoad() ejbFind ( )ejbStore() ejbHome ( )ejbRemove() ejbCreate( )ejbActivate() ejbPostCreate( )ejbPassivate() (See also: J2EE/EJB API or Table 6.1 Page 130) (Demo1: lec8/BMP/readme.txt) (Demo2: lec8/BMPMysql/readme.txt Deploy the third-party datasource:MySQL)

29 Entity Bean Configuration

30 Entity Bean Configuration

31 DataSource Configuration Tools --> Server Configuration

32 Resource Reference

33 Using Cloudscape Start server cloudscape –start Create Table cloudscape -isql < CreateTable.sql Stop server cloudscape –stop

34 Third-party Datasource: MySQL Register the database driver j2eeadmin -addJdbcDriver org.gjt.mm.mysql.Driver Set classpath Copy mysql-XXX-bin.jar to the directory below Modify %J2EE_HOME%\bin\userconfig.bat SET J2EE_CLASSPATH=%J2EE_HOME%\lib\system\mysql- connector-java bin.jar Deploy a datasource j2eeadmin -addJdbcDatasource jdbc/mysql jdbc:mysql://localhost:3306/test