SlideShare une entreprise Scribd logo
1  sur  5
Télécharger pour lire hors ligne
1
Enterprise Java Beans
by Achraf SFAXI
SUN Certified Professional
Bnak/Finance & Telecom Jobs
September 2006
 Enterprise beans are software components that run in a special environment called an
EJB container. The container hosts and manages an enterprise bean in the same
manner that the Java Web Server hosts a servlet or an HTML browser hosts a Java
applet. An enterprise bean cannot function outside of an EJB container. The EJB
container manages every aspect of an enterprise bean at runtimes including remote
access to the bean, security, persistence, transactions, concurrency, and access to and
pooling of resources.
 The enterprise bean developer can focus on encapsulating business rules, while the
container takes care of everything else.

2
 The enterprise bean interacts with its container through one of three mechanisms:
callback methods, the EJBContext interface, or the Java Naming and Directory
Interface (JNDI)
 Callback Methods : Every bean implements a subtype of the EnterpriseBean interface
which defines several methods, called callback methods. Each callback method alerts
the bean TO a different event in its lifecycle and the container will invoke these
3
methods to notify the bean when it's about to activate the bean, persist its state to the
database, end a transaction, remove the bean from memory, etc.
 EJBContext : Every bean obtains an EJBContext object, which is a reference directly
to the container. The EJBContext interface provides methods for interacting with the
container so that that bean can request information about its environment like the
identity of its client, the status of a transaction, or to obtain remote references to itself.
 Java Naming and Directory Interface : Java Naming and Directory Interface (JNDI)
is a standard extension to the Java platform for accessing naming systems like LDAP,
NetWare, file systems, etc. Every bean automatically has access to a special naming
system called the Environment Naming Context (ENC). The ENC is managed by the
container and accessed by beans using JNDI. The JNDI ENC allows a bean to access
resources like JDBC connections, other enterprise beans, and properties specific to
that bean.
 In addition to portability, the simplicity of the EJB programming model makes EJB
valuable. Because the container takes care of managing complex tasks like security,
transactions, persistence, concurrency and resource management, the bean developer
is free to focus attention on business rules and a very simple programming model. A
simple programming model means that beans can be developed faster without
requiring a Ph.D. in distributed objects, transactions and other enterprise systems.
 The Home interface Entity Bean create() method is used to create a new entity. This
will result in a new record in the database.
 A home interface may have many create() methods. The number and datatype of the
arguments of each create() are left up to the bean developer, but the return type must
be the remote interface datatype (an instance of javax.EJBObject Class). Imagine that
you have an Entity Bean that materialise a custromer, invoking create() on the
CustomerHome interface will return an instance of Customer (that is the remote
interface returning type).
 Again, we consider the Customer Entity Bean. The findByPrimaryKey() and
findByZipCode() methods are used to locate specific instance of the Customer bean.
You may define as many find methods as you need.
 The remote and home interfaces are types of Java RMI Remote interfaces. The
java.rmi.Remote interface is used by distributed objects to represent the bean in a
different address space (process or machine). An enterprise bean is a distributed
object. That means that the bean class is instantiated and lives in the container but it
can be accessed by applications that live in other address spaces.
 To make an object instance in one address space available in another requires a little
trick involving network sockets. To make the trick work, wrap the instance in a
special object called a skeleton that has a network connection to another special object
called a stub. The stub implements the remote interface so it looks like a business
object. But the stub doesn't contain business logic; it holds a network socket
connection to the skeleton. Every time a business method is invoked on the stub's
remote interface, the stub sends a network message to the skeleton telling it which
method was invoked. When the skeleton receives a network message from the stub, it
identifies the method invoked and the arguments, and then invokes the
corresponding method on the actual instance. The instance executes the business
method and returns the result to the skeleton, which sends it to the stub.
4
 In EJB, the skeleton for the remote and home interfaces are implemented by the
container, not the bean class. This is to ensure that every method invoked on these
reference types by a client application are first handled by the container and then
delegated to the bean instance.
 Distributed object protocols define the format of network messages sent between
address spaces. Distributed object protocols get pretty complicated, but luckily you
don't see any of it because it's handled automatically. Most EJB servers support either
the Java Remote Method Protocol (JRMP) or CORBA's Internet Inter-ORB Protocol
(IIOP). The bean and application programmer only see the bean class and its remote
interface, the details of the network communication are hidden.
 There are two types of entity bean: Container-Managed Persistence (CMP), and Bean-
Managed Persistence (BMP). With CMP, the container manages the persistence of the
entity bean. Vendor tools are used to map the entity fields to the database and
absolutely no database access code is written in the bean class. With BMP, the entity
bean contains database access code (usually JDBC) and is responsible for reading and
writing its own state to the database. BMP entities have a lot of help with this since
the container will alert the bean as to when it's necessary to make an update or read
its state from the database. The container can also handle any locking or transactions,
so that the database maintains integrity.
 Session beans correspond to the controller in a model-view-controller architecture
because they encapsulate the business logic of a three-tier architecture.
 Stateless session beans are made up of business methods that behave like procedures;
they operate only on the arguments passed to them when they are invoked. Stateless
beans are called "stateless" because they are transient; they do not maintain business
state between method invocations.
 Stateful session beans encapsulate business logic and state specific to a client. Stateful
beans are called "stateful" because they do maintain business state between method
invocations, held in memory and not persistent.
 In the EJB 1.1 specification, RMI over IIOP is the specified programming model, so
CORBA references types must be supported. CORBA references cannot be cast using
Java native casting. Instead the PortableRemoteObject.narrow() method must be used to
explicitly narrow a reference from one type to its subtype. Since JNDI always returns
an Object type, all bean references should be explicitly narrowed to support
portability between containers.
 As mentioned previously, the container handles persistence, transactions,
concurrency, and access control automatically for the enterprise beans. The EJB
specification describes a declarative mechanism for how these things will be handled,
5
through the use of an XML deployment descriptor. When a bean is deployed into a
container, the container reads the deployment descriptor to find out how transaction,
persistence (entity beans), and access control should be handled. The person
deploying the bean will use this information and specify additional information to
hook the bean up to these facilities at runtime.
 Below is an example of how a Customer bean might be accessed from a client
application. In this case the home interface is CustomerHome and the remote interface
is Customer.
CustomerHome home;
Object ref;
// Obtain a reference to the CustomerHome
ref =
jndiContext.lookup("java:comp/env/ejb/Customer");
// Cast object returned by the JNDI lookup to the
// appropriate datatype
home = PortableRemoteObject.narrow(ref,
CustomerHome.class);
// Use the home interface to create a
// new instance of the Customer bean.
Customer customer = home.create(customerID);
// Use a business method on the Customer.
customer.setName(someName);
 EJB components help in rapid and simplified development of distributed,
transactional, secure, and portable applications based on Java technology. However,
EJB is not a silver bullet for all your problems. You should only use EJB technology if
an application requires security and/or transaction support
If you appreciate this document make a donation to a
worldwide children association or organization. I suggest the SOS
association. This document has been downloaded from the
http://achraf.sfaxi.perso.sfr.fr space ; you can use and broadcast it for
non lucrative purposes. Further information are available upon
request.
Si vous appréciez ce document faites un don pour le compte
d’une association ou une organisation qui s’occupe des enfants. Je
recommande l’association SOS. Ce document est disponible sur
http://achraf.http://achraf.sfaxi.perso.sfr.frsfaxi.perso.sfr.fr; son utilisation
ainsi que sa propagation pour des fins non lucratives sont gratuites.

Contenu connexe

Tendances

Tendances (20)

Enterprise java beans
Enterprise java beansEnterprise java beans
Enterprise java beans
 
Entity beans in java
Entity beans in javaEntity beans in java
Entity beans in java
 
EJB .
EJB .EJB .
EJB .
 
Session 3 Tp3
Session 3 Tp3Session 3 Tp3
Session 3 Tp3
 
Session 4 Tp4
Session 4 Tp4Session 4 Tp4
Session 4 Tp4
 
EJB3 Basics
EJB3 BasicsEJB3 Basics
EJB3 Basics
 
Enterprise Java Beans - EJB
Enterprise Java Beans - EJBEnterprise Java Beans - EJB
Enterprise Java Beans - EJB
 
EJB Interview Questions
EJB Interview QuestionsEJB Interview Questions
EJB Interview Questions
 
Aravind vinnakota ejb_architecture
Aravind vinnakota ejb_architectureAravind vinnakota ejb_architecture
Aravind vinnakota ejb_architecture
 
Java EE EJB Applications
Java EE EJB ApplicationsJava EE EJB Applications
Java EE EJB Applications
 
EJB 3.0 - Yet Another Introduction
EJB 3.0 - Yet Another IntroductionEJB 3.0 - Yet Another Introduction
EJB 3.0 - Yet Another Introduction
 
Ejb notes
Ejb notesEjb notes
Ejb notes
 
EJB 3.0 and J2EE
EJB 3.0 and J2EEEJB 3.0 and J2EE
EJB 3.0 and J2EE
 
Ejb 2.0
Ejb 2.0Ejb 2.0
Ejb 2.0
 
enterprise java bean
enterprise java beanenterprise java bean
enterprise java bean
 
Skillwise EJB3.0 training
Skillwise EJB3.0 trainingSkillwise EJB3.0 training
Skillwise EJB3.0 training
 
TY.BSc.IT Java QB U5
TY.BSc.IT Java QB U5TY.BSc.IT Java QB U5
TY.BSc.IT Java QB U5
 
Ejb3.1 for the starter
Ejb3.1 for the starterEjb3.1 for the starter
Ejb3.1 for the starter
 
Ch4 ejb
Ch4 ejbCh4 ejb
Ch4 ejb
 
Hibernate Interview Questions
Hibernate Interview QuestionsHibernate Interview Questions
Hibernate Interview Questions
 

Similaire à EJB Enterprise Java Beans Guide

ADVANCED JAVA MODULE I & II.ppt
ADVANCED JAVA MODULE I & II.pptADVANCED JAVA MODULE I & II.ppt
ADVANCED JAVA MODULE I & II.pptrani marri
 
Session 5 Tp5
Session 5 Tp5Session 5 Tp5
Session 5 Tp5phanleson
 
Session 8 Tp8
Session 8 Tp8Session 8 Tp8
Session 8 Tp8phanleson
 
02 java spring-hibernate-experience-questions
02 java spring-hibernate-experience-questions02 java spring-hibernate-experience-questions
02 java spring-hibernate-experience-questionsDhiraj Champawat
 
Enterprise Java Beans( E)
Enterprise  Java  Beans( E)Enterprise  Java  Beans( E)
Enterprise Java Beans( E)vikram singh
 
Enterprise java beans(ejb)
Enterprise java beans(ejb)Enterprise java beans(ejb)
Enterprise java beans(ejb)vikram singh
 
Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2vikram singh
 
Enterprise java beans(ejb) Update 2
Enterprise java beans(ejb) Update 2Enterprise java beans(ejb) Update 2
Enterprise java beans(ejb) Update 2vikram singh
 
Enterprise java beans(ejb)
Enterprise java beans(ejb)Enterprise java beans(ejb)
Enterprise java beans(ejb)vikram singh
 
Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2vikram singh
 

Similaire à EJB Enterprise Java Beans Guide (20)

ADVANCED JAVA MODULE I & II.ppt
ADVANCED JAVA MODULE I & II.pptADVANCED JAVA MODULE I & II.ppt
ADVANCED JAVA MODULE I & II.ppt
 
Spring 2
Spring 2Spring 2
Spring 2
 
P20CSP105-AdvJavaProg.pptx
P20CSP105-AdvJavaProg.pptxP20CSP105-AdvJavaProg.pptx
P20CSP105-AdvJavaProg.pptx
 
Virtual Classroom
Virtual ClassroomVirtual Classroom
Virtual Classroom
 
EJB.docx
EJB.docxEJB.docx
EJB.docx
 
Session 5 Tp5
Session 5 Tp5Session 5 Tp5
Session 5 Tp5
 
Ejb intro
Ejb introEjb intro
Ejb intro
 
Session 8 Tp8
Session 8 Tp8Session 8 Tp8
Session 8 Tp8
 
02 java spring-hibernate-experience-questions
02 java spring-hibernate-experience-questions02 java spring-hibernate-experience-questions
02 java spring-hibernate-experience-questions
 
Enterprise Java Beans( E)
Enterprise  Java  Beans( E)Enterprise  Java  Beans( E)
Enterprise Java Beans( E)
 
Enterprise java beans(ejb)
Enterprise java beans(ejb)Enterprise java beans(ejb)
Enterprise java beans(ejb)
 
Introcution to EJB
Introcution to EJBIntrocution to EJB
Introcution to EJB
 
Ejb intro
Ejb introEjb intro
Ejb intro
 
Virtual classroom
Virtual classroomVirtual classroom
Virtual classroom
 
Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2
 
Enterprise java beans(ejb) Update 2
Enterprise java beans(ejb) Update 2Enterprise java beans(ejb) Update 2
Enterprise java beans(ejb) Update 2
 
Hibernate 3
Hibernate 3Hibernate 3
Hibernate 3
 
EJBDetailsFeb25.ppt
EJBDetailsFeb25.pptEJBDetailsFeb25.ppt
EJBDetailsFeb25.ppt
 
Enterprise java beans(ejb)
Enterprise java beans(ejb)Enterprise java beans(ejb)
Enterprise java beans(ejb)
 
Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2
 

Plus de achraf_ing

Clustering - october 2006
Clustering  - october 2006Clustering  - october 2006
Clustering - october 2006achraf_ing
 
Distributed computing - november 2006
Distributed computing  - november 2006Distributed computing  - november 2006
Distributed computing - november 2006achraf_ing
 
Initiation à Linux - Fundamentals
Initiation à Linux  - FundamentalsInitiation à Linux  - Fundamentals
Initiation à Linux - Fundamentalsachraf_ing
 
Apache server configuration & sécurisation -
Apache server configuration & sécurisation  -Apache server configuration & sécurisation  -
Apache server configuration & sécurisation -achraf_ing
 
Ssl et certification electronique - (construction de certification)
Ssl et certification electronique  - (construction de certification)Ssl et certification electronique  - (construction de certification)
Ssl et certification electronique - (construction de certification)achraf_ing
 
Crise financiere
Crise financiereCrise financiere
Crise financiereachraf_ing
 
The 23 gof design patterns in java ,the summary
The 23 gof design patterns in java ,the summaryThe 23 gof design patterns in java ,the summary
The 23 gof design patterns in java ,the summaryachraf_ing
 
Internationalization in Java
Internationalization in JavaInternationalization in Java
Internationalization in Javaachraf_ing
 

Plus de achraf_ing (10)

Clustering - october 2006
Clustering  - october 2006Clustering  - october 2006
Clustering - october 2006
 
Distributed computing - november 2006
Distributed computing  - november 2006Distributed computing  - november 2006
Distributed computing - november 2006
 
Initiation à Linux - Fundamentals
Initiation à Linux  - FundamentalsInitiation à Linux  - Fundamentals
Initiation à Linux - Fundamentals
 
Apache server configuration & sécurisation -
Apache server configuration & sécurisation  -Apache server configuration & sécurisation  -
Apache server configuration & sécurisation -
 
Ssl et certification electronique - (construction de certification)
Ssl et certification electronique  - (construction de certification)Ssl et certification electronique  - (construction de certification)
Ssl et certification electronique - (construction de certification)
 
Crise financiere
Crise financiereCrise financiere
Crise financiere
 
Stratégie
StratégieStratégie
Stratégie
 
The 23 gof design patterns in java ,the summary
The 23 gof design patterns in java ,the summaryThe 23 gof design patterns in java ,the summary
The 23 gof design patterns in java ,the summary
 
Internationalization in Java
Internationalization in JavaInternationalization in Java
Internationalization in Java
 
My Rmi F
My Rmi FMy Rmi F
My Rmi F
 

Dernier

Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
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
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
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
 
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
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 

Dernier (20)

Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
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
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
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
 
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
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 

EJB Enterprise Java Beans Guide

  • 1. 1 Enterprise Java Beans by Achraf SFAXI SUN Certified Professional Bnak/Finance & Telecom Jobs September 2006  Enterprise beans are software components that run in a special environment called an EJB container. The container hosts and manages an enterprise bean in the same manner that the Java Web Server hosts a servlet or an HTML browser hosts a Java applet. An enterprise bean cannot function outside of an EJB container. The EJB container manages every aspect of an enterprise bean at runtimes including remote access to the bean, security, persistence, transactions, concurrency, and access to and pooling of resources.  The enterprise bean developer can focus on encapsulating business rules, while the container takes care of everything else. 
  • 2. 2  The enterprise bean interacts with its container through one of three mechanisms: callback methods, the EJBContext interface, or the Java Naming and Directory Interface (JNDI)  Callback Methods : Every bean implements a subtype of the EnterpriseBean interface which defines several methods, called callback methods. Each callback method alerts the bean TO a different event in its lifecycle and the container will invoke these
  • 3. 3 methods to notify the bean when it's about to activate the bean, persist its state to the database, end a transaction, remove the bean from memory, etc.  EJBContext : Every bean obtains an EJBContext object, which is a reference directly to the container. The EJBContext interface provides methods for interacting with the container so that that bean can request information about its environment like the identity of its client, the status of a transaction, or to obtain remote references to itself.  Java Naming and Directory Interface : Java Naming and Directory Interface (JNDI) is a standard extension to the Java platform for accessing naming systems like LDAP, NetWare, file systems, etc. Every bean automatically has access to a special naming system called the Environment Naming Context (ENC). The ENC is managed by the container and accessed by beans using JNDI. The JNDI ENC allows a bean to access resources like JDBC connections, other enterprise beans, and properties specific to that bean.  In addition to portability, the simplicity of the EJB programming model makes EJB valuable. Because the container takes care of managing complex tasks like security, transactions, persistence, concurrency and resource management, the bean developer is free to focus attention on business rules and a very simple programming model. A simple programming model means that beans can be developed faster without requiring a Ph.D. in distributed objects, transactions and other enterprise systems.  The Home interface Entity Bean create() method is used to create a new entity. This will result in a new record in the database.  A home interface may have many create() methods. The number and datatype of the arguments of each create() are left up to the bean developer, but the return type must be the remote interface datatype (an instance of javax.EJBObject Class). Imagine that you have an Entity Bean that materialise a custromer, invoking create() on the CustomerHome interface will return an instance of Customer (that is the remote interface returning type).  Again, we consider the Customer Entity Bean. The findByPrimaryKey() and findByZipCode() methods are used to locate specific instance of the Customer bean. You may define as many find methods as you need.  The remote and home interfaces are types of Java RMI Remote interfaces. The java.rmi.Remote interface is used by distributed objects to represent the bean in a different address space (process or machine). An enterprise bean is a distributed object. That means that the bean class is instantiated and lives in the container but it can be accessed by applications that live in other address spaces.  To make an object instance in one address space available in another requires a little trick involving network sockets. To make the trick work, wrap the instance in a special object called a skeleton that has a network connection to another special object called a stub. The stub implements the remote interface so it looks like a business object. But the stub doesn't contain business logic; it holds a network socket connection to the skeleton. Every time a business method is invoked on the stub's remote interface, the stub sends a network message to the skeleton telling it which method was invoked. When the skeleton receives a network message from the stub, it identifies the method invoked and the arguments, and then invokes the corresponding method on the actual instance. The instance executes the business method and returns the result to the skeleton, which sends it to the stub.
  • 4. 4  In EJB, the skeleton for the remote and home interfaces are implemented by the container, not the bean class. This is to ensure that every method invoked on these reference types by a client application are first handled by the container and then delegated to the bean instance.  Distributed object protocols define the format of network messages sent between address spaces. Distributed object protocols get pretty complicated, but luckily you don't see any of it because it's handled automatically. Most EJB servers support either the Java Remote Method Protocol (JRMP) or CORBA's Internet Inter-ORB Protocol (IIOP). The bean and application programmer only see the bean class and its remote interface, the details of the network communication are hidden.  There are two types of entity bean: Container-Managed Persistence (CMP), and Bean- Managed Persistence (BMP). With CMP, the container manages the persistence of the entity bean. Vendor tools are used to map the entity fields to the database and absolutely no database access code is written in the bean class. With BMP, the entity bean contains database access code (usually JDBC) and is responsible for reading and writing its own state to the database. BMP entities have a lot of help with this since the container will alert the bean as to when it's necessary to make an update or read its state from the database. The container can also handle any locking or transactions, so that the database maintains integrity.  Session beans correspond to the controller in a model-view-controller architecture because they encapsulate the business logic of a three-tier architecture.  Stateless session beans are made up of business methods that behave like procedures; they operate only on the arguments passed to them when they are invoked. Stateless beans are called "stateless" because they are transient; they do not maintain business state between method invocations.  Stateful session beans encapsulate business logic and state specific to a client. Stateful beans are called "stateful" because they do maintain business state between method invocations, held in memory and not persistent.  In the EJB 1.1 specification, RMI over IIOP is the specified programming model, so CORBA references types must be supported. CORBA references cannot be cast using Java native casting. Instead the PortableRemoteObject.narrow() method must be used to explicitly narrow a reference from one type to its subtype. Since JNDI always returns an Object type, all bean references should be explicitly narrowed to support portability between containers.  As mentioned previously, the container handles persistence, transactions, concurrency, and access control automatically for the enterprise beans. The EJB specification describes a declarative mechanism for how these things will be handled,
  • 5. 5 through the use of an XML deployment descriptor. When a bean is deployed into a container, the container reads the deployment descriptor to find out how transaction, persistence (entity beans), and access control should be handled. The person deploying the bean will use this information and specify additional information to hook the bean up to these facilities at runtime.  Below is an example of how a Customer bean might be accessed from a client application. In this case the home interface is CustomerHome and the remote interface is Customer. CustomerHome home; Object ref; // Obtain a reference to the CustomerHome ref = jndiContext.lookup("java:comp/env/ejb/Customer"); // Cast object returned by the JNDI lookup to the // appropriate datatype home = PortableRemoteObject.narrow(ref, CustomerHome.class); // Use the home interface to create a // new instance of the Customer bean. Customer customer = home.create(customerID); // Use a business method on the Customer. customer.setName(someName);  EJB components help in rapid and simplified development of distributed, transactional, secure, and portable applications based on Java technology. However, EJB is not a silver bullet for all your problems. You should only use EJB technology if an application requires security and/or transaction support If you appreciate this document make a donation to a worldwide children association or organization. I suggest the SOS association. This document has been downloaded from the http://achraf.sfaxi.perso.sfr.fr space ; you can use and broadcast it for non lucrative purposes. Further information are available upon request. Si vous appréciez ce document faites un don pour le compte d’une association ou une organisation qui s’occupe des enfants. Je recommande l’association SOS. Ce document est disponible sur http://achraf.http://achraf.sfaxi.perso.sfr.frsfaxi.perso.sfr.fr; son utilisation ainsi que sa propagation pour des fins non lucratives sont gratuites.