Enterprise Java Beans 3.0

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    6 Favorites & 1 Group

    Enterprise Java Beans 3.0 - Presentation Transcript

    1. 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
    2. Filippo Diotalevi http://www.diotalevi.com/weblog https://java-champions.dev.java.net/ http://www.jugmilano.it JUG Milano – EJB 3.0 3
    3. Tag-Cloud StatelessSessionBean ResourceInjection EnterpriseJavaBeans StatefulSessionBean EntityBean POJO MessageDrivenBean JavaEE5 Annotations JavaPersistenceAPI Glassfish JUG Milano – EJB 3.0 4
    4. JavaEE5 Goals • EOD – Easy of Development • Increase productivity • Full backward compatibility • Community involvement ResourceInjection Tools: POJO Annotations JUG Milano – EJB 3.0 5
    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
    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
    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
    8. EJB 3: Solutions • POJO Model • Annotations • “Configuration by exception” • Java Persistence API JUG Milano – EJB 3.0 9
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    19. EntityManager • A detyped “home” interface • create(), merge() and remove() instances • Factory for Query JUG Milano – EJB 3.0 20
    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
    21. @PersistenceContext ? persistence context as \"a set of entity instances in which - for any persistent entity identity -there is a unique entity instance.\" 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
    22. Query Query query = entityManager.createQuery(\"SELECT p FROM Pagina p\"); return query.getResultList(); • Query parameters • Support for pagination • Native query entityManager.createNativeQuery() JUG Milano – EJB 3.0 23
    23. Deployment Descriptor Need to define the Persistence Unit in persistence.xml <?xml version=\"1.0\" encoding=\"UTF-8\"?> <persistence xmlns=\"http://java.sun.com/xml/ns/persistence\"> <persistence-unit name=\"defaultPersistenceUnit\" transaction-type=\"JTA\"> <jta-data-source>jdbc/__default</jta-data-source> <properties> <property name=\"toplink.platform.class.name\" value=\"oracle.toplink.essentials.platform.database.DerbyPlat form\"/> </properties> </persistence-unit> </persistence> Glassfish configuration JUG Milano – EJB 3.0 24
    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
    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
    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
    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
    28. @Questions? Thank you! JUG Milano – EJB 3.0 29
    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

    + Filippo DiotaleviFilippo Diotalevi, 3 years ago

    custom

    5033 views, 6 favs, 4 embeds more stats

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 5033
      • 5026 on SlideShare
      • 7 from embeds
    • Comments 0
    • Favorites 6
    • Downloads 511
    Most viewed embeds
    • 4 views on http://www.techiegyan.com
    • 1 views on http://simplyauser.pbwiki.com
    • 1 views on http://www.itspice.com
    • 1 views on http://www.slideshare.net

    more

    All embeds
    • 4 views on http://www.techiegyan.com
    • 1 views on http://simplyauser.pbwiki.com
    • 1 views on http://www.itspice.com
    • 1 views on http://www.slideshare.net

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories

    Groups / Events