Enterprise JavaBeans v2'0 - PowerPoint PPT Presentation

1 / 36
About This Presentation
Title:

Enterprise JavaBeans v2'0

Description:

The bean developer does not defined the bean properties, only the accessor methods ... functions in EJB QL with the same name in SQL, yet have different meanings ... – PowerPoint PPT presentation

Number of Views:33
Avg rating:3.0/5.0
Slides: 37
Provided by: slid9
Category:

less

Transcript and Presenter's Notes

Title: Enterprise JavaBeans v2'0


1
Enterprise JavaBeans v2.0
  • Overview of changes in the Enterprise JavaBeans
    Specification
  • Presented by Douglas WF Acheson
  • bea Canada Professional Services
  • July 25th, 2001

2
Agenda
  • Changes in the EJB Specification
  • New home methods
  • Local versus Remote Interfaces
  • New Hope for Container Managed Persistence
  • Container Managed Persistence Example
  • JMS Review
  • Message-Driven Bean (MD Beans) JMS and EJBs a
    New Relationship
  • MD Bean Example

3
Brief History
  • Suns entrance into the distributed component
    arena was through EJBs
  • v1.0 of EJB specification March 1998
  • v1.1 of EJB specification December 1999
  • v2.0 Proposed Final Draft late June 2001
  • Note this is only a draft of the final proposal
  • Changes may occur before the final publication

4
Changes in the EBJ Specification
  • Some of the significant changes in the
    specification, to date, are
  • Home Methods
  • Local and Remote Interfaces
  • An improved architecture for CMP including a
    query language
  • Message-Driven Beans

5
Home Methods for EJBs
  • New in v2.0 specification is the concept of Home
    methods
  • Provides an easy way to perform business logic
    that does not require actual instance of an EJB
  • Very few restrictions for home methods
  • Each method must throw java.rmi.RemoteException
  • Signature must not resemble a finder method or
    instance method
  • Can perform any business logic that does not
    involve the EJB instance

6
Local versus Remote Interfaces
  • The remote interface is the same concept as from
    previous specifications
  • Remote objects utilize Pass-By-Value
  • Location independent
  • Relies on Java RMI APIs
  • The local interface are new to v2.0 specification
  • Objects are co-located in the same JVM location
    dependent
  • Local objects utilize pass-by-reference
    (increases performance)
  • Tighter coupling between objects
  • Light-weight access to components

7
Local versus Remote InterfacesContinued
  • Example of using a local interface
  • A user requests services from EJB 1 which in turn
    require services from EJB 2

8
New Hope for Container Managed Persistence
  • Container Managed Persistence (CMP) allows the
    bean developer to concentrate more on business
    logic design and development
  • The bean developer is still responsible for
    defining the mapping between the bean properties
    and the persistent fields of the database
    (achieved through the deployment descriptor)
  • v2.0 of the specification does not solve complex
    O-R mapping requirements, but does allow for
    advanced object representation of relational
    stores
  • WebLogic Server supports this through the use of
    a Persistence Manager, which is part the the
    container

9
New Hope for Container Managed Persistence
Continued
  • v2.0 of the specification removes the concept of
    publicly accessible attributes and replaces them
    with accessor methods
  • All accessor methods are declared by the bean
    developer, not implemented by the bean developer
  • Each of the accessor methods are declared
    abstract
  • In addition, the bean is declared abstract
  • The bean developer does not defined the bean
    properties, only the accessor methods
  • For each bean attribute/property there is a
    corresponding declaration in the deployment
    descriptor

10
New Hope for Container Managed Persistence
Continued
  • Each field (property) of the bean must be
    declared as persistent field (CMP) or relational
    field (CMR)
  • Container Managed Persistence CMP
  • The ordinary single unit of data
  • Example age
  • Container Managed Relationship CMR
  • An aggregate collection of data (reference to
    another EJB or dependent entity object)
  • Example address

11
New Hope for Container Managed Persistence
Continued
  • Persisted fields are described in the ejb-jar.xml
    file
  • Persisted fields are mapped to database columns
    in the weblogic-cmp-rdbms-jar.xml file
  • Query logic for finder methods are located in the
    ejb-jar.xml file

12
EJB Query Language
  • New to the v2.0 specification is the introduction
    of the EJB Query Language (EJB QL)
  • EJB QL defines query methods for finder and
    select methods used by CMP entity beans
  • It is intended to be portable across EJB
    containers
  • Based on SQL92, however, it has been enhanced to
    allow querying or navigation over entity bean
    relationships
  • EJB QL works with objects whereas SQL works with
    tables
  • Application provider must do translation between
    EJB QL and SQL
  • EJB QL has some built in functions not as many as
    SQL

13
EJB Query Language Continued
  • EBJ QL contains functions that do not have
    equivalent methods in SQL
  • substring
  • concat
  • There exists functions in EJB QL with the same
    name in SQL, yet have different meanings
  • Outlined in the specification is the suggestion
    that the transformation from EJB QL to SQL be
    application vendors persistence manager
  • For complete list see the specification found on
    the JavaSoft web site

14
WLS Entity EJB Enhancements
  • Weblogic enhances the new Container Managed
    Entity Beans with new deployment descriptor
    directives
  • Able to load an entire EJB (graph) or part of the
    graph with a single query
  • This loading can be accomplished immediately via
    the finder methods or lazily on demand via
    accessor methods
  • The ltfield-groupgt tag allows data to be loaded
    together when any of the data is accessed
  • Read-mostly pattern now officially part of WLS
    v6.1
  • CMP beans need to be configured with a connection
    pool with gt 1 connections
  • WebLogic Server's CMP service may need to get two
    connections simultaneously

15
WLS Entity EJB Enhancements Continued
  • What is the Read-mostly pattern used by WLS
  • Under this pattern two versions of the same EJB
    are deployed
  • A read/write/transaction bean
  • A read-only/non-transactional bean
  • Any transaction is committed through a read/write
    cache
  • Once completed a multicast message is sent out to
    all read-only caches to invalidate the data
  • This allows synchronization of read/write and
    read caches

16
Container Managed Persistence Example
  • This example shows a dependant object
    relationship (1-1)

17
Container Managed Persistence Example Continued
  • Source Code for Customer Remote Interface
  • public interface Customer extends EJBObject
  • public String getName() throws RemoteException
  • public boolean isRegular() throws
    RemoteException
  • public boolean isPremium() throws
    RemoteException
  • public boolean isVIP() throws RemoteException
  • public Account getAccount() throws
    RemoteException
  • public void setAccount(Account a)
  • throws RemoteException

18
Container Managed Persistence Example Continued
  • In the ejbCreate set the non-dependent objects
  • In the ebjPostCreate set the dependent objects
  • public void ejbPostCreate(String name, int level)
    throws CreateException
  • setAccount(null)

19
Container Managed Persistence Example Continued
  • Accessor Methods used to define the bean
    attributes
  • public abstract String getName()
  • public abstract void setName(String name)
  • public abstract Account getAccount()
  • public abstract void setAccount(Account a)
  • public abstract int getLevelOfImportance()
  • public abstract void setLevelOfImportance(int
    val)

20
Container Managed Persistence Example Continued
  • ejb-jar.xml excepts
  • ltentitygt
  • ltejb-namegtCustomerEJBlt/ejb-namegt
  • ltpersistence-typegtContainerlt/persistence-typegt
  • ltreentrantgtFalselt/reentrantgt
  • ltcmp-versiongt2.xlt/cmp-versiongt
  • ltabstract-schema-namegtCustomerEBean
  • lt/abstract-schema-namegt
  • ltcmp-fieldgtltfield-namegtnamelt/field-namegt
  • lt/cmp-fieldgt
  • ltprimkey-fieldgtnamelt/primkey-fieldgt

21
Container Managed Persistence Example Continued
  • ejb-jar.xml excepts Continued
  • ltquerygt
  • ltquery-methodgt
  • ltmethod-namegtfindByImportancelt/method-namegt
  • ltmethod-paramsgt
  • ltmethod-paramgtintlt/method-paramgt
  • lt/method-paramsgt
  • lt/query-methodgt
  • ltejb-qlgt
  • lt!CDATAFROM CustomerEBean c WHERE
  • c.levelOfImportance gt ?1gt
  • lt/ejb-qlgt
  • lt/querygt
  • lt/entitygt

22
JMS Quick Review
  • November 1999 Sun release v1.0.2 of Java
    Messaging Service (JMS) specification
  • JMS is a set of interfaces and associated
    semantics that define how a JMS client accesses
    the facilities of an enterprise messaging product
  • JMS does not define how the JMS vender should
    implement the messaging system
  • BEA Weblogic Server, all version, provide JMS
    services as described by the JMS specifications

23
JMS Quick Review Continued
  • JMS supports both pub-sub (topic) and
    peer-to-peer (queue) message deliver mechanisms
  • JMS operations can be transaction ware

24
Message-Driven Beans
  • v2.0 of the specification introduces a new type
    of Enterprise JavaBeans Message-Driven Bean
    (MDBean)
  • Introduced to handle the processing of
    asynchronous requests
  • Theses beans are stateless and transaction-aware
  • MDBeans are consumers of JMS messages
  • The MD Beans have no home, remote, or local
    interfaces
  • All interaction is via the JMS through the
    container
  • Clients cannot invoke a MD Bean without a JMS
    message

25
Message-Driven Beans Continued
  • Benefits of Message-Driven Beans
  • Not bound to a JMS Queue or Topic like regular
    JMS consumers
  • Dynamic JMS binding via deployment descriptor
  • Inherits benefits of Enterprise Java Beans
  • Transaction Control
  • Memory Management
  • Security Integration
  • Drawbacks for Message-Driven Beans
  • Unable to listen on multiple JMS channels as
    regular JMS consumers are able

26
Message-Driven Beans Continued
  • To create a Message Driven Bean there are two
    interfaces that must be implemented
  • javax.ejb.MessageDrivenBean
  • javax.jms.messageListener
  • The javax.ejb.MessageDrivenBean has three methods
  • ejbCreate()
  • ejbRemove()
  • setMessageDrivenBeanContext(MessageDrivenBeanConte
    xt)
  • The javax.jms.messageListener
  • onMessage(Message)

27
Message-Driven Beans Continued
28
Message-Driven Beans Continued
29
Message-Driven Beans Example
  • An example of a Message-Driven Bean would be
    distributed logging

30
Message-Driven Beans Example Continued
  • Source Code
  • Public class Logger implements MessageDrivenBean,
  • MessageListener
  • private MessageDrivenContext ctx null
  • public void Logger()
  • public void ejbCreate()

31
Message-Driven Beans Example Continued
  • public void ejbRemove()
  • public void setMessageDrivenContext
  • (MessageDrivenContext
    ctx)
  • this.ctx ctx
  • public void onMessage(Message message)
  • // place logging code here

32
Message-Driven Beans Example Continued
  • ejb-jar file
  • ltejb-jargt
  • ltenterprise-beansgt
  • ltmessage-drivengt
  • ltejb-namegtLoggerlt/ejb-namegt
  • ltejb-classgtcom.bea.ug.Loggerlt/ejb-classgt
  • lttransactiongtcontainerlt/transactiongt
  • ltjms-acknowledge-modegt
  • auto-acknowledge
  • ltjms-acknowledge-modegt

33
Message-Driven Beans Example Continued
  • ejb-jar file continued
  • ltmessage-driven-destinationgt
  • ltjms-destination-typegt
  • javax.jms.Topic
  • lt jms-destination-typegt
  • lt/message-driven-destinationgt
  • lt/message-drivengt
  • lt/enterprise-beansgt
  • lt/ejb-jargt

34
Message-Driven Beans Example Continued
  • weblogic-ejb-jar file
  • ltweblogic-ejb-jargt
  • ltweblogic-enterprise-beangt
  • ltejb-namegtLoggerlt/ebj-namegt
  • ltmessage-driven-descriptorgt
  • ltmax-beans-in-free-poolgt10ltmax-beans-in-free
    -poolgt
  • ltintital-beans-in-free-poolgt10
  • ltinitial-beans-in-free
    -poolgt
  • ltdestination-jndi-namegtLoggerQueue
  • ltdestination-jndi-name
    gt
  • lt/message-driven-descriptorgt
  • lt/weblogic-enterprise-beangt
  • lt/weblogic-ejb-jargt

35
Resources
  • http//developer.java.sun.com/developer/technicalA
    rticles/ebeans/ejb20/index.html
  • http//www.javasoft.com/products/ejb/docs.html
  • http//www.theserverside.com/resources/index.jsp
  • http//edocs.bea.com

36
Questions and Answers
?
Write a Comment
User Comments (0)
About PowerShow.com