Chapter 7 Enterprise JavaBeans Overview
The Enterprise JavaBeans (EJB) technology defines a model for the development and deployment of reusable Java server components, called EJB components.
An EJB component is a nonvisual server component with methods that typically provide business logic in distributed applications. A remote client, called an EJB client, can invoke these methods, which typically results in the updating of a database. Since Jaguar uses CORBA as the basis for the EJB component support, EJB components running in Jaguar can be called by any other type of Jaguar client or component, and even CORBA clients using ORBs from other vendors that are compatible with CORBA 2.3.
The EJB architecture looks like this:
EJB server The EJB server contains the EJB container, which provides the services required by the EJB component. Jaguar CTS is an EJB server.
EJB client An EJB client usually provides the user-interface logic on a client machine. The EJB client makes calls to remote EJB components on a server and needs to know how to find the EJB server and how to interact with the EJB components. An EJB component can act as a EJB client by calling methods in another EJB component.
An EJB client does not communicate directly with an EJB component. The container provides proxy objects that implement the components home and remote interfaces. The component's remote interface defines the business methods that can be called by the client. The client calls the home interface methods to create and destroy proxies for the remote interface.
EJB container The EJB specification defines a container as the environment in which one or more EJB components execute. The container provides the infrastructure required to run distributed components, allowing client and component developers to focus on programming business logic, and not system-level code. In Jaguar, the container encapsulates:
EJB component implementation The Java class that runs in the server implements the Bean's business logic. The class must implement the remote interface methods and additional methods for lifecycle management.
You can implement three types of EJB component, each for a different purpose:
A stateful session Bean manages complex processes or tasks that require the accumulation of data, such as adding items to a Web catalog's shopping cart. Stateful session Beans have the following characteristics:
For example, if you create a session Bean on a Web server that tracks a user's path through the site, the session Bean is destroyed when the user leaves the site or idles beyond a specified time
A stateless session Bean manages tasks that do not require the keeping of client session data between method calls. Stateless session Beans have the following characteristics:
Unlike stateful session Beans, stateless session Beans can be pooled by the server, improving overall application performance.
An entity Bean models a business concept that is a real-world object. For example, an entity Bean might represent a scheduled airplane flight, a seat on the airplane, or a passenger's frequent-flyer account. Entity Beans have the following characteristics:
Each EJB component has a transaction attribute that determines how instances of the component participate in transactions. In Jaguar, you set the transaction attribute in the Transaction tab of the Component Properties dialog box.
When you design an EJB component, you must decide how the Bean will manage transaction demarcation: either programmatically in the business methods, or whether the transaction demarcation will be managed by the container based on the value of the transaction attribute in the deployment descriptor.
A session Bean can use either Bean-managed transaction demarcation or with container-managed transaction demarcation; you cannot create a session Bean where some methods use container-managed demarcation and others use Bean-managed demarcation. An entity Bean must use container-managed transaction demarcation.
Table 7-1 lists the transaction attribute values. Requires, Supports, Requires New, or Mandatory are the values that specify container-managed transaction demarcation. You can set the Transaction Attribute for the component and for individual methods in the home and remote interfaces. Values set at the method level override the component setting.
The EJB container provides services to EJB components. The services include transaction and persistence support.
Transaction support An EJB container must support transactions. EJB specifications provide an approach to transaction management called declarative transaction management. In declarative transaction management, you specify the type of transaction support required by your EJB component. When the Bean is deployed, the container provides the necessary transaction support.
Persistence support An EJB container can provide support for persistence of EJB components. An EJB component is persistent if it is capable of saving and retrieving its state. A persistent EJB component saves its state to some type of persistent storage (usually a file or a database). With persistence, an EJB component does not have to be re-created with each use.
An EJB component can manage its own persistence (by means of the logic you provide in the Bean) or delegate persistence services to the EJB container. Container-managed persistence means that the data appears as member data and the container performs all data retrieval and storage operations for the EJB component. See Chapter 29, "Managing Persistent Component State" for more information.
Copyright © 2000 Sybase, Inc. All rights reserved. |