< Previous | Next >

Lesson 3.6: Create the EJB component subpackage

In this lesson, you model the EJB implementation-design subpackage. This subpackage models the Enterprise JavaBeans (EJB) layer that contains the domain models that persist the data for the application. The EJB layer implements the business logic for the itso.ad.business layer.

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

  1. In the Project Explorer view, expand Enterprise IT Design Model and expand PiggyBank Implementation Designs.
  2. Right-click the itso.ad.business subpackage; then click Add UML > Package.
  3. Name the package model.
  4. In the Project Explorer view, double-click Main.
  5. In the diagram editor, name the diagram model - Persistent Entity (EJB) Model.
  6. In the Palette, double-click Class and name the class Customer.

Create the parameters of the Customer class

Procedure

  1. In the diagram editor, right-click the Customer class; then click Add UML > Attribute.
  2. Name the attribute name.
  3. In the Properties view, click Select type.
  4. In the Select Element window, click String.
  5. Add another attribute to the Customer class of type String called customerId.
  6. In the diagram editor, right-click the Customer class; then click Add UML > Operation.
  7. Name the operation getData.
  8. In the Properties view, click Set return type.
  9. 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:

The Customer EJB.

Create the EJB account

Procedure

  1. In the Palette, double-click Class and name the class Account.
  2. In the diagram editor, right-click the Account class; then click Add UML > Attribute.
  3. Name the attribute balance.
  4. In the Properties view, click Select type.
  5. In the Select Element window, click Integer.
  6. In the diagram editor, right-click the Account class; then click Add UML > Attribute.
  7. Name the attribute accountNumber.
  8. In the Properties view, click Select type.
  9. In the Select Element window, click String.
  10. In the diagram editor, right-click the Account class; then click Add UML > Operation.
  11. Name the operation getData.
  12. In the Properties view, click Set return type.
  13. In the Select Element window, expand itso.ad.business, expand framework and, in the interfaces.to subpackage, click IAccountTO.
  14. In the Palette, click Association.
  15. In the diagram editor, click the Customer class and drag the cursor to the Account class.
  16. In the diagram editor, click the Association relationship.
  17. 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:

The Customer and Account EJB relationships.

Create the transfer-object enterprise beans

About this task

The transfer-object enterprise beans transfer data between the layers of the PiggyBank design model. The PiggyBankEJBCustomerTO and PiggyBankEJBAccountTO implement the ICustomer and IAccount interfaces that you defined in the framework component layer.

Create the PiggyBankEJBCustomerTO interface

Procedure

  1. In the Project Explorer view, expand Enterprise IT Design Model and expand PiggyBank Implementation Designs.
  2. Right-click the itso.ad.business subpackage; then click Add UML > Package.
  3. Name the package to.
  4. In the Project Explorer view, double-click Main.
  5. In the diagram editor, add the title interfaces.to - Transfer Object Implementations.
  6. In the Palette, double-click Class and name the class PiggyBankEJBCustomerTO.

Create the parameters of the PiggyBankEJBCustomerTO interface

About this task

To create the parameters of the PiggyBankEJBCustomerTO interface:

Procedure

  1. In the diagram editor, right-click the PiggyBankEJBCustomerTO class; then click Add UML > Attribute.
  2. Name the attribute id.
  3. In the Properties view, click Select type.
  4. In the Select Element window, click Integer.
  5. Add another attribute to the PiggyBankEJBCustomerTO class of type String called name.
  6. In the diagram editor, right-click the PiggyBankEJBCustomerTO class; then click Add UML > Operation.
  7. Name the operation PiggyBankEJBCustomerTO ( newId, newName ).
  8. In the Properties view, on the Parameters page, for the newId parameter, click the Type field and change the parameter type to String.
  9. For the newName parameter, click the Type field and change the parameter type to String.

Create the implementation relationship

Procedure

  1. In the Project Explorer view, expand Enterprise IT Design Model, expand PiggyBank Implementation Designs, expand itso.ad.business, and expand framework.
  2. In the interfaces.to subpackage, click the ICustomerTO class and drag it into the diagram.
  3. In the Palette, click Implements.
  4. 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:

The PiggyBankEJBCustomer relationship

Create the PiggyBankEJBAccountTO enterprise bean

Procedure

  1. In the Palette, double-click Class and name the class PiggyBankEJBAccountTO.
  2. In the diagram editor, right-click the PiggyBankEJBAccountTO class; then click Add UML > Attribute.
  3. Name the attribute balance.
  4. In the Properties view, click Select type.
  5. In the Select Element window, click Integer.
  6. Add another attribute of type String to the PiggyBankEJBAccountTO class called number.
  7. In the diagram editor, right-click the PiggyBankEJBAccountTO class; then click Add UML > Operation.
  8. Name the operation PiggyBankEJBAccountTO ( newAccountNumber, newBalance ).
  9. In the Properties view, on the Parameters page, click the Type field of the newAccountNumber parameter, and change the parameter type to String.
  10. Click the Type field of the newBalance parameter, and change the parameter type to Integer.

Results

You modeled the PiggyBankEJBAccountTO enterprise bean. The PiggyBankEJBAccountTO enterprise bean contains a single constructor that instantiates the class given an account number and balance. You must now model the relationship between the PiggyBankEJBAccountTO enterprise bean and the IAccountTO interface.

Model the implementation relationship

Procedure

  1. In the Project Explorer view, expand Enterprise IT Design Model, expand PiggyBank Implementation Designs, expand itso.ad.business, and expand framework.
  2. In the interfaces.to subpackage, click the IAccountTO class and drag it into the diagram.
  3. In the Palette, click Implements.
  4. 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:

The PiggyBankEJBAccountTO and  PiggyBankEJBCustomerTO relationships.

Create the facade enterprise bean

About this task

The facade component separates the persistent application data from the business logic. The facade enterprise bean is defined by the PiggyBankController class which is derived from the control classes that you identified in the PiggyBank analysis model.

Create the PiggyBankController class

Procedure

  1. In the Project Explorer view, expand Enterprise IT Design Model and expand PiggyBank Implementation Designs.
  2. In the itso.ad.business subpackage, right-click the ejb package; then click Add UML > Package.
  3. Name the new package facade.
  4. In the Project Explorer view, double-click the Main diagram and add the title facade - Session Facade (EJB Stateless Bean) on model.
  5. In the Palette, double-click Class and name the interface PiggyBankController.

Create the cashCheck operation

Procedure

  1. In the diagram editor, right-click the PiggyBankController class; then click Add UML > Operation.
  2. Name the operation cashCheck ( accountToCredit, checkAmount, checkReference ).
  3. In the Properties view, on the Parameters page, for the accountToCredit parameter, click the Type field and change the parameter type to String.
  4. For the checkAmount parameter, click the Type field and change the parameter type to Integer.
  5. For the checkReference parameter, click the Type field and change the parameter type to String.

Create the getAccountByCustomerId operation

Procedure

  1. In the diagram editor, right-click the PiggyBankController class; then click Add UML > Operation.
  2. Name the operation getAccountByCustomerId ( customerId ).
  3. In the Properties view, on the Parameters page, for the customerId parameter, click the Type field and change the parameter type to String.
  4. In the Properties view, on the General page, click Set return type.
  5. In the Select Element window, expand itso.ad.business, expand framework and, in the interfaces.to package, click IAccountTO.
  6. In the Properties view, on the General page, select the Ordered check box and clear the Unique check box.
  7. On the Advanced page, beside Multiplicity, click the Value field and click 1..*.

Create the getBalance operation

Procedure

  1. In the diagram editor, right-click the PiggyBankController class; then click Add UML > Operation.
  2. Name the operation getBalance ( accountNumber, customerId ).
  3. In the Properties view, on the Parameters page, for the accountNumber parameter, click the Type field and change the parameter type to String.
  4. For the customerId parameter, click the Type field and change the parameter type to String.
  5. In the Properties view, on the General page, click Set return type.
  6. In the Select Element window, click Integer.

Create the getCustomerById operation

Procedure

  1. In the diagram editor, right-click the PiggyBankController class; then click Add UML > Operation.
  2. Name the operation getCustomerById ( customerId ).
  3. In the Properties view, on the Parameters page, for the customerId parameter, click the Type field and change the parameter type to String.
  4. In the Properties view, on the General page, click Set return type.
  5. In the Select Element window, expand itso.ad.business, expand framework and, in the interfaces.to package, click ICustomerTO.

Create the transfer operation

Procedure

  1. In the diagram editor, right-click the PiggyBankController class; then click Add UML > Operation.
  2. Name the operation transfer ( amountToTransfer, creditAccountNr, customerId, debitAccountNr ).
  3. In the Properties view, on the Parameters page, for the amountToTransfer parameter click the Type field and change the parameter type to Integer.
  4. For the creditAccountNr parameter, click the Type field and change the parameter type to String.
  5. For the customerId parameter, click the Type field and change the parameter type to String.
  6. 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:

The PiggyBankController class contains the facade implementation for the PiggyBank itso.ad.business design layer.

< Previous | Next >

Feedback