1
Agenda
 •
 •
 •
 •
 •



         2
3
•
•
•
•
    >

•
•
•
•
        4
5
6
•
•
    >
    >

•
    >

•
    >
        ●




    >
        ●
            7
•
    >
    >
    >

•
    >
    >

•
    >

        8
•
•
    >

•
    >
    >




        9
•   •

•   •

•   •

•   •

•   •
    •
•
        10
•
•
•

    >
    >
    >
    >

        11
12
•
•
    >
    >
    >
    >
    >
    >

        13
com/acme/FooBean.class




                         14
•
•
    >
    >
•
    >
•
    >




        15
EJB 3.1 Lite   Full EJB 3.1
Session
Beans(stateful,stateless,singleton)       ●              ●
Message-Driven Bean
       ...
Session Bean                   EJB 3.1 Lite   Full EJB 3.1
Local/No-Intafece
                                   ●         ...
Services                           EJB 3.1 Lite   Full EJB 3.1
EJB Timer Service
                                       × ...
public interface Hello {
                       public String sayHello();
@EJB               }
private Hello h;

...
h.say...
@EJB                   @Stateless
private HelloBean h;   public class HelloBean {
                           public String...
•

•

    >




        21
•
    >

•
    >

•
    >




        22
@Stateless
public class HelloBean implements Hello {
   public String sayHello(String msg) {
     return “Hello “ + msg;
 ...
•
    >
    >
    >

•
    >
    >



        24
package test;
import javax.ejb.Stateless;
@Stateless
public class Hello {
    public String sayHello(){
        return "He...
@Test
public void testSayHello() {
    Map p = new HashMap();
    p.put("org.glassfish.ejb.embedded.glassfish.instance.roo...
27
•
    >
•
    >




        28
•
    >
    >
•
    >
•



        29
•
    >
        ●



    >
    >

•
    >




            30
@Singleton                     @Stateless
public class SharedBean {      public class FooBean {
  private SharedData share...
•
    >
    >
        ●



        ●




•
    >
    >
        ●




            32
@Singleton
@Startup
public class StartupBean {

    @PostConstruct
    private void onStartup() { … }

    @PreDestroy
   ...
•
•
    >
    >


•
    >
        ●



    >
        ●




            34
@Stateless
public class BankBean {
  @PersistenceContext EntityManager accountDB;
  @Resource javax.mail.Session mailSessi...
•
    >
    >
    >

•
    >
    >
        ●




            36
@Stateless public class DocBean {
  @PersistenceContext EntityManager resultsDB;
  @EJB DocBean myself;
  public void proc...
•
•
    >
    >
    >
    >
    >
    >

        38
•       •
    >       >
•       •
    >       >
•       •
    >       >
•

    >



                39
40
•
•
•




    41
•
    >
    >

•
    >

•
    >
        ●



    >


            42
•



•
•
    >




        43
44
•
    >

•
    >

•
    >
    >



        45
% telnet localhost 6666
Trying 127.0.0.1…
Connected to localhost.
Escape character is ‘^]’.
Felix Remote Shell Console:
==...
•
    >

•
    >
    >

•
    >




        47
48
•
    >
    >
    >

•
    >
    >
    >

•
    >
        49
•
    >
    >
    >
    >

•
•
    >

•
    >
        50
•
•


•




    51
•
                                >

               SSH Client           ●



                                >
Node1     ...
•
    >
    >
        ●


        ●


        ●


        ●



•



            53
•
    >

•
    >


•
    >

•
    >


        54
•
•
    >

•
•
•
•
•
    >
        55
•
•
•
•




    56
•
    >

•
    >

•
    >

•
    >



        57
58
•
    >

•
    >
        ●



    >
    >

•
    >
    >

•
            59
60
61
62
•
•
    >
    >
    >
        ●



    >
    >



            63
•
    >


    >




        64
•
•
•
•
•
•



    65
package hello;                                         <web-app>
import javax.servlet.annotation.WebServlet;              ...
•


•

    >




        67
•
    >
    >


    >

•
    >




        68
<web-fragment>
   <servlet>
     <servlet-name>Faces Servlet</servlet-name>
     <servlet-
class>javax.faces.webapp.FacesS...
•
    >
    >

•
    >


•
    >




        70
71
<FORM action=”/MyFileUpload”                  @WebServlet( name = ”MyFileUpload”, urlPatterns =
enctype=”multipart/form-da...
Servlet 3.0
•
    >

•
    >
    >


•
    >




              73
74
•
    >

•
    >
    >
    >

•
    >




        75
76
•
•
    >
    >
    >
        ●



    >
    >
    >
            77
•
    >
    >
    >
    >
    >
    >




        78
@Entity
public class Person implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    priv...
@Entity
public class Person implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    priv...
@Embeddable                                PERSON
public class Address{
    private String street;            PK   ID
    ...
@Embeddable
public class ContactInfo {
    @Embedded
    Address addresses;                    PERSON
}                   ...
@Embeddable public class ContactInfo {        PHONE
    @Embedded
    Address addresses;                 PK    PHONENUMBER...
•
    >
    >
•
    >
    >




        84
•
    >

        @Entity public class Person{
            @OneToMany(mappedBy="owner")
            @MapKey(name="phone_typ...
Map                        Mapping          Key               Value
                                                  @Map...
@Entity
public class Customer{
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    privat...
@Entity
public class Customer{
    ....
    @ElementCollection
    @CollectionTable
    @MapKeyEnumerated(EnumType.STRING)...
@Entity
Public class Project {
    ....
    @OneToMany
    @OrderBy(“lastname DESC      ,phonenumber ASC   )
    private L...
•
    >


    >
        @Entity
        public class CreditCard {
            @Id long ccNumber;
            @OneToMany //...
•
    >


    >
    >
    @Entity public class Order {
       @Id int orderId;
       ...
       @OneToMany(cascade=PERSIS...
•
    >
    >
    >
    >




        92
•
    >
•
    >
•
    >
•
    >


        93
SELECT t
FROM CreditCard c JOIN c.transactions t
WHERE c.cardHolder.name = 'John Doe'
  AND INDEX(t) < 10




            ...
// Inventory is Map<Movie,Integer>
SELECT v.location.street, KEY(i).title, VALUE(i)
FROM VideoStore v JOIN v.inventory i
W...
•
    >


•
    >
•
    >



        96
UPDATE Employee e
SET e.salary =
  CASE e.rating
      WHEN 1 THEN e.salary * 1.2
      WHEN 2 THEN e.salary * 1.1
      E...
Employee


SELECT e
FROM Employee e
WHERE TYPE(e) IN (Contractor)
                                Regular    Contractor


...
•
    >
    >
•
    >
    >
•
    >
•
    >
        99
•
    >
    >
•
    >
    >
•
    >
•
    >
        100
EntityManager em = … ;
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Person> p = cb.createQuery(Person.class...
•
    >
        ●



    >

•
    >
        ●



    >




            102
•

EntityManager em = … ;
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Person> p = cb.createQuery(Person.cl...
•
@Entity                        import javax.persistence.metamodel
public class Person {          .SingularAttribute;
   ...
•

    EntityManager em = ...;
    Metamodel meta = em.getMetaModel();
    EntityType<Person> Person_ = meta.entity(Person...
•

    EntityManager em = … ;
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<Person> p = cb.createQue...
•
    >
        ●



•
    >
        ●


        ●




            107
•
    em.lock(person, LockModeType.PESSIMISTIC_WRITE);

•
    >
•
    >

•
    >

                                        ...
•
    @Entity public class Employee {
      @Id Integer empId;
      String name;
      @Max(15) Integer vacationDays;
   ...
•
    >


    >

•
    >


    >


    >


        110
•
    >
    >


•
    >
    >
    >
    >

        111
112
@Entity
@Cache(type=CacheType.WEAK,
    isolated=false,
    expiry=60000,
    alwaysRefresh=true,
    disableHits=true,
  ...
•
    >
        ●


        ●




•
    >
        ●


        ●


        ●




            114
public List<Person> findPersons(){
    TypedQuery<Person> query = em.createQuery(“SELECT p ...”);
    query.setProperty("j...
•
    >




        116
•
    >




        117
118
Upcoming SlideShare
Loading in …5
×

Java EE 6/Glass Fishv3

3,294 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
3,294
On SlideShare
0
From Embeds
0
Number of Embeds
1,727
Actions
Shares
0
Downloads
39
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Java EE 6/Glass Fishv3

  1. 1. 1
  2. 2. Agenda • • • • • 2
  3. 3. 3
  4. 4. • • • • > • • • • 4
  5. 5. 5
  6. 6. 6
  7. 7. • • > > • > • > ● > ● 7
  8. 8. • > > > • > > • > 8
  9. 9. • • > • > > 9
  10. 10. • • • • • • • • • • • • 10
  11. 11. • • • > > > > 11
  12. 12. 12
  13. 13. • • > > > > > > 13
  14. 14. com/acme/FooBean.class 14
  15. 15. • • > > • > • > 15
  16. 16. EJB 3.1 Lite Full EJB 3.1 Session Beans(stateful,stateless,singleton) ● ● Message-Driven Bean × ● 2.x/1.x CMP/BMP Entity Bean × ● (pruning) Java Persistence 2.0 ● ● 16
  17. 17. Session Bean EJB 3.1 Lite Full EJB 3.1 Local/No-Intafece ● ● 3.0 Remote × ● 2.x Remote Home/Component × ● JAX-WS Web Service Endpoint × ● JAX-RPC Web Service Endpoint × ● (pruning) 17
  18. 18. Services EJB 3.1 Lite Full EJB 3.1 EJB Timer Service × ● Asynchronous Session Bean Invocation × ● Interceptors ● ● RMI-IIOP Interoperability × ● Container-Managed Transactions / Bean-Managed Transactions ● ● Declarative and Programmatic Security ● ● Embeddable API ● ● 18
  19. 19. public interface Hello { public String sayHello(); @EJB } private Hello h; ... h.sayHello(); @Stateless public class HelloBean implements Hello { public String sayHello() { return “hello”; }} 19
  20. 20. @EJB @Stateless private HelloBean h; public class HelloBean { public String sayHello() ... { return “hello”; } } h.sayHello(); • • 20
  21. 21. • • > 21
  22. 22. • > • > • > 22
  23. 23. @Stateless public class HelloBean implements Hello { public String sayHello(String msg) { return “Hello “ + msg; } } java:global/hello/HelloBean java:app/hello/HelloBean java:module/HelloBean 23
  24. 24. • > > > • > > 24
  25. 25. package test; import javax.ejb.Stateless; @Stateless public class Hello { public String sayHello(){ return "Hello Embedded TEST"; } } 25
  26. 26. @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(); }} 26
  27. 27. 27
  28. 28. • > • > 28
  29. 29. • > > • > • 29
  30. 30. • > ● > > • > 30
  31. 31. @Singleton @Stateless public class SharedBean { public class FooBean { private SharedData shared; @EJB @PostConstruct private SharedBean shared; private void init() { public void foo() { shared = ...; int xyz = shared.getXYZ(); } … public int getXYZ() { } return shared.xyz; } } 31
  32. 32. • > > ● ● • > > ● 32
  33. 33. @Singleton @Startup public class StartupBean { @PostConstruct private void onStartup() { … } @PreDestroy private void onShutdown() { … } } 33
  34. 34. • • > > • > ● > ● 34
  35. 35. @Stateless public class BankBean { @PersistenceContext EntityManager accountDB; @Resource javax.mail.Session mailSession; @Schedule(hour=”8”, dayOfMonth=”Last”) void sendMonthlyBankStatements() { ... } } 35
  36. 36. • > > > • > > ● 36
  37. 37. @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) {...} 37
  38. 38. • • > > > > > > 38
  39. 39. • • > > • • > > • • > > • > 39
  40. 40. 40
  41. 41. • • • 41
  42. 42. • > > • > • > ● > 42
  43. 43. • • • > 43
  44. 44. 44
  45. 45. • > • > • > > 45
  46. 46. % telnet localhost 6666 Trying 127.0.0.1… Connected to localhost. Escape character is ‘^]’. Felix Remote Shell Console: ============================ -> ps (GlassFish v3 ) START LEVEL 1 ID State Level Name [ 0] [Active ] [ 0] System Bundle (2.0.2) ….. ( ) [ 245] [Installed ] [ 1] MyBundle (1.0.0) -> start 245 -> stop 245 -> exit Good Bye! 46
  47. 47. • > • > > • > 47
  48. 48. 48
  49. 49. • > > > • > > > • > 49
  50. 50. • > > > > • • > • > 50
  51. 51. • • • 51
  52. 52. • > SSH Client ● > Node1 Node2 • sshd sshd • > > > • 52
  53. 53. • > > ● ● ● ● • 53
  54. 54. • > • > • > • > 54
  55. 55. • • > • • • • • > 55
  56. 56. • • • • 56
  57. 57. • > • > • > • > 57
  58. 58. 58
  59. 59. • > • > ● > > • > > • 59
  60. 60. 60
  61. 61. 61
  62. 62. 62
  63. 63. • • > > > ● > > 63
  64. 64. • > > 64
  65. 65. • • • • • • 65
  66. 66. package hello; <web-app> import javax.servlet.annotation.WebServlet; <servlet> <servlet-name>Hello</servlet-name> import javax.servlet.http.HttpServlet; <servlet-class>hello.Hello</servlet-class> import javax.servlet.http.HttpServletRequest; </servlet> import javax.servlet.http.HttpServletResponse; <servlet-mapping> <servlet-name>Hello</servlet-name> @WebServlet(name="Hello", urlPatterns={"/Hello"}) <url-pattern>/Hello/* </url-pattern> </servlet-mapping> public class Hello extends HttpServlet { ... </web-app> @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ....... } } 66
  67. 67. • • > 67
  68. 68. • > > > • > 68
  69. 69. <web-fragment> <servlet> <servlet-name>Faces Servlet</servlet-name> <servlet- class>javax.faces.webapp.FacesServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>Faces Servlet</servlet-name> <url-pattern>/faces/*</url-pattern> </servlet-mapping> </web-fragment> 69
  70. 70. • > > • > • > 70
  71. 71. 71
  72. 72. <FORM action=”/MyFileUpload” @WebServlet( name = ”MyFileUpload”, urlPatterns = enctype=”multipart/form-data” method=”POST”> {“/MyFileUpload”}) : <INPUT type=”file” name=”content”> @MultipartConfig( fileSizeThreshold=5000000, <INPUT type=”submit” value=”Submit”> MaxFileSize=10000000, location=”/tmp”) </FORM> 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”); // > // • String fname = getFilename(part); > // @MultipartConfig(location=”/tmp”) // part.write(fname); 72
  73. 73. Servlet 3.0 • > • > > • > 73
  74. 74. 74
  75. 75. • > • > > > • > 75
  76. 76. 76
  77. 77. • • > > > ● > > > 77
  78. 78. • > > > > > > 78
  79. 79. @Entity public class Person implements Serializable { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; private String name; @ElementCollection PERSON private Set<String> nickname; PK ID Name PERSON_NICKNAME Person_ID NICKNAME 79
  80. 80. @Entity public class Person implements Serializable { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; private String name; @ElementCollection PERSON @CollectionTable(name="NICKNAMES") PK ID @Column(name="aliases") Name private Set<String> nickname; NICKNAMES Person_ID aliases 80
  81. 81. @Embeddable PERSON public class Address{ private String street; PK ID Name private String town; private String city; private String prefecture; } PERSON_ADDRESS @Entity Person_ID public class Person { street @ElementCollection town private Set<Address> addresses; city } prefecture 81
  82. 82. @Embeddable public class ContactInfo { @Embedded Address addresses; PERSON } PK ID @Entity name public class Person { street @Id town private Long id; city private String name; prefecture private ContactInfo contactInfo; 82
  83. 83. @Embeddable public class ContactInfo { PHONE @Embedded Address addresses; PK PHONENUMBER PHONETYPE @OneToMany Set<Phone> phone; } PERSON @Entity public class Person { @Id PK ID private Long id; name ... private String name; private ContactInfo contactInfo; PERSON_PHONE PK PERSON_ID PK PHONE_PHONENUMBER 83
  84. 84. • > > • > > 84
  85. 85. • > @Entity public class Person{ @OneToMany(mappedBy="owner") @MapKey(name="phone_type") private Map<String, PhoneNumber> phoneNumbers; … @Entity public class PhoneNumber{ @Basic private String phone_type; @ManyToOne private Person owner; 85
  86. 86. Map Mapping Key Value @MapKeyColumn Map<Basic,Basic> @ElementCollection @MapKeyEnumerated @Column @MapKeyTemporal @MapKeyColumn Embeddable Map<Basic,Embeddable> @ElementCollection @MapKeyEnumerated @AttrivuteOverride @MapKeyTemporal @AssociationOverride @MapKey @MapKeyColumn Entity Map<Basic,Entity> @OneToMany,@ManyToMany @MapKeyEnumerated @MapKeyTemporal Embeddable Map<Embeddable,Basic> @ElementCollection @Column @AttrbuteOverride Embeddable Embeddable Map<Embeddable,Embeddable> @ElementCollection @AttrivuteOverride @AttrbuteOverride @AssociationOverride Map<Embeddable,Entity> @OneToMany,@ManyToMany Embeddable Entity Map<Entity,Basic> @ElementCollection @MapKeyJoinColumn @Column Embeddable Map<Entity,Embeddable> @ElementCollection @MapKeyJoinColumn @AttrivuteOverride @AssociationOverride Map<Entity,Entity> @OneToMany,@ManyToMany @MapKeyJoinColumn Entity 86
  87. 87. @Entity public class Customer{ @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; private String firstName; .... @ElementCollection Customer_PHONENUBER @CollectionTable(name=”**”) :@MapKeyColumn(name=”**”) PK,FK1 Customer_ID PK PHONENUMBER_KEY @Column(name=”**”) private Map<String,String> PHONENUMBER phoneNumber; 87
  88. 88. @Entity public class Customer{ .... @ElementCollection @CollectionTable @MapKeyEnumerated(EnumType.STRING) @MapKeyColumn @Column private Map<PhoneType,String> phoneNumber; ..... } public enum PhoneType{Mobile, Home, Company} 88
  89. 89. @Entity Public class Project { .... @OneToMany @OrderBy(“lastname DESC ,phonenumber ASC ) private List<Person> person; } @Entity public class Person { .... private String lastname; private String phonenumber; } 89
  90. 90. • > > @Entity public class CreditCard { @Id long ccNumber; @OneToMany // unidirectional @OrderColumn List<CardTransaction> transactionHistory; ... } 90
  91. 91. • > > > @Entity public class Order { @Id int orderId; ... @OneToMany(cascade=PERSIST, orphanRemoval=true ) Set<Item> lineItems; 91
  92. 92. • > > > > 92
  93. 93. • > • > • > • > 93
  94. 94. SELECT t FROM CreditCard c JOIN c.transactions t WHERE c.cardHolder.name = 'John Doe' AND INDEX(t) < 10 94
  95. 95. // Inventory is Map<Movie,Integer> SELECT v.location.street, KEY(i).title, VALUE(i) FROM VideoStore v JOIN v.inventory i WHERE KEY(i).director LIKE '%Hitchcock%' AND VALUE(i) > 0 95
  96. 96. • > • > • > 96
  97. 97. UPDATE Employee e SET e.salary = CASE e.rating WHEN 1 THEN e.salary * 1.2 WHEN 2 THEN e.salary * 1.1 ELSE e.salary * 1.02 END 97
  98. 98. Employee SELECT e FROM Employee e WHERE TYPE(e) IN (Contractor) Regular Contractor 98
  99. 99. • > > • > > • > • > 99
  100. 100. • > > • > > • > • > 100
  101. 101. 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”)); SELECT p FROM Person p WHERE p.name = 'Taro Yamada' 101
  102. 102. • > ● > • > ● > 102
  103. 103. • 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”)); 103
  104. 104. • @Entity import javax.persistence.metamodel public class Person { .SingularAttribute; @Id @javax.persistence.metamodel.Stati @GeneratedValue(strategy = cMetaModel(Person.class) GenerationType.AUTO) public class Person_ { private Long id; public static volatile private String name; SingularAttribute<Person,Long> id; Private Integer age; public static volatile SingularAttribute<Person,String> name; public static volatile SingularAttribute<Person,Integer> age; 104
  105. 105. • EntityManager em = ...; Metamodel meta = em.getMetaModel(); EntityType<Person> Person_ = meta.entity(Person.class); 105
  106. 106. • 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”)); 106
  107. 107. • > ● • > ● ● 107
  108. 108. • em.lock(person, LockModeType.PESSIMISTIC_WRITE); • > • > • > 108
  109. 109. • @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; @NotNull @Size(max=20) String city; @Size.max @Zipcode String zipcode; @Min/@Max ... @Future/@Past } @Size 109
  110. 110. • > > • > > > 110
  111. 111. • > > • > > > > 111
  112. 112. 112
  113. 113. @Entity @Cache(type=CacheType.WEAK, isolated=false, expiry=60000, alwaysRefresh=true, disableHits=true, coordinationType=INVALIDATE_CHANGE_OBJECTS) @Cacheable(true) public class Person implements Serializable { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; 113
  114. 114. • > ● ● • > ● ● ● 114
  115. 115. 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(); } 115
  116. 116. • > 116
  117. 117. • > 117
  118. 118. 118

×