Implementing Business Object Mediators to transform logical SDOs and physical SDOs

In this lesson, you import read and change mediators to transform the logical and physical SDOs. The Business Object Mediator in the WebSphere Commerce Data Service Layer transforms between logical SDOs, the Java implementation of a noun, and physical SDOs, a Java representation of a database table. There are two types of mediators: read mediators and change mediators. Read mediators transform the physical representation of data, physical SDOs, to the logical representation, logical SDOs. Change mediators translate actions on the logical SDOs such as create, update, and delete, into operations on the physical data.

About this task

A noun part is either a part of a noun, or by definition, can be a noun itself. Mediators are needed for each noun and each changeable noun part. To simplify development and maintenance of mediators, one noun can be sectioned into multiple changeable parts. It is recommended to use one mediator for each complex element in the noun, excluding any user data elements.

Breaking up your nouns into noun parts is a design decision that is based on your business logic requirements. In general, a software architect would refactor complex substructures in the noun into noun parts.

For this tutorial, the Project noun is divided into the following noun parts:
  • Description part
  • Material part
  • Tool part
  • Instruction part
  • Collection part
  • Project part, which includes all other noun contents
The ProjectCollection noun is divided into the following noun parts:
  • Description part
  • ProjectCollection part, which includes all other noun contents

In this lesson, you import the following mediators:

Project noun:
ReadProjectDescriptionPartMediator
Builds the Description part of the Project noun.
ReadProjectMaterialPartMediator
Builds the Material part of the Project noun.
ReadProjectToolPartMediator
Builds the tool part of the Project noun.
ReadProjectInstructionPartMediator
Builds the Instruction part of the Project noun.
ReadProjectCollectionRelPartMediator
Builds the Collection part of the Project noun.
ReadProjectMediator
Builds the remainder of the Project noun.
ChangeProjectDescriptionPartMediator
Updates the physical SDOs with the Description part of the Project noun.
ChangeProjectMaterialPartMediator
Updates the physical SDOs with the Material part of the Project noun.
ChangeProjectToolPartMediator
Updates the physical SDOs with the tool part of the Project noun.
ChangeProjectInstructionPartMediator
Updates the physical SDOs with the Instruction part of the Project noun.
ChangeProjectCollectionRelPartMediator
Updates the physical SDOs with the Collection part of the Project noun.
ChangeProjectBasePartMediator
Updates the physical SDOs with the remainder of the Project noun.
ChangeProjectMediator
Creates and deletes the Project noun.
ProjectCollection noun:
ReadProjectCollectionDescriptionPartMediator
Builds the Description part of the ProjectCollection noun.
ReadProjectCollectionMediator
Builds the remainder of the ProjectCollection noun.
ChangeProjectCollectionDescriptionPartMediator
Updates the physical SDOs with the Description part of the ProjectCollection noun.
ChangeProjectCollectionBasePartMediator
Updates the physical SDOs with the remainder of the ProjectCollection noun.
ChangeProjectCollectionMediator
Creates and deletes the ProjectCollection noun.
Read mediators are responsible for constructing a logical noun from the physical SDOs that represents the corresponding entry in the database. Each read mediator contains a buildNoun method (or buildNounPart) that has two parameters:
Object aLogicalEntityType
The logical noun (or noun part) to build.
Object aPhysicalEntityType
The physical SDO containing the unique ID of the noun.
Change mediators are responsible for modifying the physical SDOs based on input that is contained in a logical SDO. The following methods are the primary methods of a change mediator:
validateCreate, validateChange, validateDelete
These methods are used to determine whether an action can proceed. For example, a validateChange method always checks if the noun to change currently exists in the database.
create, update, delete
These methods set the values of the logical noun into the physical SDOs representing the database tables.
getNounPartXPaths
This method returns the noun part that this mediator operates on, for example, /Description.
The WC_eardir\xml\config\com.mycompany.commerce.project\wc-component.xml file defines the following data service configuration:
<_config:dataservice dataMediatorType="JDBC" metadataClass="com.mycompany.commerce.project.facade.server.metadata.ProjectMetadata"> </_config:dataservice>
The ProjectMetadata class provides configuration information for the Data Service Layer.

Complete the following steps to import the mediators.

Procedure

  1. Import the ProjectMetadata.java file:
    1. Expand Project-Server/ejbModule.
    2. Right-click com.mycompany.commerce.project.facade.server.metadata; click Import.
    3. Expand General; select File System, then click Next.
    4. Browse to the temporary location where you extracted the RecipeServices.zip file.
    5. Browse to the com.mycompany.commerce.project.facade.server.metadata folder; select the folder, then click Ok.
    6. Select ProjectMetadata.java; click Finish.
    7. Click Yes to overwrite any existing file.
  2. Import the com.mycompany.commerce.project.facade.server.services.dataaccess.bom.mediator package:
    1. Expand Project-Server/ejbModule.
    2. Right-click com.mycompany.commerce.project.facade.server.services.dataaccess.bom.mediator; click Import.
    3. Expand General; select File System, then click Next.
    4. Browse to the temporary location where you extracted the RecipeServices.zip file.
    5. Browse to the com.mycompany.commerce.project.facade.server.services.dataaccess.bom.mediator folder; select the folder, then click Ok.
    6. Select all the files in the mediator folder; click Finish.
    7. Click Yes to All to overwrite any existing files.
  3. Import the com.mycompany.commerce.project.facade.server.helpers package:
    1. Right-click the Project-Server project.
    2. Click New > Package
    3. Type com.mycompany.commerce.project.facade.server.helpers in the name field. Click Finish.

      Screen capture that displays how to import the com.mycompany.commerce.project.facade.server.helpers package.
    4. Right-click the com.mycompany.commerce.project.facade.server.helpers folder and click Import.
    5. Expand General; select File System, then click Next.
    6. Browse to the temporary location where you extracted the RecipeServices.zip file.
    7. Browse to the com.mycompany.commerce.project.facade.server.helpers folder; select the folder, then click Ok.
    8. Select the ProjectComponentHelper.java file; click Finish.
    9. Click Yes to overwrite any existing files.

Results