Understanding EJB   By:   Asha Pathik   Aniruddha Ray
Saastha InfotechAgenda• Overview and Basic Concepts  –   What is EJB?  –   When to use EJB  –   Containers  –   Evolution ...
Saastha InfotechOverview and Basic concepts        What is EJB?             3
Saastha InfotechWhat is EJB ( Enterprise Java Beans )?• EJB is the J2EE standard for developing and  deploying server-side...
Saastha InfotechOverview and Basic concepts       When to use EJB             5
Saastha InfotechWhen to use EJB• For large scale applications where resources and  data are distributed.• When the applica...
Saastha InfotechOverview and Basic conceptsEvolution of Enterprise JavaBeans               7
Saastha InfotechEvolution of Enterprise Java Beans – Part 1• EJB release 1.0 focused on the following aspects:   – defined...
Saastha InfotechEvolution of Enterprise Java Beans – Part 2• EJB release 2.0 focused on the following aspects:   – defined...
Saastha InfotechEvolution of Enterprise Java Beans – Part 3• EJB release 2.1 focused on the following aspects:   – enablin...
Saastha InfotechOverview and Basic concepts         Containers            11
Saastha InfotechContainers• Are the interface between a component and low-level  platform-specific functionality that supp...
Saastha InfotechEJB Components                 13
Saastha InfotechEJB Components  Session Beans       14
Saastha InfotechSession Bean : Concepts• A Session Bean is non-persistent object that  implements some business logic.   –...
Saastha InfotechStateful Session Bean : Part(1)Conversational Bean• Consists of attributes and referenced objects :   –   ...
Saastha InfotechStateful Session Bean : Part(2)• Passivation:   – container serializes Bean instance and saves it to disk ...
Saastha InfotechStateful Session Bean : Life Cycle                       18
Saastha InfotechStateless Session Bean• All instances are equivalent• Private to one client only during one call• Pooled w...
Saastha InfotechEJB Components  Entity Beans      20
Saastha InfotechEntity Bean : Concept• An Entity Bean represents an object-oriented view of  some entities stored in a per...
Saastha InfotechPersistence Management• Bean-Managed Persistence (BMP) : any java-accessible  data storage is possible   –...
Saastha InfotechPrimary Key• A Primary Key of an Entity Bean consists of one or more  persistent Bean attributes   – value...
Saastha InfotechActivation and Passivation• The EJB Container can passivate unused Entity  Beans  – ejbPassivate is invoke...
Saastha InfotechEntity Bean : Life Cycle                       25
Saastha InfotechEJB ComponentsMessage-driven Beans        26
Saastha InfotechMessage-Driven Bean – Concepts (1)• Like a Stateless Session Bean, a Message-driven Bean  only provides a ...
Saastha InfotechMessage-Driven Bean – Concepts (2)• A Message-driven bean is assigned to a JMS  destination by means of th...
Saastha InfotechMessage-Driven Bean – Concepts (3)• A message driven bean is an enterprise bean that  allows J2EE applicat...
Saastha InfotechContents of an EJB• Interfaces: The remote and home interface for  remote access. Local and local home acc...
Upcoming SlideShare
Loading in …5
×

EJB 3.0 and J2EE

1,174 views

Published on

Ashi's presentation on EJB 3.0

Published in: Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,174
On SlideShare
0
From Embeds
0
Number of Embeds
43
Actions
Shares
0
Downloads
214
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

EJB 3.0 and J2EE

  1. 1. Understanding EJB By: Asha Pathik Aniruddha Ray
  2. 2. Saastha InfotechAgenda• Overview and Basic Concepts – What is EJB? – When to use EJB – Containers – Evolution of EJB• EJB Components – Types of Enterprise Beans – Session Beans – Entity Beans – Message-driven Beans• Creating an EJB• Summary 2
  3. 3. Saastha InfotechOverview and Basic concepts What is EJB? 3
  4. 4. Saastha InfotechWhat is EJB ( Enterprise Java Beans )?• EJB is the J2EE standard for developing and deploying server-side distributed components in java• It defines a contract between components and application servers that enables any component to run on any compliant server – it is the ubiquitous industry standard – portability is possible – rapid application development – physically, EJB is two things • a specification • a set of Java interfaces 4
  5. 5. Saastha InfotechOverview and Basic concepts When to use EJB 5
  6. 6. Saastha InfotechWhen to use EJB• For large scale applications where resources and data are distributed.• When the application is running on different servers at many locations.• Where scalability is critical.• Where transactions are required to ensure data integrity• When a variety of clients need to handled 6
  7. 7. Saastha InfotechOverview and Basic conceptsEvolution of Enterprise JavaBeans 7
  8. 8. Saastha InfotechEvolution of Enterprise Java Beans – Part 1• EJB release 1.0 focused on the following aspects: – defined the distinct “EJB roles” that are assumed by the component architecture – defined the client view of enterprise beans – defined the developer’s view of enterprise beans – defined the responsibilities of EJB Container provider and Server Provider – defined the format of ejb.jar file, EJB’s unit of deployment• EJB release 1.1 augmented these with following: – provided better support for application assembly and deployment – specified in greater detail the responsibilities of the individual EJB roles 8
  9. 9. Saastha InfotechEvolution of Enterprise Java Beans – Part 2• EJB release 2.0 focused on the following aspects: – defined message-driven bean and the integration with the JMS – provided local client view and support for efficient, lightweight access to EJB from local clients – defined new architecture for container persistence – support for management of relationships among entity beans – declarative query syntax for finder and select methods for entity beans with container-managed persistence – support for additional methods in home interface – support for run-as security identity – provided for network interoperability among servers 9
  10. 10. Saastha InfotechEvolution of Enterprise Java Beans – Part 3• EJB release 2.1 focused on the following aspects: – enabling enterprise beans to implement and utilize web services – providing a container-managed timer services – enhancing EJB QL with additional ORDER BY and aggregate operators – enhancing the message-driven bean component type to other messaging types• The EJB release 3.0 is focused on a simplification of the Enterprise JavaBeans architecture from the developer’s point of view. 10
  11. 11. Saastha InfotechOverview and Basic concepts Containers 11
  12. 12. Saastha InfotechContainers• Are the interface between a component and low-level platform-specific functionality that supports the component – components are simple set of programs that are capable of performing a particular business logic• Provide configurable settings : like data accessibility• Manages non-configurable settings like enterprise bean and servlet life cycles, database connection resource pooling, data persistence etc.• Before a J2EE component can be executed, it must be assembled into J2EE application and deployed into its container 12
  13. 13. Saastha InfotechEJB Components 13
  14. 14. Saastha InfotechEJB Components Session Beans 14
  15. 15. Saastha InfotechSession Bean : Concepts• A Session Bean is non-persistent object that implements some business logic. – private to one client connection – represents an interactive session – not recoverable after system crash or shutdown! – when client terminates, bean terminates i.e. no longer active• A Stateful Session Bean has Conversational State – activation/ passivation of a Bean is possible – E.g. items reviewed in a session at some sites.• A Stateless Session Bean has no Conversational State – no activation or passivation – pooling of stateless Session Beans by the container – very efficient – E.g. computing value using a formula. 15
  16. 16. Saastha InfotechStateful Session Bean : Part(1)Conversational Bean• Consists of attributes and referenced objects : – all non-transient attributes of the Bean – referenced data in the database – open connections to network – references to other Beans – etc.• Exists during one client session• A Conversation State is not persistent and is not automatically rolled back when a transaction fails! 16
  17. 17. Saastha InfotechStateful Session Bean : Part(2)• Passivation: – container serializes Bean instance and saves it to disk – preparation for Passivation is done with the method ejbPassivate: • close all existing connections • resolve all external references• Activation: – de-serialize Bean instance from disk – afterwards, ejbActivate method is invoked to: • re-establish external references • re-establish connections• If non-serializable objects are part of the state, these methods must be implemented in the Bean class 17
  18. 18. Saastha InfotechStateful Session Bean : Life Cycle 18
  19. 19. Saastha InfotechStateless Session Bean• All instances are equivalent• Private to one client only during one call• Pooled while not in use 19
  20. 20. Saastha InfotechEJB Components Entity Beans 20
  21. 21. Saastha InfotechEntity Bean : Concept• An Entity Bean represents an object-oriented view of some entities stored in a persistent, crash-resistant storage (usually a relational database) – persistent and transient (modifier transient) attributes are allowed, but only persistent attributes will be saved in database. – each entity bean typically has an underlying table in a RDBMS( business data), and each instance of the bean corresponds to a row in that table. – transactional and recoverable on a server crash.• Shared among multiple clients ( no per-client state)• Primary Key : a unique attribute of bean or a serializable class (Primary Key Class) with one or more attributes• Two Beans with same Home Interface and same Primary Key are regarded as identical ( Bean Identity) 21
  22. 22. Saastha InfotechPersistence Management• Bean-Managed Persistence (BMP) : any java-accessible data storage is possible – implements persistence mechanisms in ejbLoad resp. ejbStore – implements ejbActivate, ejbPassivate and ejbRemove – ejbCreate must return a ‘real’ primary key ( e.g. return pk;)• Container-Managed Persistence (CMP) : Container controls access to (usually) a relational database – empty implementation of ejbLoad, ejbStore, ejbActivate, ejbPassivate and ejbRemove – ejbCreate returns ‘null’ as primary key ( return null) – Object-Relational Mapping between Bean attributes and database entries ( Vendor –specific) – more details later 22
  23. 23. Saastha InfotechPrimary Key• A Primary Key of an Entity Bean consists of one or more persistent Bean attributes – values of primary key attributes must be unique for a Bean instance – primary key attributes must be serializable• The primary key class … – is a serializable class with one or several attributes which ( together) acts as primary key of an Entity Bean • one can use e.g. Long or String for single primary key attributes or specific classes • all primary key attributes must be persistent Bean attributes – must be declared in the Bean’s Deployment Descriptor 23
  24. 24. Saastha InfotechActivation and Passivation• The EJB Container can passivate unused Entity Beans – ejbPassivate is invoked – used resources ( e.g. database connections, references to other Beans etc. ) are freed – bean instance is pooled• The Bean is activated when used again – an instance of this Bean is taken from the pool – ejbActivate is invoked – needed resources are occupied ( e.g. database connections are re-established) 24
  25. 25. Saastha InfotechEntity Bean : Life Cycle 25
  26. 26. Saastha InfotechEJB ComponentsMessage-driven Beans 26
  27. 27. Saastha InfotechMessage-Driven Bean – Concepts (1)• Like a Stateless Session Bean, a Message-driven Bean only provides a piece of business logic without state management ( similar life cycle)• A Message-driven bean must implement the interfaces javax.ejb.MessageDrivenBean and javax.ejb.MessageListener – MessageListener declares a method public void onMessage(Message msg) which will be invoked when message arrives• A Message-driven Bean has no client-visible interfaces 27
  28. 28. Saastha InfotechMessage-Driven Bean – Concepts (2)• A Message-driven bean is assigned to a JMS destination by means of the Deployment Descriptor element – message-driven destination• The bean is invoked by the container, when a JMS message to this destination arrives 28
  29. 29. Saastha InfotechMessage-Driven Bean – Concepts (3)• A message driven bean is an enterprise bean that allows J2EE applications to process messages asynchronously• It acts a JMS listener, which is similar to an event listener except that it receives messages instead of events• The messages can be sent to any J2EE component or a non-J2EE system using JMS• It retains no data or conversational state 29
  30. 30. Saastha InfotechContents of an EJB• Interfaces: The remote and home interface for remote access. Local and local home accesses for local access.• Enterprise bean class: Implements the methods defined in the above interfaces.• Deployment descriptor: An XML file that specifies information about the bean such as its type, transaction attributes, etc.• Helper classes: non-bean classes needed by the enterprise bean class such as utility and exception classes. 30

×