Enterprise JavaBeans 3'0 to be released in 2006 - PowerPoint PPT Presentation

1 / 22
About This Presentation
Title:

Enterprise JavaBeans 3'0 to be released in 2006

Description:

no standard way to define a primary key. EJB 3.0 makes another attempt promise reducing EJB's ... vendor specific annotations defeats the goal of portability ... – PowerPoint PPT presentation

Number of Views:23
Avg rating:3.0/5.0
Slides: 23
Provided by: infosysT
Category:

less

Transcript and Presenter's Notes

Title: Enterprise JavaBeans 3'0 to be released in 2006


1
Enterprise JavaBeans 3.0to be released in 2006
  • Jacek Ratzinger
  • Distributed Systems Group
  • Vienna University of Technology

2
Outline
  • Rational for Change
  • Concepts
  • Annotations
  • Dependency Injection
  • EJB types and their specifics
  • EJB-QL
  • standardize Hibernate?
  • Client Programming Model
  • Pros and Cons

3
Rational for Change
  • EJB 2.x has become overly complex
  • to many artifacts for developers
  • to many interfaces in EJB 2.x (home, ejb)
  • unnecessary exceptions, callback methods
  • no standard way to define a primary key
  • EJB 3.0 makes another attempt promise reducing
    EJB's complexity for developers
  • simpler domain models with Plain Old Java Objects
    (POJOs)

4
Drive for EJB 3.0
  • decrease number of artefacts
  • home interfaces and deployment descriptors
  • program annotations introduced in Java 5
  • light-weight domain modelling
  • including inheritance and polymorphism
  • configuration by exception
  • dependency injection
  • reduction of checked exceptions
  • testing outside the container

5
Java 5.0 Annotations
  • annotations do not directly affect program
    semantics
  • can be inspected through source parsing or by
    using the additional reflection APIs
  • define custom annotations
  • annotate fields, methods, classes, etc.
  • used to define
  • bean's business interface
  • O/R mapping information (specific persistence)
  • resource references
  • deployment information

6
Dependency Injection
  • beans may gain references to resources by having
    the container supply it with those
  • bean instance variables or setter methods are
    annotated as targets
  • standard way annotations
  • alternatively, lookup method of
    javax.ejb.EJBContext or the JNDI APIs
  • container responsibility before use

7
Dependency Injection
  • annotation of instance variables
  • _at_Resource(name"myDB") //type inferred
  • public DataSource customerDB
  • setter injection
  • public DataSource customerDB
  • _at_Resource(name myDB)
  • public void setDataSource(DataSource myDB
  • this. customerDB myDB

8
Specifics of EJB 3.0
  • Exceptions
  • interface may declare arbitrary exceptions
  • should not throw java.rmi.RemoteException
  • EJBException thrown by the container
  • Callbacks and Callback Listener Classes
  • no callbacks (e.g. ejbCreate(), ejbPassivate) for
    life cycle events required
  • method annotations for callbacks
  • callback listener class may be used instead of
    callback methods

9
Entity Beans
  • POJOs with annotation _at_Entity
  • all fields persistent not marked with _at_Transient
    (configuration by exception)
  • persistent once it is associated with an
    EntityManager (em.persist(entity))
  • approach refer with annotations to concrete
    tables/columns instead of the abstract
    persistence schema

10
Entity Beans
  • unidirectional and bidirectional relationships
    attributes of annotations
  • one-to-one
  • one-to-many
  • many-to-one
  • many-to-many
  • owning side responsible for propagating
    relationship changes to database

11
Sample Entity Bean
  • _at_Entity public class Employee
  • _at_Id(generateGeneratorType.TABLE)
  • public Long getId() return id
  • public Address getAddress()
  • return address
  • _at_OneToMany(mappedByleader)
  • public ListltEmployeegt getTeamMembers()
  • return this.colleagues
  • _at_Transient private void getFullName()
  • return getFirstName()
    getLastName()

12
EJB QL
  • EntitiyManager API similar to Hibernate and
    Toplink
  • persist(entity), find(Entity.class, id)
  • createQuery(ejbqlString), createNativeQuery(sqlStr
    ing)
  • EJB QL Examples
  • FROM Order order
  • SELECT DISTINCT order.address.state FROM Order
    order WHERE order.customer.name LIKE ?
  • SELECT order FROM Order order INNER JOIN FETCH
    order.customer

13
Enhancements to EJB QL
  • explicit inner and outer join
  • fetch join for eager loading (defaultlazy)
  • bulk update and delete
  • subqueries
  • group-by
  • support for native SQL queries
  • dynamic query capability

14
Stateless Session Beans
  • plain Java object with a class-level annotation
    of _at_Stateless
  • can implement the javax.ejb.SessionBean
    interface, but is not required to
  • may implement a business interface
  • If no business interface implemented, generated
    using all the public methods
  • _at_BusinessMethod by default local
  • _at_Remote indicates a remote interface

15
Sample Stateless Session Bean
  • import javax.ejb.
  • _at_Stateless
  • _at_Remote
  • public class HelloWorldBean
  • public String sayHello()
  • return "Hello World"

16
Web Services Session Beans
  • JSR-181
  • a session bean that serves as a web service
    endpoint is annotated with _at_WebService
  • _at_WebMethod used to identify methods that are
    exposed as web service
  • other annotations
  • _at_WebParam, _at_WebResult, _at_OneWay, _at_SOAPBinding,
    _at_SOAPMessageHandler, _at_HandlerChain, _at_InitParam

17
Stateful Session Beans
  • similar to Stateless
  • lifecycle event callbacks
  • _at_PostConstruct after dependency injection
  • _at_PreDestroy after method with _at_Remove
  • _at_PostActivate equal to ejbActivate()
  • _at_PrePassivate equal to ejbPassivate()
  • a callback listener class (_at_CallbackListener) may
    be used instead of callback methods

18
Sample Stateful Session Bean
  • _at_Stateful
  • public class AccountManagementBean
  • _at_EJB (name"mySessionBean") //dependency
    injection
  • private MySessionI myBean
  • private Socket socket
  • _at_PostConstruct
  • _at_PostActivate
  • public void initRemoteConnectionToAccountS
    ystem()
  • try
  • this.socket new Socket,
    PORT)
  • catch (Exception ex) throw new
    EJBException(ex)
  • ...

19
Message-driven Beans
  • to a client, a message-driven bean is a message
    consumer
  • message-listener business interface determined
    by the messaging type in use
  • javax.jms.MessageListener for JMS

20
Bean Interfaces
  • session beans and message-driven beans require a
    business interface
  • interfaces automatically generated from
    implementation, if no interface implemented
  • interface name derived from class name
  • if several interfaces implemented, annotation
    required to define the business interface
  • interfaces assumed local unless annotated

21
Client Programming Model
  • EJB 3.0 remote or local clients access beans
    through their business interface
  • business interfaces are ordinary Java interfaces
  • references to business interfaces through
  • injection mechanism
  • javax.ejb.EJBContext.lookup()
  • JNDI API

22
Pros and Cons
  • less artefacts for developers
  • enterprise services for Java core (e.g.JBoss)
  • EJB 3.0 compliant desktop application?
  • contrary to annotations provide deployment
    descriptors a holistic view to EJB modules
  • vendor specific annotations defeats the goal of
    portability
  • dont forget about configuration by exception
  • entity beans owning side defined by dependent
    sidegt less complexity?
Write a Comment
User Comments (0)
About PowerShow.com