EJB 2.0 : An Overview - PowerPoint PPT Presentation

Loading...

PPT – EJB 2.0 : An Overview PowerPoint presentation | free to download - id: 2b265-YzJlM



Loading


The Adobe Flash plugin is needed to view this content

Get the plugin now

View by Category
About This Presentation
Title:

EJB 2.0 : An Overview

Description:

All 1.1 code should still deploy correctly. ... Formerly developer provided a description of what the finder methods should do. ... – PowerPoint PPT presentation

Number of Views:168
Avg rating:3.0/5.0
Slides: 46
Provided by: vbhar
Learn more at: http://www.csee.wvu.edu
Category:
Tags: ejb | code | finder | overview | zip

less

Write a Comment
User Comments (0)
Transcript and Presenter's Notes

Title: EJB 2.0 : An Overview


1
EJB 2.0 An Overview
  • CS486
  • Spring 2001
  • Vijayanand Bharadwaj

2
Overview
  • EJB Evolution (0.0 to 2.0)
  • EJB What do we know so far ?
  • Whats new in EJB 2.0 ?
  • Some Newer Features in EJB 2.0
  • Analysis of EJB 2.0 the good and the bad.
  • Conclusion and References

3
Remarks
  • References Primary -- class text.
  • also Suns Java site and articles
  • marked throughout as reference and list
    available at the end.

4
EJB Evolution (0.0 to 2.0) 3
  • EJB specification release
  • EJB 1.0 -- March 24th 1998
  • EJB 1.1 -- May 1999 time frame
  • EJB 2.0 -- June 2nd 2000 ( final draft)
  • Significant changes made between 1.0 and 1.1
  • However EJB 1.1 totally compatible with 2.0.
    Nothing deprecated . All 1.1 code should still
    deploy correctly.
  • Industry forecasts for EJB 2.0 4 Supposed to
    enhance portability and flexibility, along with
    tightening some older features. Lets see……...

5
So far along the EJB trail……..
  • EJB What do we know so far ..? 156.
  • Applications
  • Building portable software components which can
    run business logic on an Enterprise level.
  • Concept What is an EJB (Enterprise Java Bean)?
  • A software component which allows a developer to
    encapsulate business logic, freeing him/her from
    system level development concerns such as
    transactions, threading ,load balancing etc.

6
So far along the EJB trail……..
  • Anatomy and Working of an EJB

App Server
Container
Skeleton
EJB
Stub
Client
Network
HOME
REMOTE
STORE
7
So far along the EJB trail……..
  • Types of EJB

EJB
?????
Based on Main Purpose, Callback,
Runtime lifecycles
ENTITY BEANS
SESSION BEANS
Maintain state across methods
STATEFUL SB
STATELESS SB
Relationship to database
managed by
BMP EB
CMP EB
8
EJB 2.0 Whats new ?
  • Areas in which EJB 2.0 has something new to offer
    17
  • 1. Container managed Persistence
  • 2. EJB Query Language
  • 3. Message-Driven Beans
  • 4. Business methods in the Home interface
  • 5. Improved interoperability
  • Say how we divide
  • Explain briefly each one EJB What do we know so
    far ?

9
EJB 2.0 Whats new ?
  • New type of Container-Managed Persistence which
    deals with the drawbacks of the CMP model of
    version 1.1.
  • Standard query language for CMP. Formerly
    developer provided a description of what the
    finder methods should do . Deployer provided the
    actual query according tot he target Application
    Server. Advantages of EJB QL
  • Query need be developed and tested only once (
    not at each new environment)
  • Developer can do it .More suited for the purpose.

10
EJB 2.0 Whats new ?
  • Integration of EJB with Java Message Service
    (JMS). Container on arrival of a JMS message
    invokes a message-driven bean. Need not create
    a separate front-end for messages.
  • Business methods in the home interface work
    support functionality independent of any entity--
    can operate on a set of beans of an entity type.
    ( rather than in a separate session bean as in
    1.1)
  • Both the above features allow better modularity
    and design.
  • An interoperability protocol based on RMI/IIOP
    and CORBA to allow J2EE applications on different
    app servers to interact without bean developer
    intervention

11
EJB 2.0 Whats new ?
  • This discussion will cover two aspects
  • CMP in EJB 2.0
  • Business methods in the home Interface
  • The remaining will be covered by our colleague

12
EJB 2.0 Some New Features
  • Container Managed Persistence 4
  • Reviewing CMP in version 1.1
  • Bean developer responsible for declaring the
    persistent fields in the bean class.
  • On an RDBMS primitive types(String, integer etc)
    map easily to their corresponding types
  • Tell the container through the deployment
    descriptor (DD). The tags identify
    such fields.
  • Generally container tools allow you to map.

13
EJB 2.0 Some New Features
  • Container Managed Persistence 4
  • An example from EJB 1.1
  • // the Employee bean class public class
    EmployeeBean implements java.ejb.EntityBean
    // instance fields EntityContext ejbContext
    // container-managed fields public int identity
    public String firstName public String
    lastName public double salary public Address
    address //refers to dependent
  • CONTINUED…..

14
EJB 2.0 Some New Features
  • Container Managed Persistence 4
  • public Integer ejbCreate(int id, String fname,
    String lname) identity id firstName
    fname lastName lname return null ...
    // The Address dependent class public class
    Address implements Serializable public String
    street public String city public String
    state public String zip

15
EJB 2.0 Some New Features
  • Container Managed Persistence 4
  • Deployment Descriptor --version 1.1 (sample)

  • EmployeeEJB ...
    Container
    ... identity
    firstNameeld-name last
    Name amesalary
    addressfield ...

16
EJB 2.0 Some New Features
  • Container Managed Persistence 4
  • Drawbacks of 1.1
  • No standard mechanism to map serializable objects
    such as Address . Generally stored as a blob.
  • For entity beans with a large schema problem
    grows. As an entity bean may have many dependent
    objects which in turn have dependent objects
    forming complex graphs.
  • Entity bean to Entity bean relationship support
    not adequate. Since it always uses the other EBs
    primary key as a link. Relationships are not
    always based on the primary key.

17
So far along the EJB trail……..
EJB 2.0 Some New Features
  • Container Managed Persistence 4
  • EJB 2.0 CMP

App Server
Container
Persistence Manager
EJB
HOME
REMOTE
STORE
18
EJB 2.0 Some New Features
  • Container Managed Persistence 4
  • EJB 2.0 CMP Features
  • Allows you to define complex bean-to bean, bean
    to dependent object and dependent to dependent
    object relationships.
  • Done with the help of new PERSISTENCE MGR
  • Contract between container and Persistence Mgr.
  • Contract known as Abstract Schema has two parts
  • Additional XML tags in DD
  • Code idioms (Rules for coding the bean )
  • Rule) The bean class is declared abstract and all
    persistent and relationship fields are accessed
    using abstract accessor and mutator methods whose
    signatures map to special elements in the DD

19
EJB 2.0 Some New Features
  • Container Managed Persistence 4
  • EJB 2.0 CMP Features

How can you use an abstract bean class? After all
… you have to extend an abstract class in Java
and implement its methods to use it ……. The
client cant do that…..how ???
Java Geek !
20
EJB 2.0 Some New Features
  • Container Managed Persistence 4
  • EJB 2.0 CMP Features ( figure from reference4)

PM does it !!
21
EJB 2.0 Some New Features
  • Container Managed Persistence 4
  • EJB 2.0 CMP Features Same Example now…..
  • public abstract EmployeeBean implements
    javax.ejb.EntityBean // instance fields
    EntityContext ejbContext // container-managed
    persistent fields public abstract void
    setIdentity(int identity) public abstract int
    getIdentity() public abstract void
    setFirstName(String firstName) public abstract
    String getFirstName() public abstract void
    setLastName(String lastName) public abstract
    String getLastName()
  • // container-managed relationship fields public
    abstract void setContactInfo(ContactInfo info)
    public abstract ContactInfo getContactInfo()
    ...

22
EJB 2.0 Some New Features
  • Container Managed Persistence 4
  • A dependent object ( class)………..
  • public abstract class ContactInfo // home
    address info public abstract void
    setStreet(String street) public abstract String
    getStreet() public abstract void
    setState(String state) public abstract String
    getState() public abstract void setZip(String
    zip) public abstract String getZip() public
    abstract void setHomePhone(String phone) public
    abstract String getHomePhone() // work address
    info public abstract void setWorkPhone(String
    phone) public abstract String getWorkPhone()
    public abstract void setEMail(String email)
    public abstract String getEMail() ...

23
EJB 2.0 Some New Features
  • Container Managed Persistence 4
  • About dependent classes………..
  • They form relationships with entity beans
  • live and die along with the entity bean
  • only visible to the bean class and not the client
  • Bean class must have additional methods to expose
    dependent objects to the client since they are
    not suitable remote arguments.
  • Looking at an example …...

24
EJB 2.0 Some New Features
  • Container Managed Persistence 4
  • Remote Interface for Employee bean……….
  • // remote interface for the Employee bean public
    interface Employee extends javax.ejb.EJBObject
    public Address getHomeAddress()//Note this !
    public void setHomeAddress(Address address)
    public int getIdentity() throws
    RemoteException public void setFirstName(String
    firstName) throws RemoteException public String
    getFirstName()throws RemoteException public
    void setLastName(String lastName) throws
    RemoteException public String getLastName()
    throws RemoteException

25
EJB 2.0 Some New Features
  • Container Managed Persistence 4
  • Corresponding implementation in bean class,……
  • // bean class for the Employee bean public
    abstract EmployeeBean implements
    javax.ejb.EntityBean ... public Address
    getHomeAddress() ContactInfo info
    getContactInfo() Address addr new Address()
    addr.street info.getStreet() addr.city
    info.getCity() addr.state info.getState()
    addr.zip info.getZip() return addr
    CONTINUED…...

26
EJB 2.0 Some New Features
  • Container Managed Persistence 4
  • Corresponding implementation in bean class,……
  • public void setHomeAddress(Address addr)
    ContactInfo info getContactInfo()
    info.setStreet(addr.street) info.setCity(addr.c
    ity) info.setState(addr.state)
    info.setZip(addr.zip) .... //
    container-managed relationship fields public
    abstract void setContactInfo(ContactInfo info)
    public abstract ContactInfo getContactInfo()
    ...

27
EJB 2.0 Some New Features
  • Coding Relationships
  • Entity Bean to Dependent Object (one-one or
    one-many) eg Employee bean is related to one
    benefit but has many contacts.
  • public abstract EmployeeBean implements
    javax.ejb.EntityBean ... public abstract void
    setContactInfos(Collection addresses) public
    abstract Collection getContactInfos() public
    abstract void setBenefit(Benefit benefit)
    public abstract Benefit getBenefit() ...
  • Use Collections to get many dependent objects

28
EJB 2.0 Some New Features
  • Coding Relationships
  • Entity Bean to Entity Bean (one-one or one-many
    or many to many) eg Employee bean is related to
    one Spouse but has many Children ( Both are
    Person beans).
  • public abstract EmployeeBean implements
    javax.ejb.EntityBean ... public abstract void
    setSpouse(Person manager) public abstract
    Person getSpouse() public abstract void
    setChildren(Collection family) public abstract
    Collection getChildren() ...
  • Use Collections to get at many Entity Beans.

29
EJB 2.0 Some New Features
  • Coding Relationships
  • Dependent Object to Dependent Object ( or another
    entity bean) (one-one or one-many or many to
    many) eg Benefit object is related to one Salary
    and many Investment objects
  • public abstract class Benefit public abstract
    void setSalary(Salary salary) public abstract
    Salary getSalary() public abstract void
    setInvestments(Collection investments) public
    abstract Collection getInvestments()

30
EJB 2.0 Some New Features
  • Deployment Descriptor

  • EmployeeEJB ...
    Container
    ... identity
    firstNameeld-name last
    Name ...
  • CONTINUED………..

31
EJB 2.0 Some New Features
  • Deployment Descriptor
  • Conta
    ctInfo ContactI
    nfo street city statecmp-field zip
    homePhone
    workPhone
    email ...
  • CONTINUED………..

32
EJB 2.0 Some New Features
  • Deployment Descriptor

  • Employee-ContactInfotion-name
    employee-has-contac
    tinfo
    one
    EmployeeEJB
    contactInfold-name ContactInfoype
    CONTINUED………..

33
EJB 2.0 Some New Features
  • Deployment Descriptor……..

  • contactinfo_belongs
    to_employee
    one
    ContactInfo


34
EJB 2.0 Some New Features
  • Business methods in the home interface 8 Let us
    consider operations on multiple entity beans.
  • For Example deleting unused shopping cart
    entity beans
  • Could be done using finder methods or session
    beans
  • Using finder methods implies moving a business
    function ( deletion)(to the client --not the best
    design
  • Session beans --problems in maintenance as you
    have to add such function to existing session
    bean or write another bean which results in extra
    beans --tedious.

35
EJB 2.0 Some New Features
  • Business methods in the home interface
    (continued)
  • Version 2.0 allows you to add business in the
    home interface. Not associated with any one
    particular instance of the entity bean.
  • To define a Home method, just add it to your
    Home interface. The only restriction on the
    method name is that it can't start with find,
    create, or remove.

36
EJB 2.0 Some New Features
  • Business methods in the home interface
    (continued)
  • For example, the method to expire shopping
    carts might be declared this way
  • public void expireShoppingCarts() throws
    RemoteException
  • When you implement a Home method, put ejbHome in
    front of the method name in your implementation
    class. For example,
  • public void ejbHomeExpireShoppingCarts()

37
EJB 2.0 Some New Features
  • Business methods in the home interface
    (continued)
  • public interface EmployeeHome extends
    javax.ejb.EJBHome // a home method public
    void applyCola(double increate) throws
    RemoteException ...

38
EJB 2.0 Some New Features
  • Business methods in the home interface
    (continued)
  • public abstract class EmployeeBean implements
    javax.ejb.EntityBean ... // ejbHome method
    public void ejbHomeApplyCola (double increase )
  • Collection col ejbSelectAllEmployees ()
    Iterator employees col.iterator()
    while(employees.next()) ………………………………………….

39
EJB 2.0 Analysis
  • Advantages of EJB 2.0 features !!
  • Complex schemas involving relationships among
    entity beans and dependent objects can be
    depicted with the help of persistence
    manager.Closer to intuition and better database
    design and use.
  • Business methods in the home interface provide
    option for better design by isolating business
    logic completely within the entity.
  • Entity beans can communicate using JMS at the
    business logic level itself --one more for better
    design !
  • New EJB QL makes standardized query possible and
    relives deployer ! Helps in correct creation of
    finder method queries.
  • Tightened some unresolved issues of 1.1

40
EJB 2.0 Analysis
  • SO EVERYBODY HAPPY... END OF STORY !!!!

41
EJB 2.0 Analysis
  • NOT SO FAST ! !

Im not quite satisfied … . . . . . Not all is
o.k with EJB 2.0 ! !
Another Java Geek !
42
EJB 2.0 Analysis
  • Whats wrong with EJB 2.0 Specification ? by
    Tyler Jewell , February 28th 2001 9
  • An article on the OReilly Network
  • This article lists a few reasons--why things are
    not alright
  • dependent objects.
  • Lack of support for fine grained objects
  • Some other inconsistencies.
  • Also new suggestions not implemented by
  • container vendors.
  • Suggests the removal of
  • dependent objects completely !!

43
References
  • 1 Professional Java Server Programming J2EE
    edition. (Wrox Press Ltd. ) September 2000.
    Chapters 18,19,20,23
  • 2 The EJB home page at Sun Microsystems
  • http//java.sun.com/products/ejb/
  • 3 http//java.sun.com/products/ejb/news.html
  • 4 Monson-Haefel R. Read all about EJB 2.0 An
    article. http//www.javaworld.com/javaworld/jw-06-
    2000/jw-0609-ejb.html
  • 5EJB fundamentals short course by JGuru
    http//developer.java.sun.com/developer/onlineTrai
    ning/EJBIntro/EJBIntro.html
  • CONTINUED…..

44
Conclusion and References
  • 6Johnson M. A beginner's guide to Enterprise
    JavaBeans .(article) http//www.javaworld.com/jav
    aworld/jw-10-1998/jw-10-beans.html
  • 7EJB 2.0 specification
  • http//java.sun.com/products/ejb/docs.html
  • 8 Wutka. M, Whats new in EJB 2.0( article)
  • http//www.informit.com
  • 9Jewell T. Whats wrong with the EJB 2
    Specification?. (Article) . The OReilly
    network. http//onjava.com/pub/a/onjava/2001/02/28
    /ejb.html
  • ---------------------------------------------
    -------------------------------

45
THANK YOU
  • Questions , Comments, Criticisms may be sent to
  • vijay_at_csee.wvu.edu
  • vanandb_at_hotmail.com
About PowerShow.com