SlideShare uma empresa Scribd logo
1 de 60
Baixar para ler offline
Enterprise Java Bean 3.0
               Yet Another Introduction…




               Kelum Senanayake
Tag-Cloud

ResourceInjection
                      StatelessSessionBean

   EnterpriseJavaBeans
 EntityBean               StatefulSessionBean
                    MessageDrivenBean
  JavaEE                                  POJO
                       JavaPersistenceAPI
Annotations                Transactions
Enterprise Java Beans
Enterprise Java Beans (EJB)
• A platform for building portable, reusable, and
  scalable business applications.
• Allows to focus on building business logic
  without having to spend time on building
  infrastructure code for services such as
  transactions, security, automated persistence.
• An EJB is a piece of Java code that executes in
  a specialized runtime environment.
EJB as a component …
• A component should effectively encapsulate
  application behavior.
• All we need to know is what to pass in and
  what to expect back.
• Components can be reusable.
• Three types of EJB components:
  – Session beans
  – Message-driven beans
  – Entities
EJB as a framework …
• EJB components live in a container.
• Together, the components, or EJBs, and the
  container can be viewed as a framework.
• EJB framework provides valuable services for
  enterprise application development
EJB History
• EJB 1.0 (1998-03-24)
  – Defined the responsibilities of EJB Container provider
  – Defined the distinct “EJB Roles”
• EJB 1.1 (1999-12-17)
  – XML deployment descriptors
  – Session Beans, Entity Beans
  – Remote interface
• EJB 2.0 (2001-08-22)
  – Message-Driven Beans
  – Entity 2.x and EJB QL
EJB History …contd
• EJB 2.1 (2003-11-24)
  – EJB Timer Service
  – Web service support
• EJB 3.0 (2006-05-11)
  – POJO, Annotations
  – Dependency injection
• EJB 3.1 (2009-12-10)
  –   Local view without interface
  –   .war packaging of EJB components
  –   Singletons (Singleton Session Beans)
  –   EJB Lite: definition of a subset of EJB
  –   @Asynchronous for session beans
EJB 3.0 vs EJB 2.1
• EJB 3.0 is much faster than EJB 2
• An EJB 2.1 session bean must implement the
  SessionBean interface
• EJB 3.0 session bean class includes only business
  methods.
• EJB 3.0 interfaces are POJI business interfaces
  and do not require home and component
  interfaces.
• EJB 2.1 must have the deployment descriptor. But
  optional in EJB 3.0. Annotations are added to the
  language.
EJB 3.0 vs EJB 2.1 …contd
• EJB 3 introduced persistence API for database
  access. In EJB 2 you can use Entity bean.
• An EJB 2.1 Entity EJB bean class must implement
  the EntityBean interface and must provide
  implementation to the ejbCreate() and
  ejbPostCreate() methods.
• EJB 2.1 entity bean includes the home,
  component, local home and local component
  interfaces that extend the EJBHome, EJBObject,
  EJBLocalHome and EJBObject interfaces
  respectively.
EJB 3.0 vs EJB 2.1 …contd
• An EJB 2.1 bean must define resource-ref in ejb-
  jar.xml to lookup resources. An EJB 3.0 bean can
  use either dependency injection or JNDI lookup.
• An EJB 2.1 message-driven must implement the
  javax.ejb.MessgeDrivenBean interface.
• Standardized Simplified persistence with POJO
  – You couldn’t send an EJB 2 entity bean across the wire
    in different tiers.
  – They are permanently attached to the database.
  – You have to write data transfer objects
Why choose EJB 3.0?
• Ease of use
  – POJO programming, annotations in favor of verbose
    XML, heavy use of sensible defaults & JPA
• Integrated solution stack
  – EJB 3 offers a complete stack of server solutions
  – Persistence, messaging, lightweight scheduling,
    remoting, web services, dependency injection (DI) and
    interceptors
  – You won’t have to spend a lot of time looking for
    third-party tools
Why EJB 3.0 …contd
• Open Java EE standard
  – EJB is a critical part of the Java EE standard
  – EJB 3 has an open, public API specification
  – The open standard leads to broader vendor
    support
  – You don’t have to depend on a proprietary solution
Why EJB 3.0 …contd
• Broad vendor support
  – You are not at the mercy of the ups and downs of
    a particular company or group of people
  – Vendors have historically competed against one
    another by providing value-added nonstandard
    features
• Stable, high-quality code base
  – Clustering, load balancing, and failover support
    with no changes to code, no third-party tool
    integration, and relatively simple configuration
Why EJB 3.0 …contd
• Unit-testable POJO components
  – All EJB 3 components are POJOs, they can easily
    be executed outside the container
  – It is possible to unit-test all component business
    logic using testing frameworks
• Annotations and descriptors are not mutually
  exclusive
  – Deployment descriptor entries override
    configuration values hard-coded into EJB
    components
JavaEE Container
The Container
• When you build a simple Java class, you need a
  Java Virtual Machine (JVM) to execute it.
• Think of the container as simply an extension of
  the basic idea of a JVM.
• JVM transparently manages memory on your
  behalf.
• The container transparently provides EJB
  component services
  – Transactions, security management
  – Remoting and web services support
Container …contd
• A Java EE container is an application server
  solution that supports EJB 3, a web container,
  and other Java EE APIs and services.
• JPA is completely pluggable and separable.
  – Persistence provider and container in an EJB 3
    solution need not come from the same vendor
  – You could use Hibernate inside a BEA WebLogic
    container
Hello World !
HelloUser Example
HelloUser Example (Client)
Dependency injection vs. JNDI lookup
• With EJB 2, you have to write the same few lines
  of boilerplate code many times to do a JNDI
  lookup.
• In EJB 3, JNDI lookups have been turned into
  simple configuration using metadata-based
  dependency injection (DI)
• JNDI : It’s the responsibility of the client to do a
  lookup and obtain a reference to the object
• You may think DI is the opposite of JNDI
   – It is the responsibility of the container to inject an
     object based on the dependency declaration
Building business logic with
       Session Beans
Getting to know Session Beans
• So what is a Session?
   – A session is a connection between a client and a
     server that lasts for a finite period of time
• Session beans centers on the idea that each
  request by a client to complete a distinct business
  process is completed in a session.
• Recall that session beans come in two flavors:
  Stateful and Stateless
• A bean may maintain its state between calls, in
  which case it is stateful, or it may be a one-time
  call, in which case it’s stateless.
@Stateless Session Bean
• No more Home interfaces!
• A POJI Business Interface
  – Annotated with @Remote or @Local
• A POJO Implementation
  – Annotated with @Stateless
• No more deployment descriptors! (optional)
@Stateful Session Bean
• No more Home interfaces!
• A POJI Business Interface
  – Annotated with @Remote or @Local
• A POJO Implementation
  – Annotated with @Stateful
• No more deployment descriptors! (optional)
Working with multiple business
             interfaces
• You cannot mark the same interface with
  more than one access type annotation.
• However, a business interface can extend
  another interface.
• You can create a set of interfaces utilizing OO
  inheritance to avoid code duplication
Callback methods
•   @PostConstruct
•   @PostActivate
•   @PrePassivate
•   @PreDestroy
@MessageDriven Bean
Messaging with message-driven beans
Diving into the Java Persistence API
Java Persistence API
• Separate specification document
• Produced by EJB 3.0 Expert Group (JSR-220)
• Available in & outside the Java EE container
• The API itself, defined in the javax.persistence
  package
• The Java Persistence Query Language (JPQL)
• Object/relational metadata
• Gavin King (founder of Hibernate) represented
  JBoss on JSR220
@Entity Beans
• No more Home interfaces!
• No Business Interfaces!
• A POJO Implementation
  – Annotated with @Entity
• A simple deployment descriptor
• Entities need not use getter- and setter-based
  properties.
EntityManager
• EntityManager is the bridge
  between the OO and
  relational worlds.
• Knows how to store a POJO
  entity into the database,
  read, update & delete.
• Factory for Query
Query




        entityManager.createNativeQuery()
Named queries
• They improve reusability of queries.
• They improve maintainability of code
  – Queries are not scattered among the business logic.
• They can enhance performance because they
  are prepared once and can be efficiently reused.
• Can be defined either in the entity using
  annotations, or in the XML file defining O/R
  mapping metadata.
Transaction Management
Understanding transactions
• A transaction is a grouping of tasks that must be
  processed as an inseparable unit.
• Every task that is part of the transaction must
  succeed in order for the transaction to succeed.
  All-or-nothing
• The Transaction Manager is a component that,
  coordinates a transaction over multiple
  distributed resources
• EJB provides through the Java Transaction API
  (JTA)
Container-managed transactions
• In a CMT, the container starts, commits, and
  rolls back a transaction on our behalf
• Can be done through annotations or the
  deployment descriptor
• EJB context: accessing the runtime
  environment
• The javax.ejb.EJBContext interface is
  essentially your backdoor into the mystic
  world of the container
Bean-managed transactions
• The greatest strength of CMT is also its
  greatest weakness.
• CMT, you are limited to having the transaction
  boundaries set at the beginning and end of
  business methods and relying on the
  container to determine when a transaction
  starts, commits, or rolls back.
• BMT, on the other hand, allows you to specify
  exactly these details programmatically
The pros and cons of BMT
• BMT is verbose, complex, and difficult to
  maintain and some times error prone.
• With BMT, you can fine-tune your transaction
  boundaries so that the data held by your code
  is isolated for the shortest time possible
• BMT can never join an existing transaction.
  – Existing transactions are always suspended
  – Significantly limiting flexible component reuse
References
• [1] D. Panda, R. Rahman, and D. Lane, EJB 3 in Action, 1st
  ed. Manning Publications, 2007.

• [2] “Enterprise JavaBeans - Wikipedia, the free
  encyclopedia.” [Online]. Available:
  http://en.wikipedia.org/wiki/Ejb. [Accessed: 10-Mar-2012].

• [3] “What I’m Learning: Differences between EJB 3.0 and
  EJB 2.1.” [Online]. Available:
  http://mytechnicaldocs.blogspot.com/2011/08/differences
  -between-ejb-30-and-ejb-21.html. [Accessed: 10-Mar-
  2012].
@Questions?

Mais conteúdo relacionado

Mais procurados

Spring boot anane maryem ben aziza syrine
Spring boot anane maryem ben aziza syrineSpring boot anane maryem ben aziza syrine
Spring boot anane maryem ben aziza syrineSyrine Ben aziza
 
Rest api 테스트 수행가이드
Rest api 테스트 수행가이드Rest api 테스트 수행가이드
Rest api 테스트 수행가이드SangIn Choung
 
Microservices - java ee vs spring boot and spring cloud
Microservices - java ee vs spring boot and spring cloudMicroservices - java ee vs spring boot and spring cloud
Microservices - java ee vs spring boot and spring cloudBen Wilcock
 
Postman Collection Format v2.0 (pre-draft)
Postman Collection Format v2.0 (pre-draft)Postman Collection Format v2.0 (pre-draft)
Postman Collection Format v2.0 (pre-draft)Postman
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with SpringJoshua Long
 
java 8 new features
java 8 new features java 8 new features
java 8 new features Rohit Verma
 
Redux Sagas - React Alicante
Redux Sagas - React AlicanteRedux Sagas - React Alicante
Redux Sagas - React AlicanteIgnacio Martín
 
Testing Spring Boot Applications
Testing Spring Boot ApplicationsTesting Spring Boot Applications
Testing Spring Boot ApplicationsVMware Tanzu
 
Spring Framework - Spring Security
Spring Framework - Spring SecuritySpring Framework - Spring Security
Spring Framework - Spring SecurityDzmitry Naskou
 
Les dessous du framework spring
Les dessous du framework springLes dessous du framework spring
Les dessous du framework springAntoine Rey
 
Spring boot
Spring bootSpring boot
Spring bootsdeeg
 

Mais procurados (20)

Presentation Spring
Presentation SpringPresentation Spring
Presentation Spring
 
Spring boot anane maryem ben aziza syrine
Spring boot anane maryem ben aziza syrineSpring boot anane maryem ben aziza syrine
Spring boot anane maryem ben aziza syrine
 
Java Spring Framework
Java Spring FrameworkJava Spring Framework
Java Spring Framework
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Rest api 테스트 수행가이드
Rest api 테스트 수행가이드Rest api 테스트 수행가이드
Rest api 테스트 수행가이드
 
Microservices - java ee vs spring boot and spring cloud
Microservices - java ee vs spring boot and spring cloudMicroservices - java ee vs spring boot and spring cloud
Microservices - java ee vs spring boot and spring cloud
 
Postman Collection Format v2.0 (pre-draft)
Postman Collection Format v2.0 (pre-draft)Postman Collection Format v2.0 (pre-draft)
Postman Collection Format v2.0 (pre-draft)
 
Introduction à JPA (Java Persistence API )
Introduction à JPA  (Java Persistence API )Introduction à JPA  (Java Persistence API )
Introduction à JPA (Java Persistence API )
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with Spring
 
java 8 new features
java 8 new features java 8 new features
java 8 new features
 
Spring Core
Spring CoreSpring Core
Spring Core
 
Redux Sagas - React Alicante
Redux Sagas - React AlicanteRedux Sagas - React Alicante
Redux Sagas - React Alicante
 
Testing Spring Boot Applications
Testing Spring Boot ApplicationsTesting Spring Boot Applications
Testing Spring Boot Applications
 
Javascript Design Patterns
Javascript Design PatternsJavascript Design Patterns
Javascript Design Patterns
 
Spring AOP
Spring AOPSpring AOP
Spring AOP
 
Spring Framework - Spring Security
Spring Framework - Spring SecuritySpring Framework - Spring Security
Spring Framework - Spring Security
 
Les dessous du framework spring
Les dessous du framework springLes dessous du framework spring
Les dessous du framework spring
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Spring Security 5
Spring Security 5Spring Security 5
Spring Security 5
 
Spring boot
Spring bootSpring boot
Spring boot
 

Destaque

Security Risks & Vulnerabilities in Skype
Security Risks & Vulnerabilities in SkypeSecurity Risks & Vulnerabilities in Skype
Security Risks & Vulnerabilities in SkypeKelum Senanayake
 
Enterprise Java Beans - EJB
Enterprise Java Beans - EJBEnterprise Java Beans - EJB
Enterprise Java Beans - EJBPeter R. Egli
 
Couchbase - Yet Another Introduction
Couchbase - Yet Another IntroductionCouchbase - Yet Another Introduction
Couchbase - Yet Another IntroductionKelum Senanayake
 
What you need to know about GC
What you need to know about GCWhat you need to know about GC
What you need to know about GCKelum Senanayake
 
Entity beans in java
Entity beans in javaEntity beans in java
Entity beans in javaAcp Jamod
 
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
 
S314168 - What's New in Enterprise Java Bean Technology @ JavaOne Brazil 2010
S314168 - What's New in Enterprise Java Bean Technology @ JavaOne Brazil 2010S314168 - What's New in Enterprise Java Bean Technology @ JavaOne Brazil 2010
S314168 - What's New in Enterprise Java Bean Technology @ JavaOne Brazil 2010Arun Gupta
 
Session 7 Tp7
Session 7 Tp7Session 7 Tp7
Session 7 Tp7phanleson
 
Remote Method Invocation
Remote Method InvocationRemote Method Invocation
Remote Method Invocationashishspace
 
Architecture of message oriented middleware
Architecture of message oriented middlewareArchitecture of message oriented middleware
Architecture of message oriented middlewareSajan Sahu
 
Enterprise Java Beans 3 - Business Logic
Enterprise Java Beans 3 - Business LogicEnterprise Java Beans 3 - Business Logic
Enterprise Java Beans 3 - Business LogicEmprovise
 
Message Oriented Middleware (MOM)
Message Oriented Middleware (MOM)Message Oriented Middleware (MOM)
Message Oriented Middleware (MOM)drewenut
 

Destaque (20)

Security Risks & Vulnerabilities in Skype
Security Risks & Vulnerabilities in SkypeSecurity Risks & Vulnerabilities in Skype
Security Risks & Vulnerabilities in Skype
 
Node.js Introduction
Node.js IntroductionNode.js Introduction
Node.js Introduction
 
Enterprise Java Beans - EJB
Enterprise Java Beans - EJBEnterprise Java Beans - EJB
Enterprise Java Beans - EJB
 
Couchbase - Yet Another Introduction
Couchbase - Yet Another IntroductionCouchbase - Yet Another Introduction
Couchbase - Yet Another Introduction
 
EJB3 Basics
EJB3 BasicsEJB3 Basics
EJB3 Basics
 
What you need to know about GC
What you need to know about GCWhat you need to know about GC
What you need to know about GC
 
Introduction to EJB
Introduction to EJBIntroduction to EJB
Introduction to EJB
 
Entity beans in java
Entity beans in javaEntity beans in java
Entity beans in java
 
Lecture 8 Enterprise Java Beans (EJB)
Lecture 8  Enterprise Java Beans (EJB)Lecture 8  Enterprise Java Beans (EJB)
Lecture 8 Enterprise Java Beans (EJB)
 
EJB .
EJB .EJB .
EJB .
 
Ejb notes
Ejb notesEjb notes
Ejb notes
 
S314168 - What's New in Enterprise Java Bean Technology @ JavaOne Brazil 2010
S314168 - What's New in Enterprise Java Bean Technology @ JavaOne Brazil 2010S314168 - What's New in Enterprise Java Bean Technology @ JavaOne Brazil 2010
S314168 - What's New in Enterprise Java Bean Technology @ JavaOne Brazil 2010
 
Session 7 Tp7
Session 7 Tp7Session 7 Tp7
Session 7 Tp7
 
How to Share a Secret
How to Share a SecretHow to Share a Secret
How to Share a Secret
 
Remote Method Invocation
Remote Method InvocationRemote Method Invocation
Remote Method Invocation
 
Architecture of message oriented middleware
Architecture of message oriented middlewareArchitecture of message oriented middleware
Architecture of message oriented middleware
 
EJB 2
EJB 2EJB 2
EJB 2
 
Enterprise Java Beans 3 - Business Logic
Enterprise Java Beans 3 - Business LogicEnterprise Java Beans 3 - Business Logic
Enterprise Java Beans 3 - Business Logic
 
Bean Intro
Bean IntroBean Intro
Bean Intro
 
Message Oriented Middleware (MOM)
Message Oriented Middleware (MOM)Message Oriented Middleware (MOM)
Message Oriented Middleware (MOM)
 

Semelhante a EJB 3.0 - Yet Another Introduction

The Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans TechnologyThe Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans TechnologySimon Ritter
 
Connecting ejb with mule
Connecting ejb with muleConnecting ejb with mule
Connecting ejb with muleRuman Khan
 
Contextual Dependency Injection for Apachecon 2010
Contextual Dependency Injection for Apachecon 2010Contextual Dependency Injection for Apachecon 2010
Contextual Dependency Injection for Apachecon 2010Rohit Kelapure
 
Aravind vinnakota ejb_architecture
Aravind vinnakota ejb_architectureAravind vinnakota ejb_architecture
Aravind vinnakota ejb_architecturetayab4687
 
EJB Interview Questions
EJB Interview QuestionsEJB Interview Questions
EJB Interview Questionsguest346cb1
 
Enterprise beans
Enterprise beansEnterprise beans
Enterprise beansvpulec
 
Overview of Java EE 6 by Roberto Chinnici at SFJUG
Overview of Java EE 6 by Roberto Chinnici at SFJUGOverview of Java EE 6 by Roberto Chinnici at SFJUG
Overview of Java EE 6 by Roberto Chinnici at SFJUGMarakana Inc.
 
Ejb course in-mumbai
Ejb course in-mumbaiEjb course in-mumbai
Ejb course in-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
 

Semelhante a EJB 3.0 - Yet Another Introduction (20)

Unite5-EJB-2019.ppt
Unite5-EJB-2019.pptUnite5-EJB-2019.ppt
Unite5-EJB-2019.ppt
 
Ch4 ejb
Ch4 ejbCh4 ejb
Ch4 ejb
 
The Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans TechnologyThe Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans Technology
 
Connecting ejb with mule
Connecting ejb with muleConnecting ejb with mule
Connecting ejb with mule
 
Contextual Dependency Injection for Apachecon 2010
Contextual Dependency Injection for Apachecon 2010Contextual Dependency Injection for Apachecon 2010
Contextual Dependency Injection for Apachecon 2010
 
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
 
Introcution to EJB
Introcution to EJBIntrocution to EJB
Introcution to EJB
 
UNIT 4.pptx
UNIT 4.pptxUNIT 4.pptx
UNIT 4.pptx
 
EJB Interview Questions
EJB Interview QuestionsEJB Interview Questions
EJB Interview Questions
 
Enterprise beans
Enterprise beansEnterprise beans
Enterprise beans
 
enterprise java bean
enterprise java beanenterprise java bean
enterprise java bean
 
Java j2eeTutorial
Java j2eeTutorialJava j2eeTutorial
Java j2eeTutorial
 
Advance java1.1
Advance java1.1Advance java1.1
Advance java1.1
 
Virtual classroom
Virtual classroomVirtual classroom
Virtual classroom
 
Hybernat and structs, spring classes in mumbai
Hybernat and structs, spring classes in mumbaiHybernat and structs, spring classes in mumbai
Hybernat and structs, spring classes in mumbai
 
Overview of Java EE 6 by Roberto Chinnici at SFJUG
Overview of Java EE 6 by Roberto Chinnici at SFJUGOverview of Java EE 6 by Roberto Chinnici at SFJUG
Overview of Java EE 6 by Roberto Chinnici at SFJUG
 
Ejb course in-mumbai
Ejb course in-mumbaiEjb course in-mumbai
Ejb course in-mumbai
 
Real world java_ee_patterns
Real world java_ee_patternsReal world java_ee_patterns
Real world java_ee_patterns
 
Java online training from hyderabad
Java online training from hyderabadJava online training from hyderabad
Java online training from hyderabad
 

Último

New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
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
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
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
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
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
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 

Último (20)

New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
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
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
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
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
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
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 

EJB 3.0 - Yet Another Introduction

  • 1. Enterprise Java Bean 3.0 Yet Another Introduction… Kelum Senanayake
  • 2. Tag-Cloud ResourceInjection StatelessSessionBean EnterpriseJavaBeans EntityBean StatefulSessionBean MessageDrivenBean JavaEE POJO JavaPersistenceAPI Annotations Transactions
  • 4. Enterprise Java Beans (EJB) • A platform for building portable, reusable, and scalable business applications. • Allows to focus on building business logic without having to spend time on building infrastructure code for services such as transactions, security, automated persistence. • An EJB is a piece of Java code that executes in a specialized runtime environment.
  • 5. EJB as a component … • A component should effectively encapsulate application behavior. • All we need to know is what to pass in and what to expect back. • Components can be reusable. • Three types of EJB components: – Session beans – Message-driven beans – Entities
  • 6. EJB as a framework … • EJB components live in a container. • Together, the components, or EJBs, and the container can be viewed as a framework. • EJB framework provides valuable services for enterprise application development
  • 7. EJB History • EJB 1.0 (1998-03-24) – Defined the responsibilities of EJB Container provider – Defined the distinct “EJB Roles” • EJB 1.1 (1999-12-17) – XML deployment descriptors – Session Beans, Entity Beans – Remote interface • EJB 2.0 (2001-08-22) – Message-Driven Beans – Entity 2.x and EJB QL
  • 8. EJB History …contd • EJB 2.1 (2003-11-24) – EJB Timer Service – Web service support • EJB 3.0 (2006-05-11) – POJO, Annotations – Dependency injection • EJB 3.1 (2009-12-10) – Local view without interface – .war packaging of EJB components – Singletons (Singleton Session Beans) – EJB Lite: definition of a subset of EJB – @Asynchronous for session beans
  • 9. EJB 3.0 vs EJB 2.1 • EJB 3.0 is much faster than EJB 2 • An EJB 2.1 session bean must implement the SessionBean interface • EJB 3.0 session bean class includes only business methods. • EJB 3.0 interfaces are POJI business interfaces and do not require home and component interfaces. • EJB 2.1 must have the deployment descriptor. But optional in EJB 3.0. Annotations are added to the language.
  • 10. EJB 3.0 vs EJB 2.1 …contd • EJB 3 introduced persistence API for database access. In EJB 2 you can use Entity bean. • An EJB 2.1 Entity EJB bean class must implement the EntityBean interface and must provide implementation to the ejbCreate() and ejbPostCreate() methods. • EJB 2.1 entity bean includes the home, component, local home and local component interfaces that extend the EJBHome, EJBObject, EJBLocalHome and EJBObject interfaces respectively.
  • 11. EJB 3.0 vs EJB 2.1 …contd • An EJB 2.1 bean must define resource-ref in ejb- jar.xml to lookup resources. An EJB 3.0 bean can use either dependency injection or JNDI lookup. • An EJB 2.1 message-driven must implement the javax.ejb.MessgeDrivenBean interface. • Standardized Simplified persistence with POJO – You couldn’t send an EJB 2 entity bean across the wire in different tiers. – They are permanently attached to the database. – You have to write data transfer objects
  • 12. Why choose EJB 3.0? • Ease of use – POJO programming, annotations in favor of verbose XML, heavy use of sensible defaults & JPA • Integrated solution stack – EJB 3 offers a complete stack of server solutions – Persistence, messaging, lightweight scheduling, remoting, web services, dependency injection (DI) and interceptors – You won’t have to spend a lot of time looking for third-party tools
  • 13. Why EJB 3.0 …contd • Open Java EE standard – EJB is a critical part of the Java EE standard – EJB 3 has an open, public API specification – The open standard leads to broader vendor support – You don’t have to depend on a proprietary solution
  • 14. Why EJB 3.0 …contd • Broad vendor support – You are not at the mercy of the ups and downs of a particular company or group of people – Vendors have historically competed against one another by providing value-added nonstandard features • Stable, high-quality code base – Clustering, load balancing, and failover support with no changes to code, no third-party tool integration, and relatively simple configuration
  • 15. Why EJB 3.0 …contd • Unit-testable POJO components – All EJB 3 components are POJOs, they can easily be executed outside the container – It is possible to unit-test all component business logic using testing frameworks • Annotations and descriptors are not mutually exclusive – Deployment descriptor entries override configuration values hard-coded into EJB components
  • 17. The Container • When you build a simple Java class, you need a Java Virtual Machine (JVM) to execute it. • Think of the container as simply an extension of the basic idea of a JVM. • JVM transparently manages memory on your behalf. • The container transparently provides EJB component services – Transactions, security management – Remoting and web services support
  • 18. Container …contd • A Java EE container is an application server solution that supports EJB 3, a web container, and other Java EE APIs and services. • JPA is completely pluggable and separable. – Persistence provider and container in an EJB 3 solution need not come from the same vendor – You could use Hibernate inside a BEA WebLogic container
  • 19.
  • 23. Dependency injection vs. JNDI lookup • With EJB 2, you have to write the same few lines of boilerplate code many times to do a JNDI lookup. • In EJB 3, JNDI lookups have been turned into simple configuration using metadata-based dependency injection (DI) • JNDI : It’s the responsibility of the client to do a lookup and obtain a reference to the object • You may think DI is the opposite of JNDI – It is the responsibility of the container to inject an object based on the dependency declaration
  • 24.
  • 25. Building business logic with Session Beans
  • 26. Getting to know Session Beans • So what is a Session? – A session is a connection between a client and a server that lasts for a finite period of time • Session beans centers on the idea that each request by a client to complete a distinct business process is completed in a session. • Recall that session beans come in two flavors: Stateful and Stateless • A bean may maintain its state between calls, in which case it is stateful, or it may be a one-time call, in which case it’s stateless.
  • 27. @Stateless Session Bean • No more Home interfaces! • A POJI Business Interface – Annotated with @Remote or @Local • A POJO Implementation – Annotated with @Stateless • No more deployment descriptors! (optional)
  • 28.
  • 29. @Stateful Session Bean • No more Home interfaces! • A POJI Business Interface – Annotated with @Remote or @Local • A POJO Implementation – Annotated with @Stateful • No more deployment descriptors! (optional)
  • 30.
  • 31.
  • 32. Working with multiple business interfaces • You cannot mark the same interface with more than one access type annotation. • However, a business interface can extend another interface. • You can create a set of interfaces utilizing OO inheritance to avoid code duplication
  • 33.
  • 34.
  • 35. Callback methods • @PostConstruct • @PostActivate • @PrePassivate • @PreDestroy
  • 38.
  • 39.
  • 40. Diving into the Java Persistence API
  • 41. Java Persistence API • Separate specification document • Produced by EJB 3.0 Expert Group (JSR-220) • Available in & outside the Java EE container • The API itself, defined in the javax.persistence package • The Java Persistence Query Language (JPQL) • Object/relational metadata • Gavin King (founder of Hibernate) represented JBoss on JSR220
  • 42. @Entity Beans • No more Home interfaces! • No Business Interfaces! • A POJO Implementation – Annotated with @Entity • A simple deployment descriptor • Entities need not use getter- and setter-based properties.
  • 43.
  • 44.
  • 45.
  • 46. EntityManager • EntityManager is the bridge between the OO and relational worlds. • Knows how to store a POJO entity into the database, read, update & delete. • Factory for Query
  • 47.
  • 48. Query entityManager.createNativeQuery()
  • 49. Named queries • They improve reusability of queries. • They improve maintainability of code – Queries are not scattered among the business logic. • They can enhance performance because they are prepared once and can be efficiently reused. • Can be defined either in the entity using annotations, or in the XML file defining O/R mapping metadata.
  • 50.
  • 52. Understanding transactions • A transaction is a grouping of tasks that must be processed as an inseparable unit. • Every task that is part of the transaction must succeed in order for the transaction to succeed. All-or-nothing • The Transaction Manager is a component that, coordinates a transaction over multiple distributed resources • EJB provides through the Java Transaction API (JTA)
  • 53. Container-managed transactions • In a CMT, the container starts, commits, and rolls back a transaction on our behalf • Can be done through annotations or the deployment descriptor • EJB context: accessing the runtime environment • The javax.ejb.EJBContext interface is essentially your backdoor into the mystic world of the container
  • 54.
  • 55.
  • 56. Bean-managed transactions • The greatest strength of CMT is also its greatest weakness. • CMT, you are limited to having the transaction boundaries set at the beginning and end of business methods and relying on the container to determine when a transaction starts, commits, or rolls back. • BMT, on the other hand, allows you to specify exactly these details programmatically
  • 57.
  • 58. The pros and cons of BMT • BMT is verbose, complex, and difficult to maintain and some times error prone. • With BMT, you can fine-tune your transaction boundaries so that the data held by your code is isolated for the shortest time possible • BMT can never join an existing transaction. – Existing transactions are always suspended – Significantly limiting flexible component reuse
  • 59. References • [1] D. Panda, R. Rahman, and D. Lane, EJB 3 in Action, 1st ed. Manning Publications, 2007. • [2] “Enterprise JavaBeans - Wikipedia, the free encyclopedia.” [Online]. Available: http://en.wikipedia.org/wiki/Ejb. [Accessed: 10-Mar-2012]. • [3] “What I’m Learning: Differences between EJB 3.0 and EJB 2.1.” [Online]. Available: http://mytechnicaldocs.blogspot.com/2011/08/differences -between-ejb-30-and-ejb-21.html. [Accessed: 10-Mar- 2012].