Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
14Activity
0 of .
Results for:
No results containing your search query
P. 1
ejb 3.0 pdf

ejb 3.0 pdf

Ratings:

4.0

(1)
|Views: 1,217|Likes:
Published by api-3750876

More info:

Published by: api-3750876 on Oct 16, 2008
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

05/09/2014

pdf

text

original

1
Enterprise JavaBeans 3.0
to be released in 2006
Jacek Ratzinger
Distributed Systems Group
Vienna University of Technology
Outline
\u25cf
Rational for Change
\u25cf
Concepts
\u2013Annotations
\u2013Dependency Injection
\u25cf
EJB types and their specifics
\u25cf
EJB-QL
\u2013standardize Hibernate?
\u25cf
Client Programming Model
\u25cf
Pros and Cons
Rational for Change
\u25cf
EJB 2.x has become overly complex
\u25cf
to many artifacts for developers
\u25cf
to many interfaces in EJB 2.x (home, ejb)
\u25cf
unnecessary exceptions, callback methods
\u25cf
no standard way to define a primary key
\u25cf
EJB 3.0 makes another attempt promise
reducing EJB's complexity for developers
\u25cf
simpler domain models with Plain Old Java
Objects (POJOs)
Drive for EJB 3.0
\u25cf
decrease number of artefacts
\u2013home interfaces and deployment descriptors
\u25cf
program annotations introduced in Java 5
\u25cf
light-weight domain modelling
\u2013including inheritance and polymorphism
\u25cf
configuration by exception
\u25cf
dependency injection
\u25cf
reduction of checked exceptions
\u25cf
testing outside the container
Java 5.0 Annotations
\u25cf
annotations do not directly affect program
semantics
\u25cf
can be inspected through source parsing or
by using the additional reflection APIs
\u25cf
define custom annotations
\u2013annotate fields, methods, classes, etc.
\u25cf
used to define

\u2013bean's business interface
\u2013O/R mapping information (specific persistence)
\u2013resource references
\u2013deployment information

Dependency Injection
\u25cf
beans may gain references to resources by
having the container supply it with those
\u25cf
bean instance variables or setter methods
are annotated as targets
\u25cf
standard way = annotations
\u25cf
alternatively, lookup method of
javax.ejb.EJBContext or the JNDI APIs
\u25cf
container responsibility: before use
2
Dependency Injection
\u25cf
annotation of instance variables
@Resource(name="myDB") //type inferred
public DataSource customerDB;
\u25cf
setter injection
public DataSource customerDB;
@Resource(name=\u201d myDB\u201d)
public void setDataSource(DataSource myDB
this. customerDB = myDB;
}
Specifics of EJB 3.0
\u25cf
Exceptions

\u2013interface may declare arbitrary exceptions
\u2013should not throw java.rmi.RemoteException
\u2013EJBException thrown by the container

\u25cf
Callbacks and Callback Listener Classes
\u2013no callbacks (e.g. ejbCreate(), ejbPassivate) for
life cycle events required
\u2013method annotations for callbacks
\u2013callback listener class may be used instead of
callback methods
Entity Beans
\u25cf
POJOs with annotation@Entity
\u25cf
all fields persistent not marked with
@Transient (configuration by exception)
\u25cf
persistent once it is associated with an
EntityManager (em.persist(entity))
\u25cf

approach: refer with annotations to concrete
tables/columns instead of the abstract
persistence schema

Entity Beans
\u25cf
unidirectional and bidirectional relationships
attributes of annotations

\u2013one-to-one
\u2013one-to-many
\u2013many-to-one
\u2013many-to-many

\u25cf
owning side responsible for propagating
relationship changes to database
Sample Entity Bean
@Entity public class Employee {
@Id(generate=GeneratorType.TABLE)
public Long getId() { return id;}
public Address getAddress() {
return address;}
@OneToMany(mappedBy=\u201cleader\u201d)
public List<Employee> getTeamMembers() {
return this.colleagues;}
@Transient private void getFullName() {
return getFirstName() + getLastName()}
EJB QL
\u25cf
EntitiyManager API similar to Hibernate and
Toplink
\u2013persist(entity), find(Entity.class, id)
\u2013createQuery(ejbqlString),
createNativeQuery(sqlString)
\u25cf
EJB QL Examples
\u2013
FROM Order order
\u2013
SELECT DISTINCT order.address.state FROM Order
order WHERE order.customer.name LIKE ?
\u2013
SELECT order FROM Order order INNER JOIN FETCH
order.customer
3
Enhancements to EJB QL
\u25cf
explicit inner and outer join
\u25cf
fetch join for eager loading (default=lazy)
\u25cf
bulk update and delete
\u25cf
subqueries
\u25cf
group-by
\u25cf
support for native SQL queries
\u25cf
dynamic query capability
Stateless Session Beans
\u25cf
plain Java object with a class-level
annotation of@Stateless
\u25cf
can implement the javax.ejb.SessionBean
interface, but is not required to
\u25cf
may implement a business interface
\u2013If no business interface implemented, generated
using all the public methods
\u25cf
@BusinessMethodby default local
\u2013@Remoteindicates a remote interface
Sample Stateless Session Bean
import javax.ejb.*;

@Stateless
@Remote
public class HelloWorldBean {

public String sayHello() {
return "Hello World";
}
}
Web Services Session Beans
\u25cf
JSR-181
\u25cf
a session bean that serves as a web service
endpoint is annotated with@WebService
\u25cf
@WebMethod used to identify methods that
are exposed as web service
\u25cf
other annotations
\u2013@WebParam, @WebResult, @OneWay,
@SOAPBinding, @SOAPMessageHandler,
@HandlerChain, @InitParam
Stateful Session Beans
\u25cf
similar to Stateless
\u25cf
lifecycle event callbacks

\u2013@PostConstruct: after dependency injection
\u2013@PreDestroy: after method with @Remove
\u2013@PostActivate: equal to ejbActivate()
\u2013@PrePassivate: equal to ejbPassivate()

\u25cf
a callback listener class (@CallbackListener)
may be used instead of callback methods
Sample Stateful Session Bean
@Stateful

public class AccountManagementBean {
@EJB (name="mySessionBean") //dependency injection
private MySessionI myBean;
private Socket socket;

@PostConstruct
@PostActivate
public void initRemoteConnectionToAccountSystem() {

try {
this.socket = new Socket, PORT);}
catch (Exception ex) {throw new EJBException(ex);}
}...

Activity (14)

You've already reviewed this. Edit your review.
1 hundred reads
1 thousand reads
Harsh Save liked this
gori_994323 liked this
AzimZahir liked this
Cao Dũng liked this
mazazahmed liked this
vijaykumar015 liked this

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->