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 (20)

Jpa
JpaJpa
Jpa
 
Les dessous du framework spring
Les dessous du framework springLes dessous du framework spring
Les dessous du framework spring
 
Hibernate jpa
Hibernate jpaHibernate jpa
Hibernate jpa
 
Workshop spring session 2 - La persistance au sein des applications Java
Workshop spring   session 2 - La persistance au sein des applications JavaWorkshop spring   session 2 - La persistance au sein des applications Java
Workshop spring session 2 - La persistance au sein des applications Java
 
Spring User Guide
Spring User GuideSpring User Guide
Spring User Guide
 
Spring Batch Introduction
Spring Batch IntroductionSpring Batch Introduction
Spring Batch Introduction
 
Jdbc ppt
Jdbc pptJdbc ppt
Jdbc ppt
 
Spring data presentation
Spring data presentationSpring data presentation
Spring data presentation
 
Spring Data JPA
Spring Data JPASpring Data JPA
Spring Data JPA
 
Spring introduction
Spring introductionSpring introduction
Spring introduction
 
Maven et industrialisation du logiciel
Maven et industrialisation du logicielMaven et industrialisation du logiciel
Maven et industrialisation du logiciel
 
JDBC
JDBCJDBC
JDBC
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Java Enterprise Edition
Java Enterprise EditionJava Enterprise Edition
Java Enterprise Edition
 
Java spring ppt
Java spring pptJava spring ppt
Java spring ppt
 
WEB SERVICE SOAP, JAVA, XML, JAXWS
WEB SERVICE SOAP, JAVA, XML, JAXWSWEB SERVICE SOAP, JAVA, XML, JAXWS
WEB SERVICE SOAP, JAVA, XML, JAXWS
 
Spring ppt
Spring pptSpring ppt
Spring ppt
 
Less01 architecture
Less01 architectureLess01 architecture
Less01 architecture
 
Presentation Spring
Presentation SpringPresentation Spring
Presentation Spring
 
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

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 

Último (20)

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 

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].