SlideShare una empresa de Scribd logo
1 de 53
Descargar para leer sin conexión
Enterprise JavaBeans

    Ruslana Svidzinska
         CSE690
What is EJB?
q   An EJB is a specialized, non-visual
    JavaBean that runs on a server.

q   EJB technology supports application
    development based on a multiplier,
    distributed object architecture in which
    most of application’s logic is moved
    from the client to the server.
Server Components
q   Server components are application
    components that run in an application
    server.
Java Application Servers
q A Java application server provides an
  optimized execution environment for
  server-side Java application
  components.
q A Java application server delivers a
  high-performance, highly scalable,
  robust execution environment
  specifically suited to support Internet
  enabled application systems.
WORA
q   The Enterprise JavaBeans architecture
    defines a standard model for Java
    application servers to support “Write
    Once, Run Anywhere” (WORA)
    portability
Component Portability
EJB technology takes the WORA concept
  to a new level.
EJB completely portable across any
  vendor’s EJB compliant application
  server. The EJB environment
  automatically maps the component to
  the underlying vendor-specific
  infrastructure services.
Overview of EJB Technology
EJB Component Model
 Enterprise JavaBeans component model logically
 extends the JavaBeans component model to
 support server component.
 Server components are reusable, prepackaged
 pieces of application functionality that are
 designed to run in an application server.
 EJB can be assembled and customized at
 deployment time using tools provided by an EJB-
 compliant Java application server.
Simplifying Development.
The EJB architecture provides an
integrated application framework.
An EJB server automatically manages a
number of tricky middleware services on
behalf of the application components.
EJB component-builders can concentrate
on writing business logic rather than
complex middleware
Simplifying Development (cont’d)

 RESULT:
 •Application get developed more quickly
 •Code is of better quality.
What EJB Accomplishes
You can take any Java class and with little effort make
it a distributed, secure, transactional class
You can take any data source and make the data
source appear to be a collection of Java objects
    – Eliminates distinction between data from a
       database and any other source
    – All information is accessed through Java objects
    – All SQL is cleanly encapsulated in Java objects
        q true object-oriented programming

        q high reusability

    – Database objects work with the full Java class
What EJB Means to Us
q   Developers can focus on writing business logic
    rather than writing low-level infrastructure like data
    access, concurrency, transactions, threading, etc.
     – Reduces development time
     – Reduces complexity
     – Increases quality and reliability
q   The knowledge about EJB is portable among
    many different products because EJB products are
    based on a common standard
q   Greater reuse because code is located in shareable,
    server objects
So....let’s take a look at
 Enterprise JavaBeans
5   A specification from JavaSoft
5   Enterprise JavaBeans defines a server component
    model for the development and deployment of Java
    applications based on a multi-tier, distributed object
    architecture
5   The Enterprise JavaBeans specification defines:
     – A container model
     – A definition of the services the container needs to
       provide to an Enterprise JavaBean, and vice versa
     – How a container should manage Enterprise
       JavaBeans
Enterprise JavaBeans
    Architecture
The EJB architecture specifies the
responsibilities and interactions among
EJB entities
             EJB Servers                        EJB Containers
             Enterprise Beans                   EJB Clients


                                 Enterprise         Enterprise
                                   Bean               Bean



                                    EJB Container
Clients
                                       EJB Server
EJB Server
                 Provides a Runtime Environment

 q   The EJB Server provides system services and
     manages resources
      – Process and thread management
      – System resources management
      – Database connection pooling and caching
      – Management API



                                      EJB Server
EJB Container
                Provides a Run-time Environment
                      for an Enterprise Bean
q   Hosts the Enterprise JavaBeans
q   Provides services to Enterprise JavaBeans
     – Naming
     – Life cycle management
     – Persistence (state management)
     – Transaction Management
     – Security
q   Likely provided by server vendor


                                                EJB Container

                                                EJB Server
Enterprise JavaBeans
 q   A specialized Java class where the real business logic
     lives
       – May be developer-written or tool-generated
 q   Distributed over a network
 q   Transactional
 q   Secure
 q   Server vendors provide tools that automatically
     generate distribution, transaction and security
     behavior                          Enterprise Enterprise
                                       Bean        Bean



                                        EJB Container

                                          EJB Server
EJB Clients
 q   Client access is controlled by the container in
     which the enterprise Bean is deployed
 q   Clients locates an Enterprise JavaBean through
     Java Naming and Directory Interface (JNDI)
 q   RMI is the standard method for accessing a bean
     over a network


                                 Enterprise    Enterprise
                                   Bean          Bean



                                    EJB Container
         Clients
                                       EJB Server
What’s Unique About EJB
                   Declarative Programming Model
 q   Mandates a container model where common services are
     declared, not programmed
      – At development and/or deployment time, attributes defining
        the bean’s transaction and security characteristics are
        specified
      – At deployment time, the container introspects the Enterprise
        JavaBean attributes for the runtime services it requires and
        wraps the bean with the required functionality
      – At runtime, the container intercepts all calls to the object
         y   Provides transactional, threading and security behavior
             required before the method invocation
         y   Invokes the method on the object
         y   Cleans up after the call
Understanding EJB Components
JavaBeans vs Enterprise
           JavaBeans

q   Enterprise JavaBeans is a framework for
    building and deploying server-side Java
    components
q   JavaBeans is a framework for client-side Java
    components
q   Conceptually related because both are
    components
q   The specifications are different
q   The specifications do not build on each other
    or rely on each other
What’s in the EJB Specification
      ~200 Pages of technical material for EJB vendors
q   Goals for the Release
q   Roles and Scenarios
q   Fundamentals (Scope of EJB)
q   Session and Entity Beans
q   Transactions, Exceptions, Distribution
q   EJB Bean and Container Responsibilities
q   API Reference
                                    EJB Vendors
                              Have to do all the WORK
Enterprise EJB Scenario                                Existing
                                                      Enterprise
                                                      Middleware
                             EJB Application
 Clients      Web Server
                                 Server
                                                      CICS Programs

 Browser                    EJB Container
                                        Credit Card

                Servlet    Shopping
                                                        Databases
                             Cart

                                          Inventory
Application

                                                        SAP Modules
                           EJB Server
An inside look at the various
        components of EJB
q   Bean Class is written by the developer
q   EJBHome and EJBObject interfaces and classes
    control access to the Bean class       EJB Container
q   Deployment Descriptor




                                            EJBHome



                                                         EJBHome
                                            Interface
    and MANIFEST describe




                                                           Class
    security and transactional
    characteristics of the Bean                       EJB Class




                                            EJBObject



                                                         EJBObject
                                             Interface



                                                           Class
             Written by Developer
             Generated at Development
             Generated at Deployment
                                             Deployment
                                                                     Manifest
                                             Descriptor

                                           EJB Server
EJBHome Interface and Class
q   Used to get a reference to a bean’s remote interface
q   Provides bean creation services
     – myFoo = fooHome.create() instead of
        myFoo = new foo()
     – Supports multiple signatures to create EJB instances
q   Similar to class factory                EJB Container
    in COM and CORBA




                                                        EJBHome
                                           EJBHome
                                            Interface
    May be generated by




                                                          Class
q
    tools that come with an
    EJB server
q   Also manages EJB:
     – querying (Entity Bean)
     – deleting (Entity Bean)

                                           EJB Server
Interface javax.ejb.EJBHome
q   Home objects must implement this interface
q   Returns a reference to a bean by creating or finding
    it
q   Every bean has a EJBHome interface that provides
    methods for getting references to one or more beans
     – create methods are used to create new beans
     – there can be many create methods, similar to a
       class having many constructors
q   Provides a bean removal interface also
q   The EJBHome Class implementation is provided by
    the EJB Server Provider
Sample EJBHome Interface
public interface CustomerHome extends EJBHome

{
    public abstract Customer create(String id, String name)
        throws RemoteException, CreateException;

    public abstract Enumeration findByName(String val)
        throws RemoteException, FinderException;
    public abstract RemoteEnumeration findStateByName(String val)
        throws RemoteException, FinderException;
    public abstract Customer findByPrimaryKey(CustomerKey pkey)
        throws RemoteException, FinderException;
    public abstract Customer findByPrimaryKey(CustomerKey pkey, int findSource)
        throws RemoteException, FinderException;
    public abstract CustomerState findStateByPrimaryKey(CustomerKey pkey, int
findSource)
        throws RemoteException, FinderException;
}
Client makes invocation to EJBHome
 Class via the EJBHome Interface
q   Client calls one of the create() methods on the
    EJBHome Class. The EJBHome class can have
    multiple create() signatures.
                                          EJB Container




                                          EJBHome
                                            Class
                   create()



         Clients


                                        EJB Server
EJBHome Class instantiates
     the Bean Class
q   When the create() method is
    called in the EJBHome Class, it
    is responsible for instantiating
    the Bean class.                     EJB Container




                                        EJBHome
                                          Class
                                                        EJB
                                                        Class


         Clients


                                       EJB Server
EJBObject Interface and Class
q   Intercepts calls to the EJB Class to add support for:
     – transactions
     – security
     – threading                                  EJB Container
q   EJBObject class has the same methods
     as the bean and delegates to the bean
    for actual behavior
q   EJBObject class checks security and




                                                               EJBObject
                                                  EJBObject
    sets up transaction before delegating



                                                   Interface



                                                                 Class
    method call to the bean
q   Clients can never get a reference to
    a bean’s EJB Class, only the EJBObject
    interface                                     EJB Server
Interface javax.ejb.EJBObject
      public interface javax.ejb.EJBObject extends java.rmi.Remote
      {
          EJBHome getEJBHome() throws RemoteException;
          Handle  getHandle() throws RemoteException;
          Object  getPrimaryKey() throws RemoteException;
          boolean isIdentical(EJBObject obj) throws RemoteException;
          void    remove() throws RemoteException, RemoveException;
      }

 q   Represents a specific bean instance
 q   Remote objects must implement this interface
 q   Primary key is an object that represents the primary
     key for a specific instance of a bean
 q   The EJBObject Class implementation is
     provided by the EJB Server Provider
Sample EJBObject Interface
  public interface Customer extends EJBObject

  {
      public abstract String getId() throws RemoteException;
      public abstract String getName() throws RemoteException;
      public abstract void setName(String val) throws RemoteException;

      public abstract boolean getNameNull() throws RemoteException;
      public abstract boolean getIdNull() throws RemoteException;

      public abstract Enumeration getAccounts() throws RemoteException;
      public abstract void addToAccounts(Account relInst) throws RemoteException;
      public abstract void removeFromAccounts(Account relInst)
          throws RemoteException;
  }
After the EJBHome Class
        instantiates the Bean...
q   The EJBHome Class will instantiate the EJBObject Class,
    initializing it with the remote object reference to the Bean
    Class.
q   The Client will now                         EJB Container
    communicate to the




                                                  EJBHome
    EJBObject Class.




                                                    Class
                                                     Passes ref
    The EJBObject Class                               of Bean
    will delegate the call to
    the Bean.




                                                  EJBHome
                                                    Class
                     Client now has reference                EJB
           Clients   to the EJBObject Class.
                                                             Class
                      NOT A REFERENCE
                          TO THE BEAN
                            ITSELF!!!!          EJB Server
Client communicates to the Bean
  class via the EJBObject Class
q   Client never has a direct reference
    to the Bean.
q   The EJBObject Interface is the
                                           EJB Container
    interface for the Bean, so the
    EJBObject Class “delegates” the




                                            EJBHome
    calls to the Bean.




                                              Class
q   The EJBObject Class
    implementation will be
    generated using vendor
    tools.




                                            EJBHome
                                              Class
                                                           EJB
                                                           Class

           Clients
                                          EJB Server
EJB Class
q   A bean has a single Java class at its core
     – This class is written by a developer if it’s a session
       bean
     – This class is sometimes generated by a tool if it’s an
       entity bean
q   Implements application-specific business logic
q   Implements one of the following contracts:
    – javax.ejb.EntityBean
    – javax.ejb.SessionBean
q   These contracts provide for consistent behavior when
    activating beans, passivating beans, reading data,
    writing data
q   Every container can expect these methods in every bean
Deployment Descriptor
q   Allows you to declare transaction and security attributes,
    NO PROGRAMMING REQUIRED!!!
q   An EJB Deployment Descriptor describes the classes,
    interfaces and declarative behavior of an EJB
q   Deployment Descriptor format is serialized objects:
    –   javax.ejb.deployment.ControlDescriptor
    –   javax.ejb.deployment.DeploymentDescriptor
    –   javax.ejb.deployment.EntityDescriptor
    –
                                                  EJB Container
        javax.ejb.deployment.SessionDescriptor
q   The deployment descriptor
    is generated by server tools
    The deployment descriptor
                                                   Deployment
q                                                   Descriptor

    classes are defined in the                     EJB Server
    EJB specification
Let’s look at the value of the
   Deployment Descriptor
q   Step #1 - Write your Bean implementation.
q   Step #2 - Compile this Java source into Java bytecode
q   Step #3 - Developer is responsible for creating a
    serialized deployment descriptor for the bean. Most
    likely using a tool from the vendor. EJB tools will use
    Reflection API on the compiled EJB Bean to determine:
    –   name of Bean class
    –   methods
    –   parameters
    –   return values
q   Step #4 - The EJB Tool will use the above information to
    generate a Deployment Descriptor file and an editor
    with which to set transaction and security attributes.
Sample Contents of a
        Deployment Descriptor
         PS(TicketDemo,Concert,deployment_descriptor)
           Entity{
                     VersionNumber
                     {
                                  1.0
                     }
                     BeanHomeName
                     {
                                  ConcertHome
                     }

                    ControlDescriptor
                    {
                                IsolationLevel
                                {
                                            TRANSACTION_READ_COMMITTED
                                }
  Method Level                   Method
Security Attribute               {
                                    int getId() throws java.rmi.RemoteException
                                 }

                                 RunAsMode
                                 {
    Method Level                             SYSTEM_IDENTITY
                                 }
Transaction Attribute
                                 TransactionAttribute
                                 {
                                             TX_SUPPORTS
                                 }
Enterprise JavaBean Packaging
q   Enterprise JavaBeans are comprised of many Java files
q   These files are put in a JAR file
     – A JAR file is a ZIP file with a MANIFEST that
       describes the contents of the file
     – A MANIFEST is a simple text file
        q   Name: bank/AccountDeployment.ser
            Enterprise-Bean: True
q   A JAR file can contain more than one Enterprise
    JavaBean
                                               EJB Container




                                                               Manifest


                                                EJB Server
Bean Development Process
q   Implement the EJB Class
q   Specify the remote interface
                                                  EJB Container
q   Specify the home interface
    Specify security and




                                                               EJBHome
                                                  EJBHome
                                                   Interface
q




                                                                 Class
    transactional characteristics
    using vendor tools
    (DeploymentDescriptor)                                                 EJB Class
    Use vendor tools to




                                                               EJBObject
                                                  EJBObject
q




                                                   Interface



                                                                 Class
    generate supporting
    code and package
    components in EJB-jar
q   Iterate...      Written by Developer
                                                   Deployment
                                                                              Manifest
                       Generated at Development    Descriptor

                       Generated at Deployment    EJB Server
Enterprise Beans:
Session Beans & Entity Beans
     Session Beans vs. Entity Beans
       Bean-Managed Persistence
     Container-Managed Persistence
       EJB Transaction Attributes
Comparing Session and Entity
          Beans
      Session Beans                       Entity Beans
                                q   Optional for EJB 1.0
  q   Mandatory for EJB
                                q   Represents
      1.0
                                    underlying data
  q   Represents a specific         object or context
      client                         (clients share instance)
      (1 instance per client)   q   Long-lived
  q   Short-lived               q   Persistent
  q   Transient                 q   Can be a class that
  q   Can be any Java               maps to persistent
                                    data
      class                         (e.g., database)
  q   May be transactional      q   Always transactional
  q   Business Logic Beans      q   Beans which
Session Beans
                 Represents Process
q   A transient agent for an individual client that
    executes on a server (e.g., ShoppingCart)
q   Session beans are often a client of multiple entity
    beans
q   Implements javax.ejb.SessionBean interface
q   State management types for session EJBs
    – stateful - session bean may maintain state information
      across method calls
    – stateless - session bean may be used to service multiple
      clients
    – a stateless session bean can only have a single no-argument
      create() method in its Home interface
Session Beans - Stateful or
                  Stateless
q   A Stateful Session Bean maintains a one-to-one relationship
    with a Client. It maintains a user “session”. Most common
    example is an e-commerce application with a “shopping cart”
    unique for each user.
    – Container will automatically “swap out” the Session bean if it is inactive. Here
      the container calls the ejbPassivate() method to save any private data to some
      physical storage.
    – When container receives new request, the Container will call the ejbActivate()
      method to restore the Session Bean.
q   A Stateless Session Bean can be accessed by multiple incoming
    clients and keeps no private data. It does not maintain a
    unique session with a client.
    – Keeps no persistent data. If it crashes, container simply starts another one and
      the client transparently connects.
    – All access to the Bean is serialized.
Entity Bean
                      Represents Data
q   Implements javax.ejb.EntityBean interface
q   Maps a data source to a Java class
    –   table, view, join or stored procedure in a relational database
    –   a set of related records in a database
    –   legacy data
q   Each instance of an entity bean is one row of data
q   Each instance of an entity bean is uniquely identified
    by a primary key
q   An Entity Bean can also have additional methods for
    business logic, etc.
Defining an Entity Bean
q   An Entity Bean must implement the
    javax.ejb.EntityBean interface. In addition, the Entity
    Bean must implement an ejbCreate() method for
    each create() method on the Home Interface.
q   When the Home class gets a call to create(), it calls
    the ejbCreate() method on the Entity Bean with the
    corresponding signature.
q   ejbStore() and ejbLoad() used to synchronize Entity
    Bean data with the database.
q   ejbActivate() and ejbPassivate() used for notification
    that Entity Bean state is being written to the
    database or restored from the database.
Since Entity Beans represent
           Data...
q Each instance of an Entity Bean is
  uniquely identified by a primary key
  object
q Primary key can be saved and used
  later to regain access to the same EJB
  object identity
    – fooKey = fooBean.getPrimaryKey();
      …
      fooBean =
      fooHome.findByPrimaryKey(fooKey);
Entity Bean Operations
 q   BeanHome.create() is equivalent to an SQL INSERT
      – Causes a new database record to be inserted into
        the database:
         q   customerBean = customerHome.create(”Jane",
             ”Rodgers");
 q   BeanHome.findSomething() is equivalent to an SQL
     SELECT
      – Creates a bean instance that represents queried data from
        a database
      – Can also return an enumeration to represent multiple rows
        of data
 q   There will typically be many findSomething() methods:
         q   customerBean =
                customerHome.findByName(firstName, lastName);
         q   customerBeans = customerHome.findByZip(94023);
Entity Bean Operations
q   BeanHome.remove() and EJBObject.remove()
    are equivalent to an SQL DELETE
    – causes the database record to be deleted from the
      database
       q   customerBean = customerHome.findByName(“Jane”,
           “Rodgers”);
           customerBean.remove();

q   Commiting a change on a found object is
    equivalent to an SQL UPDATE
       q   customerBean = customerHome.findByName(“Jane”,
           “Rodgers”);
           customerBean.setEmailAddress(“jane.rodgers@yahoo.
           com”);
EJB Persistence
q Provides Entity Beans the ability to
  store and retrieve their state
q Can be implemented by a bean
    – Bean Managed Persistence
q   Can be implemented by a container
    – Container Managed Persistence
Bean Managed Persistence
q   The entity bean is responsible for its persistent
    behavior
q   EJB developer must implement database access
     – ejbCreate(…), ejbLoad(), ejbStore(), ejbRemove()
q   Not automated, developer manually creates mapping
    through JDBC calls
q   Not as reusable
     – Hard-code database access within class
q   Advanced features like connection pooling and
    caching are difficult to support because of reliance on
    hand written code
Container Managed Persistence
    q   The EJB container is responsible for
        persistence
    q   The container provides tools that generate
        code in the EJB class that maps methods in
        the bean to a result set
        – Can map to a table, view, join or stored procedure in a
          database
        – Server provides automated mapping to convert relational
          data to bean instances
    q   Advanced features like connection pooling
        and caching are easily supported
    q   High reuse
EJB Transaction Support
q   EJB allows you to either DECLARE transactions or CODE
    THEM EXPLICITLY.
     – TO DECLARE: EJB allows you to declare transaction
       support in the Deployment Descriptor and then have the
       container take care of the details inside the remote class
        q   Transaction attributes specified at the bean and method level
    – FOR EXPLICIT CONTROL: An EJB Container is required
      to implement javax.transaction.UserTransaction
        q   Provides an interface to a transaction service
        q   Can be used by EJB clients and enterprise beans that are declared
            to manage their own transactions (TX_BEAN_MANAGED)
    – EJB specification does not support nested transactions
EJB Transaction Attributes
   q   TX_NOT_SUPPORTED
       –   Cannot execute within a transaction
       –   Suspends any existing transaction while method is called
   q   TX_SUPPORTS
       –   Executes with or without a transaction
       –   Doesn’t suspend existing transaction
   q   TX_REQUIRED
       –   Executes within a transaction
       –   If no transaction exists, starts a new one and commits it when method completes
   q   TX_REQUIRES_NEW
       –   Always starts a new transaction and commits it when method completes
       –   Suspends existing transaction
   q   TX_BEAN_MANAGED
       –   The bean manages its own transaction control
       –   Suspends existing transaction
   q   TX_MANDATORY
       –   Must execute within a transaction
       –   If no transaction exists, throws the TransactionRequiredException

Más contenido relacionado

La actualidad más candente

Summer training java
Summer training javaSummer training java
Summer training javaArshit Rai
 
2012 04-09-v2-tdp-1167-cdi-bestpractices-final
2012 04-09-v2-tdp-1167-cdi-bestpractices-final2012 04-09-v2-tdp-1167-cdi-bestpractices-final
2012 04-09-v2-tdp-1167-cdi-bestpractices-finalRohit Kelapure
 
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
 
JEE Course - EJB
JEE Course - EJBJEE Course - EJB
JEE Course - EJBodedns
 
Aravind vinnakota ejb_architecture
Aravind vinnakota ejb_architectureAravind vinnakota ejb_architecture
Aravind vinnakota ejb_architecturetayab4687
 
Ejb3.1 for the starter
Ejb3.1 for the starterEjb3.1 for the starter
Ejb3.1 for the startershohancse
 
2012 04-06-v2-tdp-1163-java e-evsspringshootout-final
2012 04-06-v2-tdp-1163-java e-evsspringshootout-final2012 04-06-v2-tdp-1163-java e-evsspringshootout-final
2012 04-06-v2-tdp-1163-java e-evsspringshootout-finalRohit Kelapure
 
Entity beans in java
Entity beans in javaEntity beans in java
Entity beans in javaAcp Jamod
 
Enterprise Java Beans( E)
Enterprise  Java  Beans( E)Enterprise  Java  Beans( E)
Enterprise Java Beans( E)vikram singh
 

La actualidad más candente (20)

Java EE EJB Applications
Java EE EJB ApplicationsJava EE EJB Applications
Java EE EJB Applications
 
Summer training java
Summer training javaSummer training java
Summer training java
 
EJB 2
EJB 2EJB 2
EJB 2
 
2012 04-09-v2-tdp-1167-cdi-bestpractices-final
2012 04-09-v2-tdp-1167-cdi-bestpractices-final2012 04-09-v2-tdp-1167-cdi-bestpractices-final
2012 04-09-v2-tdp-1167-cdi-bestpractices-final
 
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
 
JEE Course - EJB
JEE Course - EJBJEE Course - EJB
JEE Course - EJB
 
EJB 3.0 and J2EE
EJB 3.0 and J2EEEJB 3.0 and J2EE
EJB 3.0 and J2EE
 
Aravind vinnakota ejb_architecture
Aravind vinnakota ejb_architectureAravind vinnakota ejb_architecture
Aravind vinnakota ejb_architecture
 
Ejb3.1 for the starter
Ejb3.1 for the starterEjb3.1 for the starter
Ejb3.1 for the starter
 
enterprise java bean
enterprise java beanenterprise java bean
enterprise java bean
 
2012 04-06-v2-tdp-1163-java e-evsspringshootout-final
2012 04-06-v2-tdp-1163-java e-evsspringshootout-final2012 04-06-v2-tdp-1163-java e-evsspringshootout-final
2012 04-06-v2-tdp-1163-java e-evsspringshootout-final
 
Entity beans in java
Entity beans in javaEntity beans in java
Entity beans in java
 
Introduction to EJB
Introduction to EJBIntroduction to EJB
Introduction to EJB
 
EJB3 Basics
EJB3 BasicsEJB3 Basics
EJB3 Basics
 
Enterprise Java Beans( E)
Enterprise  Java  Beans( E)Enterprise  Java  Beans( E)
Enterprise Java Beans( E)
 
EJB 3.1 by Bert Ertman
EJB 3.1 by Bert ErtmanEJB 3.1 by Bert Ertman
EJB 3.1 by Bert Ertman
 
Enterprise JavaBeans(EJB)
Enterprise JavaBeans(EJB)Enterprise JavaBeans(EJB)
Enterprise JavaBeans(EJB)
 
Ejb3 Presentation
Ejb3 PresentationEjb3 Presentation
Ejb3 Presentation
 
EJB .
EJB .EJB .
EJB .
 
Java bean
Java beanJava bean
Java bean
 

Destacado

20150402 DuurzaamDoenCafe door Vera Dalm
20150402 DuurzaamDoenCafe door Vera Dalm20150402 DuurzaamDoenCafe door Vera Dalm
20150402 DuurzaamDoenCafe door Vera DalmVera Dalm
 
Ploughshare intro 2014
Ploughshare intro 2014Ploughshare intro 2014
Ploughshare intro 2014ctgoff
 
Ploughshare Innovations Introduction & Overview
Ploughshare Innovations Introduction & OverviewPloughshare Innovations Introduction & Overview
Ploughshare Innovations Introduction & Overviewctgoff
 
Stainedglass tutorial
Stainedglass tutorialStainedglass tutorial
Stainedglass tutoriallbpeden
 
IGI Listed on Commercial Integrator as a
IGI Listed on Commercial Integrator as a IGI Listed on Commercial Integrator as a
IGI Listed on Commercial Integrator as a Aaron Vlk
 
Sustainability 02.26.13 short
Sustainability 02.26.13 shortSustainability 02.26.13 short
Sustainability 02.26.13 shortbradandemilyrobb
 
Milieu Centraal Brussel 24 juni
Milieu Centraal   Brussel 24 juniMilieu Centraal   Brussel 24 juni
Milieu Centraal Brussel 24 juniVera Dalm
 

Destacado (8)

20150402 DuurzaamDoenCafe door Vera Dalm
20150402 DuurzaamDoenCafe door Vera Dalm20150402 DuurzaamDoenCafe door Vera Dalm
20150402 DuurzaamDoenCafe door Vera Dalm
 
Ploughshare intro 2014
Ploughshare intro 2014Ploughshare intro 2014
Ploughshare intro 2014
 
Ploughshare Innovations Introduction & Overview
Ploughshare Innovations Introduction & OverviewPloughshare Innovations Introduction & Overview
Ploughshare Innovations Introduction & Overview
 
Stainedglass tutorial
Stainedglass tutorialStainedglass tutorial
Stainedglass tutorial
 
IGI Listed on Commercial Integrator as a
IGI Listed on Commercial Integrator as a IGI Listed on Commercial Integrator as a
IGI Listed on Commercial Integrator as a
 
kukuli
kukulikukuli
kukuli
 
Sustainability 02.26.13 short
Sustainability 02.26.13 shortSustainability 02.26.13 short
Sustainability 02.26.13 short
 
Milieu Centraal Brussel 24 juni
Milieu Centraal   Brussel 24 juniMilieu Centraal   Brussel 24 juni
Milieu Centraal Brussel 24 juni
 

Similar a Ejb (1)

The Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans TechnologyThe Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans TechnologySimon Ritter
 
ADVANCED JAVA MODULE I & II.ppt
ADVANCED JAVA MODULE I & II.pptADVANCED JAVA MODULE I & II.ppt
ADVANCED JAVA MODULE I & II.pptrani marri
 
EJ NOV-18 (Sol) (E-next.in).pdf
EJ NOV-18 (Sol) (E-next.in).pdfEJ NOV-18 (Sol) (E-next.in).pdf
EJ NOV-18 (Sol) (E-next.in).pdfSPAMVEDANT
 
Introduction to java_ee
Introduction to java_eeIntroduction to java_ee
Introduction to java_eeYogesh Bindwal
 
Java Ide Day 2008 - Presentation on JDeveloper by Paolo Ramasso
Java Ide Day 2008 - Presentation on JDeveloper by Paolo RamassoJava Ide Day 2008 - Presentation on JDeveloper by Paolo Ramasso
Java Ide Day 2008 - Presentation on JDeveloper by Paolo RamassoJUG Genova
 
Ejb training institute in navi-mumbai
Ejb training institute in navi-mumbaiEjb training institute in navi-mumbai
Ejb training institute in navi-mumbaivibrantuser
 
Real world java_ee_patterns
Real world java_ee_patternsReal world java_ee_patterns
Real world java_ee_patternsAlassane Diallo
 
Java online training from hyderabad
Java online training from hyderabadJava online training from hyderabad
Java online training from hyderabadrevanthonline
 

Similar a Ejb (1) (20)

The Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans TechnologyThe Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans Technology
 
Ejb
EjbEjb
Ejb
 
Introcution to EJB
Introcution to EJBIntrocution to EJB
Introcution to EJB
 
ADVANCED JAVA MODULE I & II.ppt
ADVANCED JAVA MODULE I & II.pptADVANCED JAVA MODULE I & II.ppt
ADVANCED JAVA MODULE I & II.ppt
 
Ch4 ejb
Ch4 ejbCh4 ejb
Ch4 ejb
 
J2EE Online Training
J2EE Online TrainingJ2EE Online Training
J2EE Online Training
 
Ejbandjsp 200119145750
Ejbandjsp 200119145750Ejbandjsp 200119145750
Ejbandjsp 200119145750
 
Virtual classroom
Virtual classroomVirtual classroom
Virtual classroom
 
Ejb and jsp
Ejb and jspEjb and jsp
Ejb and jsp
 
Unite5-EJB-2019.ppt
Unite5-EJB-2019.pptUnite5-EJB-2019.ppt
Unite5-EJB-2019.ppt
 
EJ NOV-18 (Sol) (E-next.in).pdf
EJ NOV-18 (Sol) (E-next.in).pdfEJ NOV-18 (Sol) (E-next.in).pdf
EJ NOV-18 (Sol) (E-next.in).pdf
 
Ejb intro
Ejb introEjb intro
Ejb intro
 
Introduction to java_ee
Introduction to java_eeIntroduction to java_ee
Introduction to java_ee
 
JEE Programming - 02 The Containers
JEE Programming - 02 The ContainersJEE Programming - 02 The Containers
JEE Programming - 02 The Containers
 
Java Ide Day 2008 - Presentation on JDeveloper by Paolo Ramasso
Java Ide Day 2008 - Presentation on JDeveloper by Paolo RamassoJava Ide Day 2008 - Presentation on JDeveloper by Paolo Ramasso
Java Ide Day 2008 - Presentation on JDeveloper by Paolo Ramasso
 
Ejb training institute in navi-mumbai
Ejb training institute in navi-mumbaiEjb training institute in navi-mumbai
Ejb training institute in navi-mumbai
 
J2 ee architecture
J2 ee architectureJ2 ee architecture
J2 ee architecture
 
Real world java_ee_patterns
Real world java_ee_patternsReal world java_ee_patterns
Real world java_ee_patterns
 
P20CSP105-AdvJavaProg.pptx
P20CSP105-AdvJavaProg.pptxP20CSP105-AdvJavaProg.pptx
P20CSP105-AdvJavaProg.pptx
 
Java online training from hyderabad
Java online training from hyderabadJava online training from hyderabad
Java online training from hyderabad
 

Último

Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...itnewsafrica
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 

Último (20)

Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 

Ejb (1)

  • 1. Enterprise JavaBeans Ruslana Svidzinska CSE690
  • 2. What is EJB? q An EJB is a specialized, non-visual JavaBean that runs on a server. q EJB technology supports application development based on a multiplier, distributed object architecture in which most of application’s logic is moved from the client to the server.
  • 3. Server Components q Server components are application components that run in an application server.
  • 4. Java Application Servers q A Java application server provides an optimized execution environment for server-side Java application components. q A Java application server delivers a high-performance, highly scalable, robust execution environment specifically suited to support Internet enabled application systems.
  • 5. WORA q The Enterprise JavaBeans architecture defines a standard model for Java application servers to support “Write Once, Run Anywhere” (WORA) portability
  • 6. Component Portability EJB technology takes the WORA concept to a new level. EJB completely portable across any vendor’s EJB compliant application server. The EJB environment automatically maps the component to the underlying vendor-specific infrastructure services.
  • 7. Overview of EJB Technology EJB Component Model Enterprise JavaBeans component model logically extends the JavaBeans component model to support server component. Server components are reusable, prepackaged pieces of application functionality that are designed to run in an application server. EJB can be assembled and customized at deployment time using tools provided by an EJB- compliant Java application server.
  • 8. Simplifying Development. The EJB architecture provides an integrated application framework. An EJB server automatically manages a number of tricky middleware services on behalf of the application components. EJB component-builders can concentrate on writing business logic rather than complex middleware
  • 9. Simplifying Development (cont’d) RESULT: •Application get developed more quickly •Code is of better quality.
  • 10. What EJB Accomplishes You can take any Java class and with little effort make it a distributed, secure, transactional class You can take any data source and make the data source appear to be a collection of Java objects – Eliminates distinction between data from a database and any other source – All information is accessed through Java objects – All SQL is cleanly encapsulated in Java objects q true object-oriented programming q high reusability – Database objects work with the full Java class
  • 11. What EJB Means to Us q Developers can focus on writing business logic rather than writing low-level infrastructure like data access, concurrency, transactions, threading, etc. – Reduces development time – Reduces complexity – Increases quality and reliability q The knowledge about EJB is portable among many different products because EJB products are based on a common standard q Greater reuse because code is located in shareable, server objects
  • 12. So....let’s take a look at Enterprise JavaBeans 5 A specification from JavaSoft 5 Enterprise JavaBeans defines a server component model for the development and deployment of Java applications based on a multi-tier, distributed object architecture 5 The Enterprise JavaBeans specification defines: – A container model – A definition of the services the container needs to provide to an Enterprise JavaBean, and vice versa – How a container should manage Enterprise JavaBeans
  • 13. Enterprise JavaBeans Architecture The EJB architecture specifies the responsibilities and interactions among EJB entities  EJB Servers  EJB Containers  Enterprise Beans  EJB Clients Enterprise Enterprise Bean Bean EJB Container Clients EJB Server
  • 14. EJB Server Provides a Runtime Environment q The EJB Server provides system services and manages resources – Process and thread management – System resources management – Database connection pooling and caching – Management API EJB Server
  • 15. EJB Container Provides a Run-time Environment for an Enterprise Bean q Hosts the Enterprise JavaBeans q Provides services to Enterprise JavaBeans – Naming – Life cycle management – Persistence (state management) – Transaction Management – Security q Likely provided by server vendor EJB Container EJB Server
  • 16. Enterprise JavaBeans q A specialized Java class where the real business logic lives – May be developer-written or tool-generated q Distributed over a network q Transactional q Secure q Server vendors provide tools that automatically generate distribution, transaction and security behavior Enterprise Enterprise Bean Bean EJB Container EJB Server
  • 17. EJB Clients q Client access is controlled by the container in which the enterprise Bean is deployed q Clients locates an Enterprise JavaBean through Java Naming and Directory Interface (JNDI) q RMI is the standard method for accessing a bean over a network Enterprise Enterprise Bean Bean EJB Container Clients EJB Server
  • 18. What’s Unique About EJB Declarative Programming Model q Mandates a container model where common services are declared, not programmed – At development and/or deployment time, attributes defining the bean’s transaction and security characteristics are specified – At deployment time, the container introspects the Enterprise JavaBean attributes for the runtime services it requires and wraps the bean with the required functionality – At runtime, the container intercepts all calls to the object y Provides transactional, threading and security behavior required before the method invocation y Invokes the method on the object y Cleans up after the call
  • 20. JavaBeans vs Enterprise JavaBeans q Enterprise JavaBeans is a framework for building and deploying server-side Java components q JavaBeans is a framework for client-side Java components q Conceptually related because both are components q The specifications are different q The specifications do not build on each other or rely on each other
  • 21. What’s in the EJB Specification ~200 Pages of technical material for EJB vendors q Goals for the Release q Roles and Scenarios q Fundamentals (Scope of EJB) q Session and Entity Beans q Transactions, Exceptions, Distribution q EJB Bean and Container Responsibilities q API Reference EJB Vendors Have to do all the WORK
  • 22. Enterprise EJB Scenario Existing Enterprise Middleware EJB Application Clients Web Server Server CICS Programs Browser EJB Container Credit Card Servlet Shopping Databases Cart Inventory Application SAP Modules EJB Server
  • 23. An inside look at the various components of EJB q Bean Class is written by the developer q EJBHome and EJBObject interfaces and classes control access to the Bean class EJB Container q Deployment Descriptor EJBHome EJBHome Interface and MANIFEST describe Class security and transactional characteristics of the Bean EJB Class EJBObject EJBObject Interface Class Written by Developer Generated at Development Generated at Deployment Deployment Manifest Descriptor EJB Server
  • 24. EJBHome Interface and Class q Used to get a reference to a bean’s remote interface q Provides bean creation services – myFoo = fooHome.create() instead of myFoo = new foo() – Supports multiple signatures to create EJB instances q Similar to class factory EJB Container in COM and CORBA EJBHome EJBHome Interface May be generated by Class q tools that come with an EJB server q Also manages EJB: – querying (Entity Bean) – deleting (Entity Bean) EJB Server
  • 25. Interface javax.ejb.EJBHome q Home objects must implement this interface q Returns a reference to a bean by creating or finding it q Every bean has a EJBHome interface that provides methods for getting references to one or more beans – create methods are used to create new beans – there can be many create methods, similar to a class having many constructors q Provides a bean removal interface also q The EJBHome Class implementation is provided by the EJB Server Provider
  • 26. Sample EJBHome Interface public interface CustomerHome extends EJBHome { public abstract Customer create(String id, String name) throws RemoteException, CreateException; public abstract Enumeration findByName(String val) throws RemoteException, FinderException; public abstract RemoteEnumeration findStateByName(String val) throws RemoteException, FinderException; public abstract Customer findByPrimaryKey(CustomerKey pkey) throws RemoteException, FinderException; public abstract Customer findByPrimaryKey(CustomerKey pkey, int findSource) throws RemoteException, FinderException; public abstract CustomerState findStateByPrimaryKey(CustomerKey pkey, int findSource) throws RemoteException, FinderException; }
  • 27. Client makes invocation to EJBHome Class via the EJBHome Interface q Client calls one of the create() methods on the EJBHome Class. The EJBHome class can have multiple create() signatures. EJB Container EJBHome Class create() Clients EJB Server
  • 28. EJBHome Class instantiates the Bean Class q When the create() method is called in the EJBHome Class, it is responsible for instantiating the Bean class. EJB Container EJBHome Class EJB Class Clients EJB Server
  • 29. EJBObject Interface and Class q Intercepts calls to the EJB Class to add support for: – transactions – security – threading EJB Container q EJBObject class has the same methods as the bean and delegates to the bean for actual behavior q EJBObject class checks security and EJBObject EJBObject sets up transaction before delegating Interface Class method call to the bean q Clients can never get a reference to a bean’s EJB Class, only the EJBObject interface EJB Server
  • 30. Interface javax.ejb.EJBObject public interface javax.ejb.EJBObject extends java.rmi.Remote { EJBHome getEJBHome() throws RemoteException; Handle getHandle() throws RemoteException; Object getPrimaryKey() throws RemoteException; boolean isIdentical(EJBObject obj) throws RemoteException; void remove() throws RemoteException, RemoveException; } q Represents a specific bean instance q Remote objects must implement this interface q Primary key is an object that represents the primary key for a specific instance of a bean q The EJBObject Class implementation is provided by the EJB Server Provider
  • 31. Sample EJBObject Interface public interface Customer extends EJBObject { public abstract String getId() throws RemoteException; public abstract String getName() throws RemoteException; public abstract void setName(String val) throws RemoteException; public abstract boolean getNameNull() throws RemoteException; public abstract boolean getIdNull() throws RemoteException; public abstract Enumeration getAccounts() throws RemoteException; public abstract void addToAccounts(Account relInst) throws RemoteException; public abstract void removeFromAccounts(Account relInst) throws RemoteException; }
  • 32. After the EJBHome Class instantiates the Bean... q The EJBHome Class will instantiate the EJBObject Class, initializing it with the remote object reference to the Bean Class. q The Client will now EJB Container communicate to the EJBHome EJBObject Class. Class Passes ref The EJBObject Class of Bean will delegate the call to the Bean. EJBHome Class Client now has reference EJB Clients to the EJBObject Class. Class NOT A REFERENCE TO THE BEAN ITSELF!!!! EJB Server
  • 33. Client communicates to the Bean class via the EJBObject Class q Client never has a direct reference to the Bean. q The EJBObject Interface is the EJB Container interface for the Bean, so the EJBObject Class “delegates” the EJBHome calls to the Bean. Class q The EJBObject Class implementation will be generated using vendor tools. EJBHome Class EJB Class Clients EJB Server
  • 34. EJB Class q A bean has a single Java class at its core – This class is written by a developer if it’s a session bean – This class is sometimes generated by a tool if it’s an entity bean q Implements application-specific business logic q Implements one of the following contracts: – javax.ejb.EntityBean – javax.ejb.SessionBean q These contracts provide for consistent behavior when activating beans, passivating beans, reading data, writing data q Every container can expect these methods in every bean
  • 35. Deployment Descriptor q Allows you to declare transaction and security attributes, NO PROGRAMMING REQUIRED!!! q An EJB Deployment Descriptor describes the classes, interfaces and declarative behavior of an EJB q Deployment Descriptor format is serialized objects: – javax.ejb.deployment.ControlDescriptor – javax.ejb.deployment.DeploymentDescriptor – javax.ejb.deployment.EntityDescriptor – EJB Container javax.ejb.deployment.SessionDescriptor q The deployment descriptor is generated by server tools The deployment descriptor Deployment q Descriptor classes are defined in the EJB Server EJB specification
  • 36. Let’s look at the value of the Deployment Descriptor q Step #1 - Write your Bean implementation. q Step #2 - Compile this Java source into Java bytecode q Step #3 - Developer is responsible for creating a serialized deployment descriptor for the bean. Most likely using a tool from the vendor. EJB tools will use Reflection API on the compiled EJB Bean to determine: – name of Bean class – methods – parameters – return values q Step #4 - The EJB Tool will use the above information to generate a Deployment Descriptor file and an editor with which to set transaction and security attributes.
  • 37. Sample Contents of a Deployment Descriptor PS(TicketDemo,Concert,deployment_descriptor) Entity{ VersionNumber { 1.0 } BeanHomeName { ConcertHome } ControlDescriptor { IsolationLevel { TRANSACTION_READ_COMMITTED } Method Level Method Security Attribute { int getId() throws java.rmi.RemoteException } RunAsMode { Method Level SYSTEM_IDENTITY } Transaction Attribute TransactionAttribute { TX_SUPPORTS }
  • 38. Enterprise JavaBean Packaging q Enterprise JavaBeans are comprised of many Java files q These files are put in a JAR file – A JAR file is a ZIP file with a MANIFEST that describes the contents of the file – A MANIFEST is a simple text file q Name: bank/AccountDeployment.ser Enterprise-Bean: True q A JAR file can contain more than one Enterprise JavaBean EJB Container Manifest EJB Server
  • 39. Bean Development Process q Implement the EJB Class q Specify the remote interface EJB Container q Specify the home interface Specify security and EJBHome EJBHome Interface q Class transactional characteristics using vendor tools (DeploymentDescriptor) EJB Class Use vendor tools to EJBObject EJBObject q Interface Class generate supporting code and package components in EJB-jar q Iterate... Written by Developer Deployment Manifest Generated at Development Descriptor Generated at Deployment EJB Server
  • 40. Enterprise Beans: Session Beans & Entity Beans Session Beans vs. Entity Beans Bean-Managed Persistence Container-Managed Persistence EJB Transaction Attributes
  • 41. Comparing Session and Entity Beans Session Beans Entity Beans q Optional for EJB 1.0 q Mandatory for EJB q Represents 1.0 underlying data q Represents a specific object or context client (clients share instance) (1 instance per client) q Long-lived q Short-lived q Persistent q Transient q Can be a class that q Can be any Java maps to persistent data class (e.g., database) q May be transactional q Always transactional q Business Logic Beans q Beans which
  • 42. Session Beans Represents Process q A transient agent for an individual client that executes on a server (e.g., ShoppingCart) q Session beans are often a client of multiple entity beans q Implements javax.ejb.SessionBean interface q State management types for session EJBs – stateful - session bean may maintain state information across method calls – stateless - session bean may be used to service multiple clients – a stateless session bean can only have a single no-argument create() method in its Home interface
  • 43. Session Beans - Stateful or Stateless q A Stateful Session Bean maintains a one-to-one relationship with a Client. It maintains a user “session”. Most common example is an e-commerce application with a “shopping cart” unique for each user. – Container will automatically “swap out” the Session bean if it is inactive. Here the container calls the ejbPassivate() method to save any private data to some physical storage. – When container receives new request, the Container will call the ejbActivate() method to restore the Session Bean. q A Stateless Session Bean can be accessed by multiple incoming clients and keeps no private data. It does not maintain a unique session with a client. – Keeps no persistent data. If it crashes, container simply starts another one and the client transparently connects. – All access to the Bean is serialized.
  • 44. Entity Bean Represents Data q Implements javax.ejb.EntityBean interface q Maps a data source to a Java class – table, view, join or stored procedure in a relational database – a set of related records in a database – legacy data q Each instance of an entity bean is one row of data q Each instance of an entity bean is uniquely identified by a primary key q An Entity Bean can also have additional methods for business logic, etc.
  • 45. Defining an Entity Bean q An Entity Bean must implement the javax.ejb.EntityBean interface. In addition, the Entity Bean must implement an ejbCreate() method for each create() method on the Home Interface. q When the Home class gets a call to create(), it calls the ejbCreate() method on the Entity Bean with the corresponding signature. q ejbStore() and ejbLoad() used to synchronize Entity Bean data with the database. q ejbActivate() and ejbPassivate() used for notification that Entity Bean state is being written to the database or restored from the database.
  • 46. Since Entity Beans represent Data... q Each instance of an Entity Bean is uniquely identified by a primary key object q Primary key can be saved and used later to regain access to the same EJB object identity – fooKey = fooBean.getPrimaryKey(); … fooBean = fooHome.findByPrimaryKey(fooKey);
  • 47. Entity Bean Operations q BeanHome.create() is equivalent to an SQL INSERT – Causes a new database record to be inserted into the database: q customerBean = customerHome.create(”Jane", ”Rodgers"); q BeanHome.findSomething() is equivalent to an SQL SELECT – Creates a bean instance that represents queried data from a database – Can also return an enumeration to represent multiple rows of data q There will typically be many findSomething() methods: q customerBean = customerHome.findByName(firstName, lastName); q customerBeans = customerHome.findByZip(94023);
  • 48. Entity Bean Operations q BeanHome.remove() and EJBObject.remove() are equivalent to an SQL DELETE – causes the database record to be deleted from the database q customerBean = customerHome.findByName(“Jane”, “Rodgers”); customerBean.remove(); q Commiting a change on a found object is equivalent to an SQL UPDATE q customerBean = customerHome.findByName(“Jane”, “Rodgers”); customerBean.setEmailAddress(“jane.rodgers@yahoo. com”);
  • 49. EJB Persistence q Provides Entity Beans the ability to store and retrieve their state q Can be implemented by a bean – Bean Managed Persistence q Can be implemented by a container – Container Managed Persistence
  • 50. Bean Managed Persistence q The entity bean is responsible for its persistent behavior q EJB developer must implement database access – ejbCreate(…), ejbLoad(), ejbStore(), ejbRemove() q Not automated, developer manually creates mapping through JDBC calls q Not as reusable – Hard-code database access within class q Advanced features like connection pooling and caching are difficult to support because of reliance on hand written code
  • 51. Container Managed Persistence q The EJB container is responsible for persistence q The container provides tools that generate code in the EJB class that maps methods in the bean to a result set – Can map to a table, view, join or stored procedure in a database – Server provides automated mapping to convert relational data to bean instances q Advanced features like connection pooling and caching are easily supported q High reuse
  • 52. EJB Transaction Support q EJB allows you to either DECLARE transactions or CODE THEM EXPLICITLY. – TO DECLARE: EJB allows you to declare transaction support in the Deployment Descriptor and then have the container take care of the details inside the remote class q Transaction attributes specified at the bean and method level – FOR EXPLICIT CONTROL: An EJB Container is required to implement javax.transaction.UserTransaction q Provides an interface to a transaction service q Can be used by EJB clients and enterprise beans that are declared to manage their own transactions (TX_BEAN_MANAGED) – EJB specification does not support nested transactions
  • 53. EJB Transaction Attributes q TX_NOT_SUPPORTED – Cannot execute within a transaction – Suspends any existing transaction while method is called q TX_SUPPORTS – Executes with or without a transaction – Doesn’t suspend existing transaction q TX_REQUIRED – Executes within a transaction – If no transaction exists, starts a new one and commits it when method completes q TX_REQUIRES_NEW – Always starts a new transaction and commits it when method completes – Suspends existing transaction q TX_BEAN_MANAGED – The bean manages its own transaction control – Suspends existing transaction q TX_MANDATORY – Must execute within a transaction – If no transaction exists, throws the TransactionRequiredException