You will now create a stateless session bean named QuickOrderProcessorBean in your EJB Module project QuickCarRentalEJB. This session bean will implement the business logic of the car rental application. In particular, you will add the business methods to the bean that enable the application to save bookings, cancel bookings, and display all active bookings at the client end.
|
You have created the EJB project QuickCarRentalEjb. The structure of this project is currently displayed in the J2EE Explorer. |
|
You have created the necessary auxiliary classes in the Java project Helperclasses. |
Since the auxiliary classes from the Java project are to be referenced in the EJBs, you will need to add the Java project Helperclasses as a required project to the EJB project.
...
1. In the J2EE Explorer, select the project node QuickCarRentalEjb and open the context menu.
2. Choose Properties.
3. Choose Java Build Path in the left frame. In the right frame, choose the Projects tab.
4. Select Helperclasses and confirm with OK.
|
|
...
1. In the J2EE Explorer, to open the relevant wizard, choose New → EJB… from the context menu of the project node QuickCarRentalEjb.
2. In the New EJB wizard that appears, assign the following values to the properties of the new EJB:
|
|
EJB Name |
QuickOrderProcessorBean |
EJB Project |
QuickCarRentalEjb |
Beantype |
Stateless Session Bean |
Default Package |
com.sap.examples.quickcarrental |
Generate default interfaces |
activated |
3. Choose Next.
4. Accept the settings in the next screen and choose Next.
In the wizard dialog that appears, you can add the necessary business methods.
To make the specific features of the business logic available, you will need the following business methods:
Business Method |
Use |
Saves the booking data. |
|
cancelBooking |
Implements the cancellation of a booking and sets its status to CANCELLED. |
viewActiveBookings |
Provides data for all active bookings to the client or to a Web service. |
5. To add the first method, saveBooking, select the Business Methods folder in the left pane of the wizard and choose Add.
To the right, input fields appear, where you can specify the method.
6. Enter the name saveBooking and as the return type assign the auxiliary class com.sap.engine.examples.util.QuickBookingModel.
7. Add the following parameters to the method:
Name of the parameter |
Type (Full Qualified Name) |
vehicleTypeId |
java.lang.String |
dateFromString |
java.lang.String |
dateToString |
java.lang.String |
pickupLocation |
java.lang.String |
dropoffLocation |
java.lang.String |
|
|
8. To add the method cancelBooking, select the Business Methods folder again in the left pane of the wizard and choose Add.
9. Enter the name cancelBooking and assign the return type java.lang.String.
10. Add the parameter bookingId of type java.lang.String to this method.
11. Add the third method, viewActiveBookings. Enter the following values:
|
|
Name |
viewActiveBookings |
Return Type |
com.sap.engine.examples.util.QuickBookingModel |
Array |
activated |
Array/Input field |
1 (for a one-dimensional array) |
Parameters |
None |
|
|
12. Choose Finish to create the session bean.
The wizard generates: the bean class QuickOrderProcessorBean; the local interface QuickOrderProcessorLocal; remote interface QuickOrderProcessor; local home interface QuickOrderProcessorLocalHome and home interface QuickOrderProcessorBeanHome, with the appropriate EJB default methods and the three business methods.
In the J2EE Explorer, a new substructure named QuickOrderProcessorBean is inserted automatically under QuickCarRentalEjb → ejb-jar.xml.
|
|
Implementing the Session Bean Class