SlideShare una empresa de Scribd logo
1 de 21
Descargar para leer sin conexión
J2EE-Tutorial

Developing a J2EE-Application with JBoss



Übung SAVES, Sommersemester 2006

Holger Klus
Sebastian Herold

Technische Universität Kaiserslautern
Fachbereich Informatik
AG Softwarearchitektur
Overview

  Application Scenario „Drink Account Manager“
    Current situation
    Goals of „Drink Account Manager“
  J2EE-Introduction
    Short Overview
    Container-Concept
    Entity Beans
    Session Beans
    Servlets/JSP‘s
    Packaging and Deployment
    XDoclet
Application Scenario „Drink Account Manager“

Current situation                                          Wasser             Cola (0,5   Apfelschorle   …
    A printed list with available drinks                   (0,7 Liter)        Liter)      (0,7 Liter)
    and possible consumers is provided
    in our kitchen
                                             Sebastian
    Every person makes a bar in the          Herold
    corresponding field if he removes a
    drink                                    Holger Klus

    Additionally a price list is available
    Every 4-5 weeks a bill is sent to the    …
    consumers by E-Mail

Goals of „Drink Account Manager“
    Making bars via Touch-Screen in the                    Getränk                              Preis
    kitchen                                                Wasser (0,7 Liter)                   0,40 €
    Automatic generation of bills and the
    corresponding E-Mail                                   Cola (0,5 Liter)                     0,75 €
    But first: Implementing basic
    functionality like                                     Apfelschorle (0,7 Liter)             0,70 €
      - Show/Add/Edit/Delete
           -   Consumers                                   …
           -   Drinks
           -   Removals
           -   Prices
           -   Bills
Application Scenario „Drink Account Manager“

  Implementation of this scenario using two different
  approaches
    Fat-Client-Approach
      - Client is a Java application using Hibernate for Object-Relational
        mapping
      - All data will be stored in a MySQL-Database
    Ultra-Thin-Client-Approach (using J2EE)
      - Client accesses the application through a web interface
      - Web-pages are generated on server-side and will then be sent to
        the client
      - The application runs in an application server including
          - Business logic and
          - Persistence functionality
          - Also: dynamic generation of required web-pages
      - Data will also be stored in a MySQL-Database
Relational DB-Schema

                             tblBill
                             pk_id fk_consumer dateOfIssue expirationDate balanced


tblConsumer
pk_id firstName lastName   email



                     tblRemoval
                     pk_id fk_consumer fk_bill fk_drink amount dateOfRemoval



 tblDrink                              tblPrice
  pk_id name capacity                  pk_id fk_drink amount validFrom validUntil
J2EE - Short Overview

  J2EE ≡ “Java 2 Platform Enterprise Edition”
     The newest version is called “Java Platform, Enterprise Edition (Java EE)”
  Provides a programming platform for developing and running
     distributed, and
     multi-tier architecture
     Java applications
  J2EE is based on software components executable in an application
  server
     There are specific runtime environments for specific components
       - Containers
  Allows developers to create an enterprise application that is portable
  between platforms
     „Write once, run anywhere, and reuse everywhere“
     Possible, because J2EE is standardized
J2EE – Short Overview

  One of the most important concepts in J2EE are
  Containers
     Provide an environment in which the components can be
     executed in a controlled and managed way
     They provide services that the components can use either in a
     programmatic or a declarative way
     Allows declarative transaction management (only possible in the
     EJB-container)
  Different types of Containers
     Application Container
     Applet Container
     EJB-Container
      - Entity Beans, Session Beans, Message-driven Beans
     Web-Container
      - Servlets, JSPs
J2EE – Container-Concept
J2EE – Enterprise Java Beans (EJB)


  Three types of EJBs (all executed in the EJB-Container)
     Entity Beans
      - Provide an object-oriented view to the underlying persistent data
      - Container- vs. Bean Managed Persistence
      - Synchronous access using RMI-IIOP
     Session Beans
      -   Modelling business processes
      -   Stateless vs. Stateful Session Beans
      -   They are conversational and perform specific actions
      -   Synchronous access using RMI-IIOP
     Message-driven Beans
      - Similar to Session Beans but provide asynchronous access using
        JMS
J2EE – Bean-Usage

  Beans are registered in a JNDI-repository
     Lookup by name
  Access Beans through interfaces
     Remote Interface
       - Interface to the application-specific services of the bean
            - setName()
            - getName()
            - getDrinkList()
     Home Interface
       - Interface for managing bean instances
            - create()
            - findAll()
            - findByPrimaryKey()
  Each type available in local and remote version (since EJB 2.0)
J2EE – Entity Beans

  An Entity Bean is a Java class with some additional
  features/attributes
     They can be made persistent in an relational database
      - Bean-Managed persistence (BMP)
          - The programmer has to implement several callback methods like
            ejbCreate, ejbRemove, …
      - Container-Managed persistence (CMP)
          - Only a mapping to the relational DB has to be provided by the
            programmer, the rest will be managed by the container
          - Three descriptors involved
              - mysql-ds.xml (located in jboss-4.0.4RC1serverdefaultdeploy)
              - jbosscmp-jdbc.xml
              - ejb-jar.xml
          - Mapping of relations between beans is also done in these descriptors
     Naming convention
      - setProperty()
      - getProperty()
EJB-QL (EJB Query Language)

  Defines queries for the finder and select methods of an entity bean
  with container-managed persistence
  The scope of an EJB-QL query spans the abstract schemas of
  related entity beans that are packaged in the same EJB jar-file.
  They are defined in the deployment descriptor of the entity bean
  (ejb-jar.xml).
     SELECT OBJECT(a) FROM Drink AS a
     SELECT DISTINCT OBJECT(p)
     FROM Drink d
     WHERE d.name = ?1 AND d.capacity = ?2
J2EE – Session Beans

  Used for realizing superior business logic
  Often their methods correspond to use cases and use
  services of one or many Entity Beans
      E.g. Methods which provides appropriate data for the
      presentation layer
  Session Beans encapsulate Entity Beans
  Session Beans represent a classical facade

                                   Entity Bean


   Client       Session Bean       Entity Bean   Entity Bean


                                   Entity Bean
                                                  EJB-Container
J2EE – Value Objects / Data Access Objects (DAO)

  Value objects/DAOs are simple POJOs (plain old java
  objects)
     Are used to exchange application-specific data
     Example: DrinkListEntry
     Simple POJOs can be generated automatically
  Important:
     Value Objects have to be serializable
J2EE - Servlets

  Special Java classes located on the server
  Appropriate for the implementation of web-based user interfaces
  Dynamic generation of web content instead of returning static content
  The client invokes a servlet using an HTTP request
     The web container forwards the request to the servlet.
     The servlet processes it and generates the content dynamically.
     The web container then transmits the response back to the web server and
     finally to the client.
  Servlets can access components running in the EJB container (-> Session
  Beans)
  But: html-code is generated using println-statements
     PrintWriter out = resp.getWriter();
     out.println("<html><head><title>");
     …
  Disadvantages
     Html mixed with Java
     Recompilation required after changes in the source code
J2EE - JSPs

  Special html-pages located on the server
  They can be developed like html-pages but can also include Java-code
     Naturally appropriate for the implementation of web-based user interfaces
     Not particular well suited to perform processing logic
  JSPs are transformed into Servlets at runtime
     No Recompilation required after changes of the layout
  Some important jsp-Tags
     <% … %>
       - Here you can insert Java code, so called “Scriptlets”
     <%@ … %>
       - Among others you can insert an import-statement with libraries to be included
       - Content of this tag is called “Directive”
     <jsp:forward>
       - Can be used to redirect the request to another jsp-page
  Important
     jsp-tags, names, parameters, … are case-sensitive
J2EE – Packaging and Deployment

  Packaging
     All components and deployment descriptors have to be packaged in a
     specific way
     .ear
      - .war
           - *.jsp
           - WEB-INF
                - jboss-web.xml
                - web.xml
      - .jar
           - META-INF
               - ejb-jar.xml
               - jboss.xml
               - jbosscmp-jdbc.xml
      - META-INF
           - application.xml
J2EE – Deployment and Packaging

  Deployment
     Step of transferring the J2EE-Application to the application
     server
     Only the .ear-file has to be deployed



  Doing all that stuff manually would take a lot of time!
     Therefore XDoclet has been developed in order to automate
     these tasks like
      - Generating required interfaces
      - Generating deployment descriptors
      - …
XDoclet


  Open Source code generation engine
  Enables Attribute-Oriented Programming for Java
     Adding meta data to the java source
  XDoclet parses the source files and generates artifacts
  such as XML descriptors and/or source code from it
  Currently XDoclet can only be used as part of the build
  process utilizing Jakarta Ant
  Details look at
     http://xdoclet.sourceforge.net/xdoclet/index.html
XDoclet – Main Idea


              XDoclet-Tags




                    Java-Files            XDoclet-build.xml



                                   ant




            .java        web.xml   jboss.xml    ejb-jar.xml   …
Advantages/Disadvantages of J2EE

  Advantages
     J2EE provides a complete architecture for developing
      - Distributed systems including object persistence, session tracking,
        transaction management, …
     Separation of technical and application-specific code
      - Deployment descriptors
      - Container Managed Persistence
  Disadvantages
     Very complex technology
      - Even simple examples require many interfaces, bean classes, deployment
        descriptors, …
     Many errors occur only at runtime (several steps required until the
     application is running)
           -   Compilation
           -   Packaging
           -   Deployment
           -   Running the application

Más contenido relacionado

La actualidad más candente

EJB 3.0 Java Persistence with Oracle TopLink
EJB 3.0 Java Persistence with Oracle TopLinkEJB 3.0 Java Persistence with Oracle TopLink
EJB 3.0 Java Persistence with Oracle TopLinkBill Lyons
 
Lecture 8 Enterprise Java Beans (EJB)
Lecture 8  Enterprise Java Beans (EJB)Lecture 8  Enterprise Java Beans (EJB)
Lecture 8 Enterprise Java Beans (EJB)Fahad Golra
 
Ejb3.1 for the starter
Ejb3.1 for the starterEjb3.1 for the starter
Ejb3.1 for the startershohancse
 
EJB Interview Questions
EJB Interview QuestionsEJB Interview Questions
EJB Interview Questionsguest346cb1
 
JEE Course - EJB
JEE Course - EJBJEE Course - EJB
JEE Course - EJBodedns
 
Java Web Programming [4/9] : JSP Basic
Java Web Programming [4/9] : JSP BasicJava Web Programming [4/9] : JSP Basic
Java Web Programming [4/9] : JSP BasicIMC Institute
 
Session 4 Tp4
Session 4 Tp4Session 4 Tp4
Session 4 Tp4phanleson
 
Lecture 1: Introduction to JEE
Lecture 1:  Introduction to JEELecture 1:  Introduction to JEE
Lecture 1: Introduction to JEEFahad Golra
 
Java EE Introduction
Java EE IntroductionJava EE Introduction
Java EE Introductionejlp12
 
Java Web Programming [3/9] : Servlet Advanced
Java Web Programming [3/9] : Servlet AdvancedJava Web Programming [3/9] : Servlet Advanced
Java Web Programming [3/9] : Servlet AdvancedIMC Institute
 
AAI 1713-Introduction to Java EE 7
AAI 1713-Introduction to Java EE 7AAI 1713-Introduction to Java EE 7
AAI 1713-Introduction to Java EE 7Kevin Sutter
 

La actualidad más candente (20)

EJB 3.0 Java Persistence with Oracle TopLink
EJB 3.0 Java Persistence with Oracle TopLinkEJB 3.0 Java Persistence with Oracle TopLink
EJB 3.0 Java Persistence with Oracle TopLink
 
Ejb3 Presentation
Ejb3 PresentationEjb3 Presentation
Ejb3 Presentation
 
Lecture 8 Enterprise Java Beans (EJB)
Lecture 8  Enterprise Java Beans (EJB)Lecture 8  Enterprise Java Beans (EJB)
Lecture 8 Enterprise Java Beans (EJB)
 
EJB3 Basics
EJB3 BasicsEJB3 Basics
EJB3 Basics
 
Javabeans .pdf
Javabeans .pdfJavabeans .pdf
Javabeans .pdf
 
Ejb (1)
Ejb (1)Ejb (1)
Ejb (1)
 
Java bean
Java beanJava bean
Java bean
 
Ejb3.1 for the starter
Ejb3.1 for the starterEjb3.1 for the starter
Ejb3.1 for the starter
 
Enterprise java beans
Enterprise java beansEnterprise java beans
Enterprise java beans
 
EJB Interview Questions
EJB Interview QuestionsEJB Interview Questions
EJB Interview Questions
 
JEE Course - EJB
JEE Course - EJBJEE Course - EJB
JEE Course - EJB
 
EJB 3.1 by Bert Ertman
EJB 3.1 by Bert ErtmanEJB 3.1 by Bert Ertman
EJB 3.1 by Bert Ertman
 
Java Web Programming [4/9] : JSP Basic
Java Web Programming [4/9] : JSP BasicJava Web Programming [4/9] : JSP Basic
Java Web Programming [4/9] : JSP Basic
 
jsf2 Notes
jsf2 Notesjsf2 Notes
jsf2 Notes
 
Session 4 Tp4
Session 4 Tp4Session 4 Tp4
Session 4 Tp4
 
Lecture 1: Introduction to JEE
Lecture 1:  Introduction to JEELecture 1:  Introduction to JEE
Lecture 1: Introduction to JEE
 
Java EE Introduction
Java EE IntroductionJava EE Introduction
Java EE Introduction
 
Java EE and Glassfish
Java EE and GlassfishJava EE and Glassfish
Java EE and Glassfish
 
Java Web Programming [3/9] : Servlet Advanced
Java Web Programming [3/9] : Servlet AdvancedJava Web Programming [3/9] : Servlet Advanced
Java Web Programming [3/9] : Servlet Advanced
 
AAI 1713-Introduction to Java EE 7
AAI 1713-Introduction to Java EE 7AAI 1713-Introduction to Java EE 7
AAI 1713-Introduction to Java EE 7
 

Destacado

Administration ubuntu-serveur-installation-ftp-serveur
Administration ubuntu-serveur-installation-ftp-serveurAdministration ubuntu-serveur-installation-ftp-serveur
Administration ubuntu-serveur-installation-ftp-serveurTECOS
 
Présentation de Fedora 15
Présentation de Fedora 15Présentation de Fedora 15
Présentation de Fedora 15Fedora-Fr
 
Fedora, state of the art
Fedora, state of the artFedora, state of the art
Fedora, state of the artAnne Nicolas
 
Administration ubuntu-serveur-installation-ftp-serveur-bernier-francois
Administration ubuntu-serveur-installation-ftp-serveur-bernier-francoisAdministration ubuntu-serveur-installation-ftp-serveur-bernier-francois
Administration ubuntu-serveur-installation-ftp-serveur-bernier-francoisspeegel
 
Projet de fin d'etude gestion informatique
Projet de fin d'etude gestion informatiqueProjet de fin d'etude gestion informatique
Projet de fin d'etude gestion informatiquejihene Ab
 

Destacado (7)

Administration ubuntu-serveur-installation-ftp-serveur
Administration ubuntu-serveur-installation-ftp-serveurAdministration ubuntu-serveur-installation-ftp-serveur
Administration ubuntu-serveur-installation-ftp-serveur
 
Présentation de Fedora 15
Présentation de Fedora 15Présentation de Fedora 15
Présentation de Fedora 15
 
5 serveur dhcp
5 serveur dhcp5 serveur dhcp
5 serveur dhcp
 
Fedora, state of the art
Fedora, state of the artFedora, state of the art
Fedora, state of the art
 
Atelier 3
Atelier 3Atelier 3
Atelier 3
 
Administration ubuntu-serveur-installation-ftp-serveur-bernier-francois
Administration ubuntu-serveur-installation-ftp-serveur-bernier-francoisAdministration ubuntu-serveur-installation-ftp-serveur-bernier-francois
Administration ubuntu-serveur-installation-ftp-serveur-bernier-francois
 
Projet de fin d'etude gestion informatique
Projet de fin d'etude gestion informatiqueProjet de fin d'etude gestion informatique
Projet de fin d'etude gestion informatique
 

Similar a 0012

J2EE - Practical Overview
J2EE - Practical OverviewJ2EE - Practical Overview
J2EE - Practical OverviewSvetlin Nakov
 
ADVANCED JAVA MODULE I & II.ppt
ADVANCED JAVA MODULE I & II.pptADVANCED JAVA MODULE I & II.ppt
ADVANCED JAVA MODULE I & II.pptrani marri
 
Real world java_ee_patterns
Real world java_ee_patternsReal world java_ee_patterns
Real world java_ee_patternsAlassane Diallo
 
Introduction to ejb and struts framework
Introduction to ejb and struts frameworkIntroduction to ejb and struts framework
Introduction to ejb and struts frameworks4al_com
 
Intorduction to struts
Intorduction to strutsIntorduction to struts
Intorduction to strutsAnup72
 
AAI-1713 Introduction to Java EE 7
AAI-1713 Introduction to Java EE 7AAI-1713 Introduction to Java EE 7
AAI-1713 Introduction to Java EE 7WASdev Community
 
Ejb course in-mumbai
Ejb course in-mumbaiEjb course in-mumbai
Ejb course in-mumbaivibrantuser
 
Ejb - september 2006
Ejb  - september 2006Ejb  - september 2006
Ejb - september 2006achraf_ing
 
Enterprise application developement
Enterprise application developementEnterprise application developement
Enterprise application developementArchana Jha
 
Monoliths are so 2001 – What you need is Modularity
Monoliths are so 2001 – What you need is ModularityMonoliths are so 2001 – What you need is Modularity
Monoliths are so 2001 – What you need is ModularityGraham Charters
 
J2ee web services(overview)
J2ee web services(overview)J2ee web services(overview)
J2ee web services(overview)Prafull Jain
 
Summer training java
Summer training javaSummer training java
Summer training javaArshit Rai
 
Summer training java
Summer training javaSummer training java
Summer training javaArshit Rai
 
Developing Java Web Applications
Developing Java Web ApplicationsDeveloping Java Web Applications
Developing Java Web Applicationshchen1
 

Similar a 0012 (20)

J2 Ee Overview
J2 Ee OverviewJ2 Ee Overview
J2 Ee Overview
 
J2EE - Practical Overview
J2EE - Practical OverviewJ2EE - Practical Overview
J2EE - Practical Overview
 
ADVANCED JAVA MODULE I & II.ppt
ADVANCED JAVA MODULE I & II.pptADVANCED JAVA MODULE I & II.ppt
ADVANCED JAVA MODULE I & II.ppt
 
Real world java_ee_patterns
Real world java_ee_patternsReal world java_ee_patterns
Real world java_ee_patterns
 
Introduction to ejb and struts framework
Introduction to ejb and struts frameworkIntroduction to ejb and struts framework
Introduction to ejb and struts framework
 
Intorduction to struts
Intorduction to strutsIntorduction to struts
Intorduction to struts
 
Ejb intro
Ejb introEjb intro
Ejb intro
 
Jsf+ejb 50
Jsf+ejb 50Jsf+ejb 50
Jsf+ejb 50
 
Virtual classroom
Virtual classroomVirtual classroom
Virtual classroom
 
AAI-1713 Introduction to Java EE 7
AAI-1713 Introduction to Java EE 7AAI-1713 Introduction to Java EE 7
AAI-1713 Introduction to Java EE 7
 
Ch4 ejb
Ch4 ejbCh4 ejb
Ch4 ejb
 
Ejb course in-mumbai
Ejb course in-mumbaiEjb course in-mumbai
Ejb course in-mumbai
 
Ejb - september 2006
Ejb  - september 2006Ejb  - september 2006
Ejb - september 2006
 
Enterprise application developement
Enterprise application developementEnterprise application developement
Enterprise application developement
 
Monoliths are so 2001 – What you need is Modularity
Monoliths are so 2001 – What you need is ModularityMonoliths are so 2001 – What you need is Modularity
Monoliths are so 2001 – What you need is Modularity
 
Unite5-EJB-2019.ppt
Unite5-EJB-2019.pptUnite5-EJB-2019.ppt
Unite5-EJB-2019.ppt
 
J2ee web services(overview)
J2ee web services(overview)J2ee web services(overview)
J2ee web services(overview)
 
Summer training java
Summer training javaSummer training java
Summer training java
 
Summer training java
Summer training javaSummer training java
Summer training java
 
Developing Java Web Applications
Developing Java Web ApplicationsDeveloping Java Web Applications
Developing Java Web Applications
 

0012

  • 1. J2EE-Tutorial Developing a J2EE-Application with JBoss Übung SAVES, Sommersemester 2006 Holger Klus Sebastian Herold Technische Universität Kaiserslautern Fachbereich Informatik AG Softwarearchitektur
  • 2. Overview Application Scenario „Drink Account Manager“ Current situation Goals of „Drink Account Manager“ J2EE-Introduction Short Overview Container-Concept Entity Beans Session Beans Servlets/JSP‘s Packaging and Deployment XDoclet
  • 3. Application Scenario „Drink Account Manager“ Current situation Wasser Cola (0,5 Apfelschorle … A printed list with available drinks (0,7 Liter) Liter) (0,7 Liter) and possible consumers is provided in our kitchen Sebastian Every person makes a bar in the Herold corresponding field if he removes a drink Holger Klus Additionally a price list is available Every 4-5 weeks a bill is sent to the … consumers by E-Mail Goals of „Drink Account Manager“ Making bars via Touch-Screen in the Getränk Preis kitchen Wasser (0,7 Liter) 0,40 € Automatic generation of bills and the corresponding E-Mail Cola (0,5 Liter) 0,75 € But first: Implementing basic functionality like Apfelschorle (0,7 Liter) 0,70 € - Show/Add/Edit/Delete - Consumers … - Drinks - Removals - Prices - Bills
  • 4. Application Scenario „Drink Account Manager“ Implementation of this scenario using two different approaches Fat-Client-Approach - Client is a Java application using Hibernate for Object-Relational mapping - All data will be stored in a MySQL-Database Ultra-Thin-Client-Approach (using J2EE) - Client accesses the application through a web interface - Web-pages are generated on server-side and will then be sent to the client - The application runs in an application server including - Business logic and - Persistence functionality - Also: dynamic generation of required web-pages - Data will also be stored in a MySQL-Database
  • 5. Relational DB-Schema tblBill pk_id fk_consumer dateOfIssue expirationDate balanced tblConsumer pk_id firstName lastName email tblRemoval pk_id fk_consumer fk_bill fk_drink amount dateOfRemoval tblDrink tblPrice pk_id name capacity pk_id fk_drink amount validFrom validUntil
  • 6. J2EE - Short Overview J2EE ≡ “Java 2 Platform Enterprise Edition” The newest version is called “Java Platform, Enterprise Edition (Java EE)” Provides a programming platform for developing and running distributed, and multi-tier architecture Java applications J2EE is based on software components executable in an application server There are specific runtime environments for specific components - Containers Allows developers to create an enterprise application that is portable between platforms „Write once, run anywhere, and reuse everywhere“ Possible, because J2EE is standardized
  • 7. J2EE – Short Overview One of the most important concepts in J2EE are Containers Provide an environment in which the components can be executed in a controlled and managed way They provide services that the components can use either in a programmatic or a declarative way Allows declarative transaction management (only possible in the EJB-container) Different types of Containers Application Container Applet Container EJB-Container - Entity Beans, Session Beans, Message-driven Beans Web-Container - Servlets, JSPs
  • 9. J2EE – Enterprise Java Beans (EJB) Three types of EJBs (all executed in the EJB-Container) Entity Beans - Provide an object-oriented view to the underlying persistent data - Container- vs. Bean Managed Persistence - Synchronous access using RMI-IIOP Session Beans - Modelling business processes - Stateless vs. Stateful Session Beans - They are conversational and perform specific actions - Synchronous access using RMI-IIOP Message-driven Beans - Similar to Session Beans but provide asynchronous access using JMS
  • 10. J2EE – Bean-Usage Beans are registered in a JNDI-repository Lookup by name Access Beans through interfaces Remote Interface - Interface to the application-specific services of the bean - setName() - getName() - getDrinkList() Home Interface - Interface for managing bean instances - create() - findAll() - findByPrimaryKey() Each type available in local and remote version (since EJB 2.0)
  • 11. J2EE – Entity Beans An Entity Bean is a Java class with some additional features/attributes They can be made persistent in an relational database - Bean-Managed persistence (BMP) - The programmer has to implement several callback methods like ejbCreate, ejbRemove, … - Container-Managed persistence (CMP) - Only a mapping to the relational DB has to be provided by the programmer, the rest will be managed by the container - Three descriptors involved - mysql-ds.xml (located in jboss-4.0.4RC1serverdefaultdeploy) - jbosscmp-jdbc.xml - ejb-jar.xml - Mapping of relations between beans is also done in these descriptors Naming convention - setProperty() - getProperty()
  • 12. EJB-QL (EJB Query Language) Defines queries for the finder and select methods of an entity bean with container-managed persistence The scope of an EJB-QL query spans the abstract schemas of related entity beans that are packaged in the same EJB jar-file. They are defined in the deployment descriptor of the entity bean (ejb-jar.xml). SELECT OBJECT(a) FROM Drink AS a SELECT DISTINCT OBJECT(p) FROM Drink d WHERE d.name = ?1 AND d.capacity = ?2
  • 13. J2EE – Session Beans Used for realizing superior business logic Often their methods correspond to use cases and use services of one or many Entity Beans E.g. Methods which provides appropriate data for the presentation layer Session Beans encapsulate Entity Beans Session Beans represent a classical facade Entity Bean Client Session Bean Entity Bean Entity Bean Entity Bean EJB-Container
  • 14. J2EE – Value Objects / Data Access Objects (DAO) Value objects/DAOs are simple POJOs (plain old java objects) Are used to exchange application-specific data Example: DrinkListEntry Simple POJOs can be generated automatically Important: Value Objects have to be serializable
  • 15. J2EE - Servlets Special Java classes located on the server Appropriate for the implementation of web-based user interfaces Dynamic generation of web content instead of returning static content The client invokes a servlet using an HTTP request The web container forwards the request to the servlet. The servlet processes it and generates the content dynamically. The web container then transmits the response back to the web server and finally to the client. Servlets can access components running in the EJB container (-> Session Beans) But: html-code is generated using println-statements PrintWriter out = resp.getWriter(); out.println("<html><head><title>"); … Disadvantages Html mixed with Java Recompilation required after changes in the source code
  • 16. J2EE - JSPs Special html-pages located on the server They can be developed like html-pages but can also include Java-code Naturally appropriate for the implementation of web-based user interfaces Not particular well suited to perform processing logic JSPs are transformed into Servlets at runtime No Recompilation required after changes of the layout Some important jsp-Tags <% … %> - Here you can insert Java code, so called “Scriptlets” <%@ … %> - Among others you can insert an import-statement with libraries to be included - Content of this tag is called “Directive” <jsp:forward> - Can be used to redirect the request to another jsp-page Important jsp-tags, names, parameters, … are case-sensitive
  • 17. J2EE – Packaging and Deployment Packaging All components and deployment descriptors have to be packaged in a specific way .ear - .war - *.jsp - WEB-INF - jboss-web.xml - web.xml - .jar - META-INF - ejb-jar.xml - jboss.xml - jbosscmp-jdbc.xml - META-INF - application.xml
  • 18. J2EE – Deployment and Packaging Deployment Step of transferring the J2EE-Application to the application server Only the .ear-file has to be deployed Doing all that stuff manually would take a lot of time! Therefore XDoclet has been developed in order to automate these tasks like - Generating required interfaces - Generating deployment descriptors - …
  • 19. XDoclet Open Source code generation engine Enables Attribute-Oriented Programming for Java Adding meta data to the java source XDoclet parses the source files and generates artifacts such as XML descriptors and/or source code from it Currently XDoclet can only be used as part of the build process utilizing Jakarta Ant Details look at http://xdoclet.sourceforge.net/xdoclet/index.html
  • 20. XDoclet – Main Idea XDoclet-Tags Java-Files XDoclet-build.xml ant .java web.xml jboss.xml ejb-jar.xml …
  • 21. Advantages/Disadvantages of J2EE Advantages J2EE provides a complete architecture for developing - Distributed systems including object persistence, session tracking, transaction management, … Separation of technical and application-specific code - Deployment descriptors - Container Managed Persistence Disadvantages Very complex technology - Even simple examples require many interfaces, bean classes, deployment descriptors, … Many errors occur only at runtime (several steps required until the application is running) - Compilation - Packaging - Deployment - Running the application