Tutorials > Management Center > Create the Project BOD service module

< Previous | Next >


Implement Business Object Mediators to transform logical SDOs 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.

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. IBM recommends to use one mediator for each complex element in the noun, excluding any user data elements.

Breaking up the nouns into noun parts is a design decision based on the 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:

The ProjectCollection noun is divided into the following noun parts:

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 contained in a logical SDO. The primary methods of a change mediator are the following:

validateCreate, validateChange, validateDelete

These methods are used to determine if 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_EAR\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 the com.mycompany.commerce.project.facade.server.metadata package and click Import. Expand General and select File System.

    3. Click Next.

    4. Browse to the temporary location where you unzipped RecipeServices.zip. Browse to the com.mycompany.commerce.project.facade.server.metadata folder.

    5. Select ProjectMetadata.java in the folder.

    6. Click Finish. 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 the com.mycompany.commerce.project.facade.server.services.dataaccess.bom.mediator package.

    3. Click Import. Expand General and select File System.

    4. Click Next.

    5. Browse to the temporary location where you unzipped RecipeServices.zip. Browse to the com.mycompany.commerce.project.facade.server.services.dataaccess.bom.mediator folder.

    6. Select all files in the mediator folder.

    7. Click Finish. 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.

    4. Right-click the com.mycompany.commerce.project.facade.server.helpers package.

    5. Click Import. Expand General and select File System.

    6. Browse to the temporary location where you unzipped RecipeServices.zip. Browse to the com.mycompany.commerce.project.facade.server.helpers folder.

    7. Select the ProjectComponentHelper.java file in the folder.

    8. Click Finish.

< Previous | Next >


+

Search Tips   |   Advanced Search