Your SlideShare is downloading. ×
0
Insert Picture Here>Java EE 6                         	                    Fusion Middleware   	   Java    http://yoshio3....
Copyright© 2011, Oracle. All rights reserved.
Copyright© 2011, Oracle. All rights reserved.
WebLogic           Copyright© 2011, Oracle. All rights reserved.

                                                  	    	                  	         	                         	          ...
                                                                  	                                                       ...
                                                                     	                                        	           ...

                                                                                              	                          ...

            	                      	                                                       	                             ...

                                                 	Copyright© 2011, Oracle. All rights reserved.                          ...
Copyright© 2011, Oracle. All rights reserved.
                            	                                            	                                                ...
                                                                   	                             	                        ...
JSR-250 Java EE                                                                    Common Annotation@javax.annotation.Mana...

                                                                       	                      	                          ...

                                                                     	import javax.interceptor.AroundInvoke;!import javax...
import javax.interceptor.Interceptors;!!@javax.annotation.ManagedBean!@Stateless!@Interceptors(MyInterceptor.class)!public...
Copyright© 2011, Oracle. All rights reserved.

                      	            	                                                              	                      ...

                                   	                                                                                    	...

                                                                          	    package hello;!    import javax.servlet.an...

                  	                              	                                                                       ...

         	                                                                   	                            	              ...

                                                                                         	                               ...

                                                              	<?xml version=”1.0″ encoding=”UTF-8″?>
<web-fragment xmlns...

                                                                       	                                   	             ...

                                                                          	                                              ...

                              	 <FORM action=”/MyFileUpload” enctype=”multipart/form-data” method=”POST”>!       : <INPUT...

                                   	   @WebServlet(name = ”MyFileUpload”, urlPatterns ={“/MyFileUpload”})!   @MultipartCo...

                                       	                                                                  	              ...

                                  	@WebServlet(name="CalculatorServlet", asyncSupported=true, !                         u...

                              	                       	                                                             	    ...
Copyright© 2011, Oracle. All rights reserved.
                                                 	                 	                        	                             ...

                             	                                	                   	                   	              	   ...

                                  	                   	                                                                 	...

                	                                                                    	                       	           ...

            	                                                        	                                                   ...

                                             	                   	                                                       ...

                                                        	                                                                ...
Copyright© 2011, Oracle. All rights reserved.

                  
    	   	                           	                                	                                ...

                                                                    	 foo.ear                                           f...

                                                            	                                        •                   ...

                                                                                        	                                ...

                                                     	    Copyright© 2011, Oracle. All rights reserved.                  ...

                                                                 	                	                                      ...

                                                           	@Stateless!public class HelloBean implements Hello {!      !p...

                                                                	            	                                           ...

                                                        	package test;!import javax.ejb.Stateless;!@Stateless!public clas...

                                                            	@Test!public void testSayHello() {!       Map p = new HashMa...

                                                	            	        Copyright© 2011, Oracle. All rights reserved.      ...

                                                          	                                                              ...

                      	                                         	                        	                               ...

                                   	                                                	                                    ...

                                         	@Singleton!                            @Stateless !public class SharedBean {!  ...

                                             	                                  	                                        ...

                                              	Startup/Shutdown             !!@Singleton!@Startup (                      ...

                            	                                                	                                           ...

                                    	@Stateless !public class BankBean { !     @PersistenceContext EntityManager accountD...

                	                                                                                      	                 ...

                	@Stateless public class DocBean {!  @PersistenceContext EntityManager resultsDB;!  @EJB DocBean myself;!...
Copyright© 2011, Oracle. All rights reserved.

                               	                     	        	                    	             	               	       ...

                               	                          	                     	                               	        ...

                                         	@Entity!public class Person implements Serializable {!    @Id!    @GeneratedVal...

                                      	@Entity!public class Person implements Serializable {!    @Id!    @GeneratedValue(...

                                                         	@Embeddable!public class Address{!    private String street;!  ...

                                               	@Embeddable!public class ContactInfo {!    @Embedded!    Address addresse...

                                                                    	@Embeddable public class ContactInfo {!    @Embedded...

                              	            	                    	                                                        ...

                                               	                                                           	             ...

                                                                                     	     	                      	      ...

                                                                           	     	                 	                     ...

                                                                  	@Entity!public class Person {!    @Id!    @GeneratedVa...

                                                                       	public class Person implements Serializable { !  ...

                                            	           	                         	      	                    	          ...

                                  	                 	                                                                    ...

                                                          	                                                              ...

                                                             	                                                           ...

                                           	         	                                	                              	   ...

                                                  	                                                          	           ...

                                                     	                                         		                        ...

                                                                            	                              	        	    ...

                                       	                             		                            	              	      ...

                           	                      	                                   		          	                	     ...

            	                                                              	                                             ...

                                                                	                   	                                    ...

                                                                               	     EntityManager em = … ;!     Criteria...

                     	                               	                          	                                        ...

                                                                      	     EntityManager em = … ;!     CriteriaBuilder c...

                                        	@Entity!                          importpublic class Person {!            javax....

                                                                   	                                                     ...

                                                                       	    EntityManager em = … ;!    CriteriaBuilder cb...

                                                       	                                            	                    ...

                                         	        	                  	                                                   ...

                                    		                                                                   		              ...

                                                                  	                                                      ...

                                                                   
    	                          	                     ...

                                                                  	        	                                             ...

                                                                        	                        	                       ...

                                                                                      	                                  ...

                                                                  	                                            	         ...

                                                                  	                                               	public...

                                                                        	                                           	    ...

                                                                             	                                           ...
Copyright© 2011, Oracle. All rights reserved.

                                           	                                                                  	          ...

                                                               	                                               	         ...

    	                                                                    	                          	          	      	 U...

                                              	                                                               	        	 ...

                                           	                                   	        	                                ...

                                                         	HTTPGET /music/artists/beatles/recordings HTTP/1.1Host: musicsi...

                                                      	                                                              	   ...

                                   	@Path(“root”)!Public class RootResource{ //                !   @Context UriInfo uri;!...

                                             	                             	                                             ...

                                                       	         	                                                       ...

                                                                      	@Path(“/items”)!@Consumes(“application/xml”)!Publi...

        	                                                               	                                                ...

                                         	@Path(“/myResource”)!@Produces(“text/plain”)!Public class SomeResource{!!   // ...

                                                                    	!//                                    URI     !@POS...

        	                                                                         	                                      ...

                                          	!//                     MIME                                        !@POST!@Co...
                  	                                         	                                                           	 ...
Copyright© 2011, Oracle. All rights reserved.
                                                                             	                                            ...
Copyright© 2011, Oracle. All rights reserved.
                         	                                	                    	                          	               ...
Copyright© 2011, Oracle. All rights reserved.
                       	                                  	        	                             	        	             	 ...
Copyright© 2011, Oracle. All rights reserved.
Copyright© 2011, Oracle. All rights reserved.
Upcoming SlideShare
Loading in...5
×

Java EE 6 Detail

46,125

Published on

This presentation explains the detail of Java EE 6 and future of Java EE.

Published in: Technology

Transcript of "Java EE 6 Detail"

  1. 1. Insert Picture Here>Java EE 6 Fusion Middleware Java http://yoshio3.com
  2. 2. Copyright© 2011, Oracle. All rights reserved.
  3. 3. Copyright© 2011, Oracle. All rights reserved.
  4. 4. WebLogic Copyright© 2011, Oracle. All rights reserved.
  5. 5. 
         Copyright© 2011, Oracle. All rights reserved.
  6. 6.           Copyright© 2011, Oracle. All rights reserved.
  7. 7.               Web Profile X Profile Y Profile Full Java EE 6 (Enterprise Platform) Copyright© 2011, Oracle. All rights reserved.
  8. 8. 
                           Copyright© 2011, Oracle. All rights reserved.
  9. 9. 
                 Copyright© 2011, Oracle. All rights reserved.
  10. 10. 
 Copyright© 2011, Oracle. All rights reserved.
  11. 11. Copyright© 2011, Oracle. All rights reserved.
  12. 12.                         Copyright© 2011, Oracle. All rights reserved.
  13. 13.                   Copyright© 2011, Oracle. All rights reserved.
  14. 14. JSR-250 Java EE Common Annotation@javax.annotation.ManagedBean!@Stateless! public class SomeBean {! @Resourece! private Detasouce ds;!! @PostConstruct! public void init(){ … }! ! @PreDestroy! public void destroy(){ … }!}! ManagedBean @Resource @Resource SomeBean sbean@Inject SomeBean sbean Copyright© 2011, Oracle. All rights reserved.
  15. 15. 
     import static java.lang.annotation.ElementType.TYPE;! import static java.lang.annotation.ElementType.METHOD;! import java.lang.annotation.Inherited;! import java.lang.annotation.Retention;! import java.lang.annotation.Target;! ! @Inherited! @javax.interceptor.InterceptorBinding! @Retention(java.lang.annotation.RetentionPolicy.RUNTIME)! @Target({METHOD, TYPE})! public @interface MyInterceptorBinding {! } Copyright© 2011, Oracle. All rights reserved.
  16. 16. 
 import javax.interceptor.AroundInvoke;!import javax.interceptor.Interceptor;!import javax.interceptor.InvocationContext;!!@Interceptor!@MyInterceptorBinding!public class MyInterceptor {!! @AroundInvoke! public Object intercept(InvocationContext context) throwsException {! System.out.println("before interception”);! Object result = context.proceed();// ! System.out.println("after interception”);! return result;! }!} Copyright© 2011, Oracle. All rights reserved.
  17. 17. import javax.interceptor.Interceptors;!!@javax.annotation.ManagedBean!@Stateless!@Interceptors(MyInterceptor.class)!public class SomeBean {! @Resourece! private Detasouce ds;!! @PostConstruct! INIT was called! public void init(){ … }! before interception! ! EJB INIT! @PreDestroy! public void destroy(){ … }! after interception!}! DESTROY was called Copyright© 2011, Oracle. All rights reserved.
  18. 18. Copyright© 2011, Oracle. All rights reserved.
  19. 19. 
                   Copyright© 2011, Oracle. All rights reserved.
  20. 20. 
     Copyright© 2011, Oracle. All rights reserved.
  21. 21. 
 package hello;! import javax.servlet.annotation.WebServlet;! import javax.servlet.http.HttpServlet;! import javax.servlet.http.HttpServletRequest;! import javax.servlet.http.HttpServletResponse;! @WebServlet(name="Hello", urlPatterns={"/Hello"})! public class Hello extends HttpServlet {!! <web-app>! @Override! <servlet> ! protected void doGet(HttpServletRequest request, ! <servlet-name>Hello</servlet-name> ! HttpServletResponse response) <servlet-class>hello.Hello</servlet-class>!throws ServletException, IOException {! </servlet>! .......! <servlet-mapping>! }! <servlet-name>Hello</servlet-name> ! } <url-pattern>/Hello/* </url-pattern>! </servlet-mapping>! </web-app> web.xml Copyright© 2011, Oracle. All rights reserved.
  22. 22. 
         WEB-INF/lib/resources.jar > jar cvf resources.jar META-INF/ META-INF/MANIFEST.MF META-INF/resources/ META-INF/resources/test.html http://www.oracle.com/test.html Copyright© 2011, Oracle. All rights reserved.
  23. 23. 
               Copyright© 2011, Oracle. All rights reserved.
  24. 24. 
       <web-app version=”3.0″ ! xmlns=”http://java.sun.com/xml/ns/javaee” ! xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” ! xsi:schemaLocation=”http://java.sun.com/xml/ns/javaee ! http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd” ! metadata-complete=”false”> Copyright© 2011, Oracle. All rights reserved.
  25. 25. 
 <?xml version=”1.0″ encoding=”UTF-8″?>
<web-fragment xmlns=http://java.sun.com/xml/ns/javaee! xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
 xsi:schemaLocation=”http://java.sun.com/xml/ns/javaee 
 http://java.sun.com/xml/ns/javaee/web-fragment_3_0.xsd”
 version=”3.0″>
    <context-param>
    </context-param>
    <servlet>
    </servlet>
    <servlet-mapping>
    </servlet-mapping>
    <session-config>
    </session-config>
    <welcome-file-list>
    </welcome-file-list>!</web-fragment> web.xml Copyright© 2011, Oracle. All rights reserved.
  26. 26. 
               Copyright© 2011, Oracle. All rights reserved.
  27. 27. 
   !@HandlesTypes(WebService.class)!!class JAXWSServletContainerInitializer implementsServletContainerInitializer{!! public void onStartup(Set<Class<?>> c, ServletContext ctx) !throws ServletException {! // JAX-WS ServletRegistration reg = ctx.addServlet("JAXWSServlet", ! ! ! ! !"com.sun.webservice.JAXWSServlet");! reg.addServletMapping("/foo");! }!}! Copyright© 2011, Oracle. All rights reserved.
  28. 28. 
  <FORM action=”/MyFileUpload” enctype=”multipart/form-data” method=”POST”>! : <INPUT type=”file” name=”content”>!         <INPUT type=”submit” value=”Submit”>! </FORM>!                 Copyright© 2011, Oracle. All rights reserved.
  29. 29. 
 @WebServlet(name = ”MyFileUpload”, urlPatterns ={“/MyFileUpload”})! @MultipartConfig(fileSizeThreshold=5000000,! MaxFileSize=10000000, location=”/tmp”)! public class MyFileUpload extends HttpServlet {   !    protected void processRequest(HttpServletRequest  ! request, HttpServletResponse response)!    throws ServletException, IOException {!    // <INPUT type=”file” name=”content”> ! Part part = request.getPart(“content”);! // Content-Disposition ! //         String fname = getFilename(part);! // @MultipartConfig(location=”/tmp”)          part.write(fname);! Copyright© 2011, Oracle. All rights reserved.
  30. 30. 
               Copyright© 2011, Oracle. All rights reserved.
  31. 31. 
 @WebServlet(name="CalculatorServlet", asyncSupported=true, ! urlPatterns={"/calc", "/getVal"})!public class CalculatorServlet extends HttpServlet{! public void doGet(HttpServletRequest req,HttpServletResponse res) {! ...! AsyncContext aCtx = req.startAsync(req, res);! }! } Copyright© 2011, Oracle. All rights reserved.
  32. 32. 
                 Copyright© 2011, Oracle. All rights reserved.
  33. 33. Copyright© 2011, Oracle. All rights reserved.
  34. 34.                         Copyright© 2011, Oracle. All rights reserved.
  35. 35. 
           http://yoshio3.com/2011/01/14/jsf20-new-with-facelets-template/ Copyright© 2011, Oracle. All rights reserved.
  36. 36. 
     <ui:insert name="content">Content</ui:insert>      <ui:composition template="./templates/tableTemplate.xhtml"><ui:define name="content">! </ui:define> !</ui:composition> Copyright© 2011, Oracle. All rights reserved.
  37. 37. 
         http://yoshio3.com/2011/01/18/jsf-20-ajax-support/ Copyright© 2011, Oracle. All rights reserved.
  38. 38. 
       Ajax Copyright© 2011, Oracle. All rights reserved.
  39. 39. 
               Copyright© 2011, Oracle. All rights reserved.
  40. 40. 
         http://yoshio3.com/2011/02/16/jsf-bookmarkable-url-suppor/ Copyright© 2011, Oracle. All rights reserved.
  41. 41. Copyright© 2011, Oracle. All rights reserved.
  42. 42. 
 
              Copyright© 2011, Oracle. All rights reserved.
  43. 43. 
 foo.ear foo.ear foo.ear lib/foo_common.jar WEB-INF/web.xml com/acme/Foo.class WEB-INF/classes/ foo_web.war com/acme/FooServlet.class WEB-INF/classes WEB-INF/web.xml WEB-INF/classes/foo. ar com/acme/FooServlet.classcom/acme/FooBean.class foo_ejb.jarcom/acme/Foo.class com/acme/FooBean.class Copyright© 2011, Oracle. All rights reserved.
  44. 44. 
 •  •  •  WEB-INF/classes/com/acme/ •  FooServlet.class •  •  FooBean.class (EJB) •  •  Copyright© 2011, Oracle. All rights reserved.
  45. 45. 
                             Copyright© 2011, Oracle. All rights reserved.
  46. 46. 
 Copyright© 2011, Oracle. All rights reserved.
  47. 47. 
                         Copyright© 2011, Oracle. All rights reserved.
  48. 48. 
 @Stateless!public class HelloBean implements Hello {! !public String sayHello(String msg) {! ! return “Hello “ + msg;! }!}!!JNDI NAME:!java:global/hello/HelloBean!java:app/hello/HelloBean!java:module/HelloBean! Copyright© 2011, Oracle. All rights reserved.
  49. 49. 
               Copyright© 2011, Oracle. All rights reserved.
  50. 50. 
 package test;!import javax.ejb.Stateless;!@Stateless!public class Hello { ! public String sayHello(){! return "Hello Embedded TEST";! }!}! Copyright© 2011, Oracle. All rights reserved.
  51. 51. 
 @Test!public void testSayHello() {! Map p = new HashMap();! p.put("org.glassfish.ejb.embedded.glassfish.instance.root",! "/Applications/GlassFish/glassfishv3-webprofile/glassfish/! domains/domain1");! EJBContainer container = EJBContainer.createEJBContainer(p);! try{! Hello hello = (Hello)container.getContext().lookup! ("java:global/classes/Hello");! System.out.println(hello.sayHello());! }catch(Exception e){! e.printStackTrace();! }}! http://bit.ly/hzzjR3 Copyright© 2011, Oracle. All rights reserved.
  52. 52. 
   Copyright© 2011, Oracle. All rights reserved.
  53. 53. 
           Copyright© 2011, Oracle. All rights reserved.
  54. 54. 
             Copyright© 2011, Oracle. All rights reserved.
  55. 55. 
           Copyright© 2011, Oracle. All rights reserved.
  56. 56. 
 @Singleton! @Stateless !public class SharedBean {! public class FooBean {! private SharedData @EJB !shared;! private SharedBean @PostConstruct ! shared;! private void init() { ! ! shared = ...; ! public void foo() {! }! int xyz = public int getXYZ() {! shared.getXYZ();! return shared.xyz;! …! }! }! ! }! Copyright© 2011, Oracle. All rights reserved.
  57. 57. 
                     Copyright© 2011, Oracle. All rights reserved.
  58. 58. 
 Startup/Shutdown !!@Singleton!@Startup ( EJB )!public class StartupBean {!! @PostConstruct ! private void onStartup() { … }!! @PreDestroy! private void onShutdown() { … }! !}! Copyright© 2011, Oracle. All rights reserved.
  59. 59. 
                   Copyright© 2011, Oracle. All rights reserved.
  60. 60. 
 @Stateless !public class BankBean { ! @PersistenceContext EntityManager accountDB;! @Resource javax.mail.Session mailSession;! // sendMonthlyBankStatements() @Schedule(hour=”8”, dayOfMonth=”Last”)! void sendMonthlyBankStatements() {! ...! }!}!! @Schedule void @Timeout or @Schedule method must return void and be a no-arg method or takea single javax.ejb.Timer param Copyright© 2011, Oracle. All rights reserved.
  61. 61. 
                 Copyright© 2011, Oracle. All rights reserved.
  62. 62. 
 @Stateless public class DocBean {! @PersistenceContext EntityManager resultsDB;! @EJB DocBean myself;! public void processDocument(Document document) {! myself.doAnalysisA(document);! myself.doAnalysisB(document);! }! @Asynchronous ! public void doAnalysisA(Document d) {...}! @Asynchronous ! public void doAnalysisB(Document d) {...} Copyright© 2011, Oracle. All rights reserved.
  63. 63. Copyright© 2011, Oracle. All rights reserved.
  64. 64. 
                 Copyright© 2011, Oracle. All rights reserved.
  65. 65. 
               Copyright© 2011, Oracle. All rights reserved.
  66. 66. 
 @Entity!public class Person implements Serializable {! @Id! @GeneratedValue(strategy = GenerationType.AUTO)! private Long id;! private String name;! @ElementCollection! private Set<String> nickname;! Copyright© 2011, Oracle. All rights reserved.
  67. 67. 
 @Entity!public class Person implements Serializable {! @Id! @GeneratedValue(strategy = GenerationType.AUTO)! private Long id;! private String name;! @ElementCollection! @CollectionTable(name="NICKNAMES")! @Column(name="aliases")! private Set<String> nickname;! Copyright© 2011, Oracle. All rights reserved.
  68. 68. 
 @Embeddable!public class Address{! private String street;! private String town;! private String city;! private String prefecture;!}!@Entity!public class Person {! …! @ElementCollection! private Set<Address> addresses;!}!! Copyright© 2011, Oracle. All rights reserved.
  69. 69. 
 @Embeddable!public class ContactInfo {! @Embedded! Address addresses;!}!@Entity!public class Person {! @Id! private Long id;! private String name;! private ContactInfo contactInfo;! Copyright© 2011, Oracle. All rights reserved.
  70. 70. 
 @Embeddable public class ContactInfo {! @Embedded Address addresses;! @OneToMany! Set<Phone> phone;!}!@Entity public class Person {! @Id! private Long id;! private String name;! private ContactInfo contactInfo;!}!@Entity!public class Phone {! @Id String phonenumber;! String phonetype;!}! Copyright© 2011, Oracle. All rights reserved.
  71. 71. 
             Copyright© 2011, Oracle. All rights reserved.
  72. 72. 
     @Entity public class Person{! @OneToMany(mappedBy="owner")! @MapKey(name="phone_type")! private Map <String, PhoneNumber> phoneNumbers;! …!@Entity!public class PhoneNumber{! @Basic @Id private String phone_type;! @ManyToOne private Person owner;! Copyright© 2011, Oracle. All rights reserved.
  73. 73. 
 Copyright© 2011, Oracle. All rights reserved.
  74. 74. 
 Copyright© 2011, Oracle. All rights reserved.
  75. 75. 
 @Entity!public class Person {! @Id! @GeneratedValue(strategy = GenerationType.AUTO)! private Long id;! private String name;! ! @ElementCollection! @CollectionTable(name=”**”)! :@MapKeyColumn(name=”**”)! @Column(name=”**”)! private Map<String,String>phoneNumber; Copyright© 2011, Oracle. All rights reserved.
  76. 76. 
 public class Person implements Serializable { ! @Id private Long id;!! @ElementCollection! @CollectionTable! @MapKeyEnumerated(EnumType.STRING)! @MapKeyColumn! @Column! private Map<PhoneType,String> phoneNumber;!}!public enum PhoneType{Mobile, Home, Company}! Copyright© 2011, Oracle. All rights reserved.
  77. 77. 
 Copyright© 2011, Oracle. All rights reserved.
  78. 78. 
       @Entity! public class CreditCard {! ! @Id long ccNumber;! @OneToMany // unidirectional! @OrderColumn! List<CardTransaction> transactionHistory;! ...! }! Copyright© 2011, Oracle. All rights reserved.
  79. 79. 
         Copyright© 2011, Oracle. All rights reserved.
  80. 80. 
           Copyright© 2011, Oracle. All rights reserved.
  81. 81. 
                 Copyright© 2011, Oracle. All rights reserved.
  82. 82. 
 Copyright© 2011, Oracle. All rights reserved.
  83. 83. 
 Copyright© 2011, Oracle. All rights reserved.
  84. 84. 
               Copyright© 2011, Oracle. All rights reserved.
  85. 85. 
 Copyright© 2011, Oracle. All rights reserved.
  86. 86. 
     Copyright© 2011, Oracle. All rights reserved.
  87. 87. 
                     Copyright© 2011, Oracle. All rights reserved.
  88. 88. 
                     Copyright© 2011, Oracle. All rights reserved.
  89. 89. 
 EntityManager em = … ;! CriteriaBuilder cb = em.getCriteriaBuilder();! CriteriaQuery<Person> p = cb.createQuery(Person.class);! Root<Person> person = p.from(Person.class);! p.select(person).where(! cb.equal(person.get(“name”),”Taro Yamada”));! ! Copyright© 2011, Oracle. All rights reserved.
  90. 90. 
                 Copyright© 2011, Oracle. All rights reserved.
  91. 91. 
 EntityManager em = … ;! CriteriaBuilder cb = em.getCriteriaBuilder();! CriteriaQuery<Person> p = cb.createQuery(Person.class);! Root<Person> person = p.from(Person.class);! p.select(person).where(! cb.equal(person.get(“name”),”Taro Yamada”));!! Copyright© 2011, Oracle. All rights reserved.
  92. 92. 
 @Entity! importpublic class Person {! javax.persistence.metamodel.Singul @Id! arAttribute;! @javax.persistence.metamodel.Stati @GeneratedValue cMetaModel(Person.class)!(strategy = ! GenerationType.AUTO)! public class Person_ {! private Long id;! public static volatile SingularAttribute<Person,Long> id;! private String name;! public static volatile Private Integer age;! SingularAttribute<Person,String>}! name;! public static volatile SingularAttribute<Person,Integer> age;! Copyright© 2011, Oracle. All rights reserved.
  93. 93. 
 EntityManager em = ...;! Metamodel meta = em.getMetaModel();! EntityType<Person> Person_ = meta.entity(Person.class);!! Copyright© 2011, Oracle. All rights reserved.
  94. 94. 
 EntityManager em = … ;! CriteriaBuilder cb = em.getCriteriaBuilder();! CriteriaQuery<Person> p = cb.createQuery(Person.class);! Root<Person> person = p.from(Person.class);! p.select(person).! where(cb.equal(person.get(Person_.name),”Taro Yamada”));!! Copyright© 2011, Oracle. All rights reserved.
  95. 95. 
     Copyright© 2011, Oracle. All rights reserved.
  96. 96. 
               Copyright© 2011, Oracle. All rights reserved.
  97. 97. 
             Copyright© 2011, Oracle. All rights reserved.
  98. 98. 
 !@Entity public class Employee {! @Id Integer empId;! String name;! @Max(15) Integer vacationDays;! @Valid Address worksite; ! ...!}!@Embeddable public class Address {! @Size(max=30) String street;! @Size(max=20) String city;! @Zipcode String zipcode;! ...!}! Copyright© 2011, Oracle. All rights reserved.
  99. 99. 
 
    Transaction Transaction     Persistence Persistence   Context Context   Level 2   Copyright© 2011, Oracle. All rights reserved.
  100. 100. 
                 Copyright© 2011, Oracle. All rights reserved.
  101. 101. 
     Copyright© 2011, Oracle. All rights reserved.
  102. 102. 
   Copyright© 2011, Oracle. All rights reserved.
  103. 103. 
                   Copyright© 2011, Oracle. All rights reserved.
  104. 104. 
 public List<Person> findPersons(){! TypedQuery<Person> query = ! em.createQuery(“SELECT p ...”);! query.setProperty(! "javax.persistence.cache.retrieveMode",! CacheRetrieveMode.BYPASS);! query.setProperty(! "javax.persistence.cache.storeMode",! CacheStoreMode.REFRESH);! return query.getResultList();!}! Copyright© 2011, Oracle. All rights reserved.
  105. 105. 
       <property name="eclipselink.jdbc.driver" ! value="org.apache.derby.jdbc.ClientDriver"/>! <property name="eclipselink.jdbc.url" ! value="jdbc:derby://localhost:1527/Sample"/>! <property name="eclipselink.jdbc.user" value="APP"/>! <property name="eclipselink.jdbc.password" value="APP"/>! Copyright© 2011, Oracle. All rights reserved.
  106. 106. 
       <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/> <property name="javax.persistence.jdbc.url" value="jdbc:derby://localhost:1527/Sample> <property name="javax.persistence.jdbc.user" value="APP"/> <property name="javax.persistence.jdbc.password" value="APP"/> Copyright© 2011, Oracle. All rights reserved.
  107. 107. Copyright© 2011, Oracle. All rights reserved.
  108. 108. 
                     Copyright© 2011, Oracle. All rights reserved.
  109. 109. 
             Copyright© 2011, Oracle. All rights reserved.
  110. 110. 
   URI Copyright© 2011, Oracle. All rights reserved.
  111. 111. 
               Copyright© 2011, Oracle. All rights reserved.
  112. 112. 
                   Copyright© 2011, Oracle. All rights reserved.
  113. 113. 
 HTTPGET /music/artists/beatles/recordings HTTP/1.1Host: musicsite.example.comAccept: application/xmlHTTPHTTP 1.1 200 OKDate: Wed, 20 Apr 2011 18:22:58 GMTServer: Oracle GlassFish Server 3.1Content-Type: application/xml; charset=UTF-8<?xml version=1.0”?><recordings xmlns=“…”> ….</recordings> Copyright© 2011, Oracle. All rights reserved.
  114. 114. 
         @Path(“widgets”)! Public class WidgetsResource{! @GET! String getList(){…}! ! @GET @Path(“{id}”)! String getWidget(@PathParam(“id”) String id) {…}! }! Copyright© 2011, Oracle. All rights reserved.
  115. 115. 
 @Path(“root”)!Public class RootResource{ // ! @Context UriInfo uri;!! @GET! public String get (){ return “GET”; }! ! @Path(“sub-resource”)! public SubResource sub() { return new SubResource();}!}!!public class SubResource{! …!}! Copyright© 2011, Oracle. All rights reserved.
  116. 116. 
       http://example.com/users/FooBar @Path(“/users/{username}”)! Public class UserResource{! @GET! @Produces(“text/xml”)! String getUser(@PathParam(“username”)String name){! …! }! }! Copyright© 2011, Oracle. All rights reserved.
  117. 117. 
           Copyright© 2011, Oracle. All rights reserved.
  118. 118. 
 @Path(“/items”)!@Consumes(“application/xml”)!Public class ItemResource{! // http://host/catalogue/items/?start=123! @GET! ItemConverter get (@QueryParam(“start”)int start){! … }!! // http://host/catalogue/items/123! @Path(“{id}”)! ItemResource getItemResource(@PathParam(“id”)Long id){! …!}! Copyright© 2011, Oracle. All rights reserved.
  119. 119. 
         Copyright© 2011, Oracle. All rights reserved.
  120. 120. 
 @Path(“/myResource”)!@Produces(“text/plain”)!Public class SomeResource{!! // ! @GET! public String doGetAsPlainText (){}!! // ! @GET! @Produces(“text/xml”)! public String doGetAsXML () {}!}! Copyright© 2011, Oracle. All rights reserved.
  121. 121. 
 !// URI !@POST!@Consumes(“application/xml”)!public Response addUser(InputStream userData){! try{! User user = getUser(userData);! long userId = persist(user); //DB ! return Response.created(URI.create(“/” + ! userId)).build();! } catch (Exception e) {! throw new MyException(e);! }!}! Copyright© 2011, Oracle. All rights reserved.
  122. 122. 
           Copyright© 2011, Oracle. All rights reserved.
  123. 123. 
 !// MIME !@POST!@Consumes(“application/xml”)!public Response postXml(String xmlData){! …!}!!@POST!@Consumes(“text/plain”)!public Response postText(String textData){! …!}! Copyright© 2011, Oracle. All rights reserved.
  124. 124.                   Copyright© 2011, Oracle. All rights reserved.
  125. 125. Copyright© 2011, Oracle. All rights reserved.
  126. 126.                         Copyright© 2011, Oracle. All rights reserved.
  127. 127. Copyright© 2011, Oracle. All rights reserved.
  128. 128.                   Copyright© 2011, Oracle. All rights reserved.
  129. 129. Copyright© 2011, Oracle. All rights reserved.
  130. 130.                 Copyright© 2011, Oracle. All rights reserved.
  131. 131. Copyright© 2011, Oracle. All rights reserved.
  132. 132. Copyright© 2011, Oracle. All rights reserved.
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×