Você está na página 1de 6

1. Why EJB ?

• The benefit to application developers is that they can focus on writing


the business logic without worrying much about implementing the
surrounding framework.
• The main difference between JavaBeans and EJB is that when you use
JavaBeans to create a server application, you have to build the entire
server framework. With EJB the framework is provided for you; you
simply have to conform to its APIs.
• It follows the Java’s “Write once and run anywhere” concept. It is
platform independent.
• It makes distributed programming (RMI/CORBA) easier.
• All the transaction processing is taken care by the EJB server.
• It follows the multithreaded architecture.

2. What is the EJB architecture like ?


• It is logically a three-tier architecture consisting of mainly The Client
The EJB server and The Databases.
• The EJB bean resides in the container , which in turn reside on the
EJB server.
• A program on the client side makes remote calls to the EJBs.The
client can never communicate directly with the EJB beans.
• It talks to the EJB bean through the Home and Remote interfaces
provided by the container.

3. What is the role of the container ?


• An container is an enviroment in which the EJBs execute.
• It can contain one or more EJB classes.
• The container is resposible for generating the implementations of the
Home and Remote interfaces.
• Clients can never connect to the EJB bean itself , rather they connect
to the representation of the EJB(EJBObject) provided by the
container , which then forwards the clients request to the EJB.
• The container provides the following facilities :
• Swapping to and from secondary storage(for session beans).
• Persistence management (for entity beans).
• Creation and lookup of the Home object through the JNDI (Java
Naming & Directory Interfaces) accessible namespace.
• Supports management of multiple Instances.

1
• Implementation of certain basic security services.
• Support for transactions management.

4. What does the Home interface do ?


• The EJBHome object must implement the home interface.
• This interface contains the methods used by the clients to create and
remove the instances of the EJB.
• The home interface is the client’s initial point of contact with your
EJB components.
• For the client to access the EJB , an instance of the EJB is created
from one or more create() methods of the Home interface.
• The ejbCreate() methods defined in the EJB must also be declared
with matching signatures in the Home interface.
• Returns a reference to a EJB by creating or finding it.

5. What does the Remote interface do ?


• The EJBObject class must implement the remote interface.
• Once the client has used the home interface to gain access to EJB ,it
uses this interface to invoke the business methods defined in the EJB
class.
• Clients can never get a reference to the EJBs class , only the
EJBObject class.
• The EJB container uses the remote interface for your bean to
generate both the client-side stub and server-side proxy object that
passes client calls to your EJB object.

6. What is the EJB class?


• EJBHome and EJBObject interfaces and classes control access to the
EJB class.
• The EJB is the class that the developer writes to provide application
functionality or business logic.
• The methods in this bean are never invoked directly from the
client.The client calls the EJBs methods indirectly through the
EJBObject which acts as a proxy.
• The developer has the option of creating either a Session bean or
Entity bean.

7. What are Session beans ?

2
• A session bean is an EJB bean where each instance of a session bean
is created through its home interface and is private to the client.
• The life time of a session bean is that of its client.
• This allows it to maintain the clients state. E.g. Shopping cart .
• Represents a transient conversation with a client.
• It is relatively short lived. Only for the duration of single
client/server session.
• If the server or client crashes , the session bean is gone.
• Might use an entity bean to make a call , in that case the session bean
is the client.
• The container may optionally implement a swapping mechanism to move
the instances of the session beans from the memory to secondary
storage.
• This can be done by serialization of the bean.
• The method ejbPassivate()-(passivation means the process of swapping
out the bean) and ejbActivate()-(activation means the process of
restoring the bean) allow the container to tell the bean that it is
about to be swapped out and that it has just swapped in.
• If the bean is currently in a transaction , it will not be
passivated(swapped out).

8. What are two types of session beans ?


• A session beans deployment descriptor must declare the bean as
either a stateless or stateful one.
• The two types of session beans are Stateless and Stateful session
beans.
Stateless session bean:-It is one that does not keep track of the
state information between method calls.
• Stateless session beans are not swapped.
• Since they do not maintain state there is nothing to preserve.
• It can also be shared by multiple incoming clients.
• Essestially a bean with no instance variables.

Stateful session bean :-It is one that keeps track of the state
information between method calls or a conversation.
• Essentially a bean with instance variables.
• Maintains a user session.

3
• Since there is conversation between methods the state has to be
preserved.

9. What is an Entity bean ?


• They are used to represent persistent data.
• An entity bean can be defined to represent a row in a database table ,
where each instance of the bean represents a specific row.
• It is long lived. Exists across client session.
• Unlike session beans creating an entity bean means that a new row is
created in the database. So in addition to the create() ,the Home
interface will also have finder methods like( findByPrimaryKey() ).
• The finder method will return a unique identifier , or a primary key to
the container.
• The container will take this primary key and use it to instansiate a new
EJBObject to represent the selected row.
• The activation and passivation work in the same manner as session
beans.
• They are recoverable from system crashes.

10. What are the two types of Entity beans ?


• The two types are Bean managed persistence and Container managed
persistence:-
• Bean Managed Persistence :-
• The developer of the bean must write any necessary database calls to
send the object out to persistent storage and read it back in again.
• To achieve this u must place your database calls within the ejbLoad()
method of the bean.
• The container calls the ejbLoad() to get the state from the database.
• The container calls the ejbStore() to write the state to the database.
• The rows in the database remain locked as long as the transaction
context is alive.
• When the transaction is about to be committed by the client or the
container , the container will first invoke the ejbStore() method to
flush the data to the database.
• Advanced features like connection pooling and caching are not easily
managed because it has been developed manually.

• Container managed persistence :-

4
• The container is responsible for persistence.
• You just have to specify which fields are persistent.
• Advanced features like connection pooling and caching are easily
supported.
• The container will load the data from the database into the bean and
then invoke the ejbLoad() to tell that it has just received data from
the database.
• Likewise the container will invoke the ejbStore() to tell its data is
about to be written to the database.
• For portability and scalability a container managed persistence is
used.

11. What are the transactions supported ?


• EJB supports 6 modes of transaction:-
• TX_NOT_SUPPORTED.
• TX_SUPPORTS.
• TX_REQUIRES_NEW.
• TX_REQUIRED.
• TX_BEAN_MANAGED.
• TX_MANADATORY.

12. What is a deployment descriptor ?


• The deployment descriptor objects are used to establish the runtime
service settings for an enterprise bean.
• This object defines the enviromental properties , along with the
enterprise bean class name, the JNDI namespace,the home and
remote interface name.
• It has two types depending on the requirements,Session descriptor
and entity descriptor.
• The delpoyment descriptor also contains detailed inforamtion about
how the bean should execute regarding transaction and security.
• The deployment descriptor provides the full description of all files in
the ejb jar.
• Now the deployment descriptor is defined in a XML based format
having some standard tags and attributes.

5
13. What are the steps involved in running an EJB ?
• Create the Remote and Home interface for the EJB.
• Create the EJB beans class.
• Compile the above classes.
• Create one of the XML based deployment descriptors(session or
entity descriptors).
• Create the EJB jar file of the above classes.
• Deploy the EJB jar file.(To deploy an EJB the appropriate descriptor
is allocated,initialised and serialized and placed in a jar file along with
the EJB classes).The EJB deployer is responsible for installing the
EJB classes in the EJB server.

Você também pode gostar