Lesson 3.6: Create the EJB component subpackage
About this task
The following table lists the three subpackages of the ejb implementation design subpackage:
| Package | Description |
|---|---|
| model | This subpackage describes the domain classes that represent the persistent application data. The model subpackage contains the Customer and Account classes that you defined in the analysis model. |
| to | This subpackage contains the transfer objects that extract information from the design layers in the model. The transfer objects are interfaces that the Customer and Account classes implement. |
| facade | This subpackage contains the implementation of the business logic for the PiggyBank online banking system. The session facade contains the PiggyBankController class that defines the functional tasks, such as the Display Balance, Transfer Money, and Cash Check operations that were described in the PiggyBank use-case model. |
In this lesson, you create the Customer and Account domain EJB classes and their interfaces. You create the IAccount and ICustomer interfaces in the framework package.
The Customer and Account enterprise beans form the domain of the PiggyBank design model, and are used to persist the application data. The Customer and Account classes derive from the same two classes that you identified in the PiggyBank analysis model.
Because you decided during the design not to persist transfer data or check data, you do not have to create Transfer and Check business objects that persist.
Create the EJB customer
Procedure
- In the Project Explorer view, expand Enterprise IT Design Model and expand PiggyBank Implementation Designs.
- Right-click the itso.ad.business subpackage; then click Add UML > Package.
- Name the package model.
- In the Project Explorer view, double-click Main.
- In the diagram editor, name the diagram model - Persistent Entity (EJB) Model.
- In the Palette, double-click Class and name the class Customer.
Create the parameters of the Customer class
Procedure
- In the diagram editor, right-click the Customer class; then click Add UML > Attribute.
- Name the attribute name.
- In the Properties view, click Select type.
- In the Select Element window, click String.
- Add another attribute to the Customer class of type String called customerId.
- In the diagram editor, right-click the Customer class; then click Add UML > Operation.
- Name the operation getData.
- In the Properties view, click Set return type.
- In the Select Element window, expand itso.ad.business, expand framework and, in the interfaces.to subpackage, click ICustomerTO.
Results
You created the Customer entity bean. Your diagram should look similar to the following figure:

Create the EJB account
Procedure
- In the Palette, double-click Class and name the class Account.
- In the diagram editor, right-click the Account class; then click Add UML > Attribute.
- Name the attribute balance.
- In the Properties view, click Select type.
- In the Select Element window, click Integer.
- In the diagram editor, right-click the Account class; then click Add UML > Attribute.
- Name the attribute accountNumber.
- In the Properties view, click Select type.
- In the Select Element window, click String.
- In the diagram editor, right-click the Account class; then click Add UML > Operation.
- Name the operation getData.
- In the Properties view, click Set return type.
- In the Select Element window, expand itso.ad.business, expand framework and, in the interfaces.to subpackage, click IAccountTO.
- In the Palette, click Association.
- In the diagram editor, click the Customer class and drag the cursor to the Account class.
- In the diagram editor, click the Association relationship.
- In the Properties view, in the Accounts Multiplicity field, type an asterisk (*).
Results
You created the Persistent Entity EJB Model diagram. Note that the getData operations of the Customer and Account enterprise beans return the transfer object interfaces that you created in the previous lesson. Your diagram should look similar to the following figure:

Create the transfer-object enterprise beans
About this task
Create the PiggyBankEJBCustomerTO interface
Procedure
- In the Project Explorer view, expand Enterprise IT Design Model and expand PiggyBank Implementation Designs.
- Right-click the itso.ad.business subpackage; then click Add UML > Package.
- Name the package to.
- In the Project Explorer view, double-click Main.
- In the diagram editor, add the title interfaces.to - Transfer Object Implementations.
- In the Palette, double-click Class and name the class PiggyBankEJBCustomerTO.
Create the parameters of the PiggyBankEJBCustomerTO interface
About this task
Procedure
- In the diagram editor, right-click the PiggyBankEJBCustomerTO class; then click Add UML > Attribute.
- Name the attribute id.
- In the Properties view, click Select type.
- In the Select Element window, click Integer.
- Add another attribute to the PiggyBankEJBCustomerTO class of type String called name.
- In the diagram editor, right-click the PiggyBankEJBCustomerTO class; then click Add UML > Operation.
- Name the operation PiggyBankEJBCustomerTO ( newId, newName ).
- In the Properties view, on the Parameters page, for the newId parameter, click the Type field and change the parameter type to String.
- For the newName parameter, click the Type field and change the parameter type to String.
Create the implementation relationship
Procedure
- In the Project Explorer view, expand Enterprise IT Design Model, expand PiggyBank Implementation Designs, expand itso.ad.business, and expand framework.
- In the interfaces.to subpackage, click the ICustomerTO class and drag it into the diagram.
- In the Palette, click Implements.
- In the diagram editor, click the PiggyBankEJBCustomerTO class and drag the cursor to the ICustomerTO interface.
Results
Your diagram should look similar to the following figure:

Create the PiggyBankEJBAccountTO enterprise bean
Procedure
- In the Palette, double-click Class and name the class PiggyBankEJBAccountTO.
- In the diagram editor, right-click the PiggyBankEJBAccountTO class; then click Add UML > Attribute.
- Name the attribute balance.
- In the Properties view, click Select type.
- In the Select Element window, click Integer.
- Add another attribute of type String to the PiggyBankEJBAccountTO class called number.
- In the diagram editor, right-click the PiggyBankEJBAccountTO class; then click Add UML > Operation.
- Name the operation PiggyBankEJBAccountTO ( newAccountNumber, newBalance ).
- In the Properties view, on the Parameters page, click the Type field of the newAccountNumber parameter, and change the parameter type to String.
- Click the Type field of the newBalance parameter, and change the parameter type to Integer.
Results
Model the implementation relationship
Procedure
- In the Project Explorer view, expand Enterprise IT Design Model, expand PiggyBank Implementation Designs, expand itso.ad.business, and expand framework.
- In the interfaces.to subpackage, click the IAccountTO class and drag it into the diagram.
- In the Palette, click Implements.
- In the diagram editor, click the PiggyBankEJBAccountTO class and drag it to the IAccountTO interface.
Results
Your diagram should look similar to the following figure:

Create the facade enterprise bean
About this task
Create the PiggyBankController class
Procedure
- In the Project Explorer view, expand Enterprise IT Design Model and expand PiggyBank Implementation Designs.
- In the itso.ad.business subpackage, right-click the ejb package; then click .
- Name the new package facade.
- In the Project Explorer view, double-click the Main diagram and add the title facade - Session Facade (EJB Stateless Bean) on model.
- In the Palette, double-click Class and name the interface PiggyBankController.
Create the cashCheck operation
Procedure
- In the diagram editor, right-click the PiggyBankController class; then click .
- Name the operation cashCheck ( accountToCredit, checkAmount, checkReference ).
- In the Properties view, on the Parameters page, for the accountToCredit parameter, click the Type field and change the parameter type to String.
- For the checkAmount parameter, click the Type field and change the parameter type to Integer.
- For the checkReference parameter, click the Type field and change the parameter type to String.
Create the getAccountByCustomerId operation
Procedure
- In the diagram editor, right-click the PiggyBankController class; then click .
- Name the operation getAccountByCustomerId ( customerId ).
- In the Properties view, on the Parameters page, for the customerId parameter, click the Type field and change the parameter type to String.
- In the Properties view, on the General page, click Set return type.
- In the Select Element window, expand itso.ad.business, expand framework and, in the interfaces.to package, click IAccountTO.
- In the Properties view, on the General page, select the Ordered check box and clear the Unique check box.
- On the Advanced page, beside Multiplicity, click the Value field and click 1..*.
Create the getBalance operation
Procedure
- In the diagram editor, right-click the PiggyBankController class; then click .
- Name the operation getBalance ( accountNumber, customerId ).
- In the Properties view, on the Parameters page, for the accountNumber parameter, click the Type field and change the parameter type to String.
- For the customerId parameter, click the Type field and change the parameter type to String.
- In the Properties view, on the General page, click Set return type.
- In the Select Element window, click Integer.
Create the getCustomerById operation
Procedure
- In the diagram editor, right-click the PiggyBankController class; then click .
- Name the operation getCustomerById ( customerId ).
- In the Properties view, on the Parameters page, for the customerId parameter, click the Type field and change the parameter type to String.
- In the Properties view, on the General page, click Set return type.
- In the Select Element window, expand itso.ad.business, expand framework and, in the interfaces.to package, click ICustomerTO.
Create the transfer operation
Procedure
- In the diagram editor, right-click the PiggyBankController class; then click .
- Name the operation transfer ( amountToTransfer, creditAccountNr, customerId, debitAccountNr ).
- In the Properties view, on the Parameters page, for the amountToTransfer parameter click the Type field and change the parameter type to Integer.
- For the creditAccountNr parameter, click the Type field and change the parameter type to String.
- For the customerId parameter, click the Type field and change the parameter type to String.
- For the debitAccountNr parameter, click the Type field and change the parameter type to String.
Results
You modeled the itso.ad.business component-layer facade. Your diagram should look similar to the following figure:
