Enterprise Java Beans 3.0
Upcoming SlideShare
Loading in...5
×
 

Enterprise Java Beans 3.0

on

  • 10,571 views

 

Statistics

Views

Total Views
10,571
Views on SlideShare
10,511
Embed Views
60

Actions

Likes
13
Downloads
867
Comments
1

9 Embeds 60

http://www.slideshare.net 33
http://www.linkedin.com 7
http://www.techiegyan.com 6
http://www.jugmilano.it 4
https://www.linkedin.com 4
http://192.168.6.52 3
http://simplyauser.pbwiki.com 1
http://www.itspice.com 1
http://10.150.250.21 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • Nice one for EJB 3.0 overview.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Enterprise Java Beans 3.0 Enterprise Java Beans 3.0 Presentation Transcript

  • Enterprise Java Bean 3.0 Filippo Diotalevi http://www.diotalevi.com filippo.diotalevi@jugmilano.it Java User Group Milano http://www.jugmilano.it February 16th, 2006
  • Filippo Diotalevi http://www.diotalevi.com/weblog https://java-champions.dev.java.net/ http://www.jugmilano.it JUG Milano – EJB 3.0 3
  • Tag-Cloud StatelessSessionBean ResourceInjection EnterpriseJavaBeans StatefulSessionBean EntityBean POJO MessageDrivenBean JavaEE5 Annotations JavaPersistenceAPI Glassfish JUG Milano – EJB 3.0 4
  • JavaEE5 Goals • EOD – Easy of Development • Increase productivity • Full backward compatibility • Community involvement ResourceInjection Tools: POJO Annotations JUG Milano – EJB 3.0 5
  • JavaEE5: Key new Specs • Java Persistence API (JSR-220) • EJB 3.0 (JSR-220) • JavaServer Faces (JSR-252) • JAX-WS (JSR-224) • JAXB (JSR-222) • Common Annotations (JSR-250) • StAX (JSR-173) JUG Milano – EJB 3.0 6
  • EJB History EJB 1.1 ( J2EE 1.2 ), 1999 • Session beans (stateless & stateful), Entity Beans • Remote interface EJB 2.0 ( J2EE 1.3 ), 2001 • Message-Driven Beans • Entity 2.x and EJB QL • Local and Remote interfaces EJB 2.1 ( J2EE 1.4 ) 2003 • EJB Timer Service • Minor EJB QL enhancements JUG Milano – EJB 3.0 7
  • EJB 2.x Problems • “Noisy” • Metadata XML Hell • Difficult test • Not truly OO • Pattern proliferation (DTO, Service Locator, ...) JUG Milano – EJB 3.0 8
  • EJB 3: Solutions • POJO Model • Annotations • “Configuration by exception” • Java Persistence API JUG Milano – EJB 3.0 9
  • @Stateless Session Bean • No more Home interfaces! • A POJI Business Interface (optional!) Annotated with @Remote or @Local • A POJO Implementation Annotated with @Stateless • No more deployment descriptors! (optional) JUG Milano – EJB 3.0 10
  • @Stateless Session Bean public interface Calculator @Remote { @Local public int sum(int a, int b); ..or default (@Local) } @Stateless public class CalculatorImpl implements Calculator { public int sum(int a, int b) { return a + b; } } JUG Milano – EJB 3.0 11
  • Transaction Management @Stateless public class CalculatorImpl implements Calculator { @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) public int sum(int a, int b) { //.... } TransactionAttributeType.MANDATORY TransactionAttributeType.REQUIRED TransactionAttributeType.REQUIRES_NEW TransactionAttributeType.SUPPORTS TransactionAttributeType.NOT_SUPPORTED TransactionAttributeType.NEVER JUG Milano – EJB 3.0 12
  • @Stateful Session Bean • No more Home interfaces! • A POJI Business Interface (optional!) Annotated with @Remote or @Local • A POJO Implementation Annotated with @Stateful • No more deployment descriptors! (optional) JUG Milano – EJB 3.0 13
  • @Stateful Session Bean @Local public interface CounterEjb { public int count(); public void reset(); } @Stateful public class CounterEjbImplementation implements CounterEjb { private int count = 0; public int count() { return ++count; } public void reset() { count = 0; } } JUG Milano – EJB 3.0 14
  • Other features Callback methods @PostConstruct @PostActivate @PrePassivate @PreDestroy @Interceptors Declare interceptor classes (@Interceptors) Develop an interceptor (POJO!) Annotate interceptor's methods with @AroundInvoke JUG Milano – EJB 3.0 15
  • EJB Invocation & dependency injection public class CountServlet extends HttpServlet{ @EJB public CounterEjb counter; protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException,IOException { counter.count(); } } Dependency injection can only be used by managed classes Servlet, listener classes, web services end-point, JAX-RPC handlers, EJB, interceptors, web services end-point JUG Milano – EJB 3.0 16
  • Java Persistence API • Separate specification document • Produced by EJB 3.0 EG (JSR-220) • Available in & outside the Java EE container JUG Milano – EJB 3.0 17
  • @Entity Beans • No more Home interfaces! • No Business Interfaces! • A POJO Implementation Annotated with @Entity • A simple deployment descriptor JUG Milano – EJB 3.0 18
  • @Entity Beans @Entity public class Item implements Serializable{ private Long id; Id auto generation private String name; Primary Key @Id @GeneratedValue(strategy = GenerationType.AUTO) public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getName() { return name;} public void setName(String name) { this.name = name; } } (if not transient) Properties are automatically persisted JUG Milano – EJB 3.0 19
  • EntityManager • A detyped “home” interface • create(), merge() and remove() instances • Factory for Query JUG Milano – EJB 3.0 20
  • EntityManager @Stateless public class PaginaDAOImpl implements PaginaDAO { @PersistenceContext EntityManager entityManager; public void salva(Pagina pagina) { EntityManager injected! entityManager.merge(pagina); } public void elimina(Pagina pagina) { entityManager.remove(pagina); } public Pagina leggi(String titolo) { Pagina p = entityManager.find(Pagina.class, titolo); } JUG Milano – EJB 3.0 21
  • @PersistenceContext ? persistence context as quot;a set of entity instances in which - for any persistent entity identity -there is a unique entity instance.quot; A persistence unit is persistence unit #2 a set of classes that are mapped to a single data store JUG Milano – EJB 3.0 22
  • Query Query query = entityManager.createQuery(quot;SELECT p FROM Pagina pquot;); return query.getResultList(); • Query parameters • Support for pagination • Native query entityManager.createNativeQuery() JUG Milano – EJB 3.0 23
  • Deployment Descriptor Need to define the Persistence Unit in persistence.xml <?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?> <persistence xmlns=quot;http://java.sun.com/xml/ns/persistencequot;> <persistence-unit name=quot;defaultPersistenceUnitquot; transaction-type=quot;JTAquot;> <jta-data-source>jdbc/__default</jta-data-source> <properties> <property name=quot;toplink.platform.class.namequot; value=quot;oracle.toplink.essentials.platform.database.DerbyPlat formquot;/> </properties> </persistence-unit> </persistence> Glassfish configuration JUG Milano – EJB 3.0 24
  • Entity Beans: advanced features • Associations @OneToOne @OneToMany @ManyToOne @ManyToMany • Support for inheritance @Inheritance > 3 inheritance strategies: SINGLE TABLE TABLE PER CLASS JOINED TABLES • Support for “cascadable” associations (@Cascade) • Support for optmistic locking (@Version) JUG Milano – EJB 3.0 25
  • EJB Query Language • Very similar to HQL (Hibernate Query Language) • Support for polymorphic queries • Support for native queries • Subselects UPDATE Customer c SET c.status = 'outstanding' WHERE c.balance < 10000 JUG Milano – EJB 3.0 26
  • @MessageDriven Bean • The Business Interface is the message listener interface (for JMS, javax.jms.MessageListener) • A POJO Implementation Annotated with @MessageDriven • No more deployment descriptors! (optional) JUG Milano – EJB 3.0 27
  • Open Source EJB3 Implementations https://glassfish.dev.java.net/ http://www.jboss.org http://jonas.objectweb.org/ To be released: Open JPA (Solarmetric KODO) JUG Milano – EJB 3.0 28
  • @Questions? Thank you! JUG Milano – EJB 3.0 29
  • References • JSR 220: Enterprise JavaBeansTM 3.0 http://www.jcp.org/en/jsr/detail?id=220 • Glassfish website and documentation https://glassfish.dev.java.net • JBoss website and documentation http://www.jboss.org • Gavin King's “Entity Beans in EJB 3” http://hibernate.org/gavin/ebejb3.pdf • Kenneth Saks “Enterprise Java Bean 3.0” http://www.javasig.com/Archive/lectures/JavaSIG-EJB30.pdf • Filippo Diotalevi's “Java EE 5 – Step by Step” http://www.diotalevi.com/weblog/?page_id=125 JUG Milano – EJB 3.0 30