Overview

As you saw yesterday, Session beans are a key technology within the J2EE platform because they allow business functionality to be developed and then deployed independently of the presentational layer.

For example, you might create an application with a user interface built using Java's Swing API. This application might then provide access to some business functionality for the employees working on the company's internal network. If the underlying business functionality is implemented as Session beans, a different user interface could take its place without having to redevelop the entire application. A Web-based interface would make the application available from the Internet at a single stroke.

There are two types of Session beans: stateful and stateless. Stateful Session beans, as the name suggests, maintain client state and can therefore only be used by a single client. Stateless Session beans maintain no client state and can be shared among many clients. A couple of analogies help explain the differences between them.

At some point, you almost certainly will have used a so-called wizard to guide you through some task--in any modern word-processing program or IDE. A wizard encapsulates a conversation between you the user and the application running on the computer. The steps in that conversation are dictated by the Next and the Back buttons. The wizard remembers the answers from one page, and these sometimes dictate the choices for the next. When you are done, you select the Finish button and the wizard goes away and does its stuff.

The wizard is analogous to a stateful Session bean. The wizard remembers the answers from each page, or put another way, it remembers the state of the conversation. It also provides some service, as characterized by the Finish button. This is precisely what a stateful Session bean does.

On the other hand, you may well have had cause to write or call stored procedures. These are named routines (methods and functions) that are stored in a database. They provide a way to implement business rules on the database.

To invoke a stored procedure, a client-side application needs to know just the name of the stored procedure and the parameters it requires. No knowledge of the underlying database schema is needed.

A stored procedure is analogous to a stateless Session bean. The stored procedure just provides a service and can be invoked by any client.

Session beans provide a service to a client application. In other words, Session beans are an extension of a client's business functionality into the middle tier.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.19.185