Exercise 3.6: Modeling the EJB component subpackage

In this exercise, 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.

The ejb impementation design subpackage is divided into the three subpackages in the following table:

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 abstract information between the design layers in the model. The transfer objects are interfaces that are implemented by the Customer and Account classes.
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 exercise, you create the Customer and Account domain EJB classes and their interfaces. You create the IAccount and ICustomer interfaces in the framework package.

Modeling the domain enterprise beans

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 are derived from the same two classes that you identified in the PiggyBank analysis model.The original domain diagram showing the Account and Customer classes. The PiggyBank design model does not contain persistable Check and Transfer classes. Because you decided at design time not to persist transfer or check data, there is no need to create persistable Transfer and Check business objects.

To model the EJB Customer:
  1. In the Model 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 Model 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.

To model the parameters of the Customer class:
  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.

You have created the Customer entity EJB. Your diagram should look similar to the following figure:

The Customer EJB.

To model the EJB Account:
  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. Add an attribute of type String to the Account class called accountNumber.
  7. In the diagram editor, right-click the Account class; then click Add UML > Operation.
  8. Name the operation getData.
  9. In the Properties view, click Set return type.
  10. In the Select Element window, expand itso.ad.business, expand framework and in the interfaces.to subpackage, click IAccountTO.
  11. In the Palette, click Association.
  12. In the diagram editor, click the Customer class and drag it to the Account class.
  13. In the diagram editor, click the relationship.
  14. In the Properties view, in the Accounts Multiplicity field, type *.

You have 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 exercise. Your diagram should look similar to the following figure:

The Customer and Account EJB relationship.

Modeling the transfer object enterprise beans

The transfer object enterprise beans are used to 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.

To model the PiggyBankEJBCustomerTO:
  1. In the Model 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 Model 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.

To model the parameters of the PiggyBankEJBCustomerTO interface:
  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, click the Type field of the newId parameter, and change the parameter type to String.
  9. Click the Type field of the newName parameter, and change the parameter type to String.
You have modeled the PiggyBankEJBCustomerTO enterprise bean. The PiggyBankEJBCustomerTO contains a single constructor that instantiates the class given a customer ID and name. You must now model the relationship between the PiggyBankEJBCustomerTO enterprise bean and the ICustomerTO interface.

To model the implementation relationship:
  1. In the Model 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 it to the ICustomerTO interface.

Your diagram should look similar to the following figure:

The PiggyBankEJBCustomerTO EJB.

To model the PiggyBankEJBAccountTO:
  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.
You have modeled the PiggyBankEJBAccountTO enterprise bean. The PiggyBankEJBAccountTO 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.

To model the implementation relationship:
  1. In the Model 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.

Your diagram should look similar to the following figure:

The PiggyBankEJBCustomerTO and PiggyBankEJBAccountTO objects

Modeling the facade enterprise bean

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.

To model the PiggyBankController class:
  1. In the Model 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 Model 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 PiggyController.

To model the cashCheck operation:
  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, click the Type field of the accountToCredit parameter and change the parameter type to String.
  4. Click the Type field of the checkAmount parameter and change the parameter type to Integer.
  5. Click the Type field of the checkReference parameter and change the parameter type to String.

To model the getAccountByCustomerId operation:
  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, click the Type field of the customerId parameter, 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. Deselect the Unique check box.
  8. On the Advanced page, beside Multiplicity, click the Value field and click 1..*.

To model the getBalance operation:
  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, click the Type field of the accountNumber parameter, and change the parameter type to String.
  4. Click the Type field of the customerId parameter 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.

To model the getCustomerById operation:
  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, click the Type field of the customerId parameter, 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.

To model the transfer operation:
  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, click the Type field of the amountToTransfer parameter and change the parameter type to Integer.
  4. Click the Type field of the creditAccountNr parameter and change the parameter type to String.
  5. Click the Type field of the customerId parameter and change the parameter type to String.
  6. Click the Type field of the debitAccountNr parameter and change the parameter type to String.

You have modeled the itso.ad.business component layer facade. Your diagram should looked similar to the following figure:

The PiggyBankController class contains the facade implementation for the PiggyBank itso.ad.business design layer.
Terms of use | Feedback
(C) Copyright IBM Corporation 2004, 2005. All Rights Reserved.