How an enterprise bean works

 How an enterprise bean works

 

v  The remote home and/or home interface for the bean The home interface defines the methods a client uses to create , locate , and destroy instances of an enterprise bean.

v  The remote and/or local interface for bean The remote or local interface defines the business methods implemented in the bean. A client accesses these methods through the remote interface.

v The enterprise bean class The enterprise bean class implements the business logic for the bean. The client accesses these methods through the bean's remote interface.

 

Once the bean is deployed in the EJB container, the client calls the create() method defined in the home interface to instantiate the bean. The home interface isn't implemented in the bean itself, but by the container. Other methods declared in the home interface permit the client to locate an instance of a bean and to remove a bean instance when it is no longer needed. EJB 2.0 beans also allow the home interface to have business methods called EJB Home Methods, When the enterprise bean is instantiated , the client can call the business methods within the bean. The client never calls a method in the bean instance directly , however. The methods available to the client are defined in the remote or local interface of the bean , and the remote or local interface is implemented by the container . When the client calls a method, the container receives the request and delegates it to the bean instance.

 

Types of Enterprise Beans

 

An Enterprise bean can be

1.            Session Bean

2.            Entity Bean

3.            Message Driven Bean

 

Session beans

 

A session bean is a transient EJB instance that serves a single client. Session beans tend to implement procedural logic; they embody actions more than data.

 

Session beans can be either Stateful Session bean or Stateless  Session Bean

 

Stateless Session Beans:

 

Stateless beans don't maintain state for a particular client. Because they don't maintain conversational state, stateless beans can be used to support multiple clients.

 

Stateful Session Beans:

 

A stateful session bean executes on behalf of a single Client. In a sense, the session bean represents the client in the EJB server. Stateful session beans can maintain the client's state, which means they can retain information for the client. The classic example where a session bean might be used is a shopping cart for an individual shopping at an online store on the web. As the shopper selects items to put in the "cart", the session bean retains a list of the selected items. Session beans can be short lived. Usually when the clients ends the session , the bean is removed by the client.

 

Entity beans

 

An entity bean represents an object that contains data, such as customer, an account, or an inventory item. Entity beans contains data values and methods that can be invoked on those values. The values are saved in a database (using JDBC) or some other data store. Entity beans can participate in transactions involving other enterprise beans and transactional services.

 

Entity beans are often mapped to objects in databases. An entity bean can represent a row in a table, a single column in a row, or an entire table or query result. Associated with each entity bean is a unique primary key used to find, retrieve, and save the bean.

 

Unlike session beans , entity beans are considered to be long lived. They maintain a persistent state, living as long as the data remains in the database, rather than as long as a particular client needs it.

 

An entity bean can employ one of the following

 

Ø Bean managed persistence the bean contains code to retrieve and save persistent values.

Ø Container managed persistence the EJB container loads and saves values on behalf of the bean

 

Message driven beans

 

The EJB specification introduced message driven beans. They behave as a java message service (JMS) listener, processing asynchronous messages . The EJB container manages the bean’s entire environment. Message driven beans are similar to stateless session beans because they maintain no conversational state. Unlike session and entity beans, clients don’t access them through interfaces. A message driven bean has no interfaces, just a bean class. A single message driven bean can process.

No comments:

Post a Comment