12.11.2014 Views

web server - Borland Technical Publications

web server - Borland Technical Publications

web server - Borland Technical Publications

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Client view of an enterprise bean<br />

remote interface--sort() and merge()--to do its sorting work. When the work finishes,<br />

the client calls the remote interface's remove() method to remove the instance of the<br />

enterprise bean.<br />

Session beans<br />

A client obtains a reference to a session bean's remote interface by calling one of the<br />

create methods on the home interface.<br />

All session beans must have at least one create() method. A stateless session bean<br />

must have only one create() method, and that method must have no arguments. A<br />

stateful session bean can have one create() method, and may have additional<br />

create() methods whose parameters vary. If a create() method does have parameters,<br />

the values of these parameters are used to initialize the session bean.<br />

The default create() method has no parameters. For example, the sort example uses a<br />

stateless session bean. It has, by definition, one create() method that takes no<br />

parameters:<br />

Sort sort = home.create();<br />

The cart example, on the other hand, uses a stateful session bean, and its home<br />

interface, CartHome, implements more than one create() method. One of its create()<br />

methods takes three parameters, which together identify the purchaser of the cart<br />

contents, and returns a reference to the Cart remote interface. The CartClient sets<br />

values for the three parameters--cardHolderName, creditCardNumber, and expirationDate-<br />

-then calls the create() method. This is shown in the code sample below:<br />

Cart cart;<br />

{<br />

String cardHolderName = "Jack B. Quick";<br />

String creditCardNumber = "1234-5678-9012-3456";<br />

Date expirationDate = new GregorianCalendar(2001, Calendar.JULY,<br />

1).getTime();<br />

cart = home.create(cardHolderName, creditCardNumber, expirationDate);<br />

}<br />

Session beans do not have finder methods.<br />

Entity beans<br />

A client obtains a reference to an entity object either through a find operation or a<br />

create operation. Recall that an entity object represents some underlying data stored in<br />

a database. Because the entity bean represents persistent data, entity beans typically<br />

exist for quite a long time; certainly for much longer than the client applications that call<br />

them. Thus, a client most often needs to find the entity bean that represents the piece<br />

of persistent data of interest, rather than creating a new entity object, which would<br />

create and store new data in the underlying database.<br />

A client uses a find operation to locate an existing entity object, such as a specific row<br />

within a relational database table. That is, find operations locate data entities that have<br />

previously been inserted into data storage. The data may have been added to the data<br />

store by an entity bean or it may have been added outside of the EJB context, such as<br />

directly from within the database management system (DBMS). Or, in the case of<br />

legacy systems, the data may have existed prior to the installation of the EJB<br />

container.<br />

A client uses an entity bean object's create() method to create a new data entity that<br />

will be stored in the underlying database. An entity bean's create() method inserts the<br />

entity state into the database, initializing the entity's variables according to the values in<br />

the create() method's parameters. A create() method for an entity bean always returns<br />

the remote interface, but the corresponding ejbCreate() method returns primary key of<br />

the entity instance.<br />

Chapter 11: Writing enterprise bean clients 87

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!