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. ...
Get Enterprise JavaBeans, Fourth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.