Introduction àEJB 3Cedric DumoulinModule Technologies AvancéesDESS IPINT – 2005/2006Cedric.dumoulin@lifl.frObjectifsn Réduire la complexité des EJBn à l’aide de :n Plain Old Java Object (Pojo)n suppression des interfaces utilisation et Homen Annotations Java 5n Injectionn spécifie les propriétés/méthodes utilisésn supprime les interfaces à implémenterSpecificationsn J2EE 5 (1.5)n JSR-244 - Java Platform, Enterprise Edition 5 (Java EE 5) Specificationn http://jcp.org/en/jsr/detail?id=244n EJB 3n JSR-220 - Enterprise JavaBeans 3.0n http://jcp.org/en/jsr/detail?id=220n standardisation de la couche de persistance :Java Persistance APIn JSR : Java Specification RequestContainers – similaire j2ee 1.4Java Persistence APIn Java APIn simplifier la persistance et le mapping des objetsn introduit par EJB 3n prend le meilleur de Hibernate, JDO, TopLink, …n Annotations Java 5Annotationn Se placent aux mêmes endroits que les modificateurs (public, protected, private, …)n Se déclare à la façon d’une interface :/** * Describes the Request-For-Enhancement(RFE) that led* to the presence of the annotated API element.*/public @interface RequestForEnhancement {int id();String synopsis();String engineer() default "[unassigned]";String date() default "[unimplemented]";}Annotations - déclarationn Declaration/** * Describes the Request-For-Enhancement(RFE) that led* to the presence of the annotated API element.*/public @interface ...
Declaration /** * Describes the Request-For-Enhancement(RFE) that led * to the presence of the annotated API element. */ public @interfaceRequestForEnhancement { int id(); String synopsis(); String engineer() default "[unassigned]"; String date() default "[unimplemented]"; } utilisation : @RequestForEnhancement( id = 2868724, synopsis = "Enable time-travel", engineer = "Mr. Peabody", date = "4/1/3007" ) public static voide(hTlevartmiThguor Date destination) { ... }
Annotations - déclaration
n
n
n
Annotation sans propriétés nles () peuvent être omises
Déclaration /** Indicates that the specification of the annotated element is preliminary and subject to change. */
public @interfacePreliminary { } Utilisation
@Preliminarypublic classTimeTravel { ... }
API
Annotations - déclaration
n
n
n
Annotation avec 1 propriétés nle nom de la propriété peut être omise nla propriété doit s’appeler « value » Déclaration /** * Associates a copyright notice with the annotated API element. */ public @interfaceCopyright { Stringvalue(); } Utilisation @Copyright("2002 Yoyodyne Propulsion Systems") public classOscillationOverthruster { ... }
.0/docs/guide/laus.noc/m2jes1/5..hnsltm
n
n
n
Processing par le compilateur : ngeneration de fichiers (descripteurs, classes, ) ngrppeorecssni metadonnées accessibles dans le programme nMethod m = obj.getMethods(); if (m.isAnnotationPresent(Copyright.class)) { } nRequestForEnhancement req = obj.getAnnotation(RequestForEnhancement.class); String engineer = req.engineer();