O'Reilly logo

Enterprise JavaBeans, Fourth Edition by Richard Monson-Haefel, Bill Burke, Sacha Labourey

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 28. Exercises for Chapter 11

Exercise 11.1: A Stateless Session Bean

In this exercise, you will build and examine a stateless session bean, ProcessPaymentEJB, which writes payment information to the database. You will also build a client application to test this ProcessPayment bean.

The bean inserts the payment information data directly into the database, without using an intermediary entity bean.

Examine the EJB

This example is based on the Customer and Address EJBs and their related data objects that you used in Exercise 6.3. The present exercise leaves these EJBs unchanged, and focuses on the ProcessPayment stateless session bean.

The ProcessPayment bean has a very simple remote interface. It offers options to process a payment by check, cash, or credit card. Each possibility is handled by a different method.

ProcessPaymentRemote.java

public interface ProcessPaymentRemote extends javax.ejb.EJBObject
{
   public boolean byCheck (CustomerRemote customer, 
                           CheckDO        check, 
                           double         amount)
   throws RemoteException, PaymentException;
   
   public boolean byCash (CustomerRemote customer, 
                          double         amount)
   throws RemoteException, PaymentException;
   
   public boolean byCredit (CustomerRemote customer, 
                            CreditCardDO   card, 
                            double         amount)
   throws RemoteException, PaymentException;
   ...
}

Each method’s third parameter is a simple transaction amount. The other two are more interesting.

The first is a CustomerRemote interface, which enables the ProcessPayment EJB to get any information it needs about the customer. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required