Tutorials > Program model > Web services > Create a new WebSphere Commerce 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.

Mediators are needed for each changeable noun part. A noun part is either a part of a noun, or by definition, can be a noun itself.

To simplify development and maintenance of mediator, 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. For this tutorial, the TutorialStore noun is divided into the following noun parts:

In this lesson you import the following mediators:

Change mediators for the SupportedLanguages and SupportedCurrencies parts are not implemented as this tutorial does not provide any services for modifying the SupportedLanguages or SupportedCurrencies of a store.

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:

The following buildNoun method is from the ReadTutorialStoreMediator:

public void buildNoun(Object aLogicalEntityType, Object aPhysicalEntityType) throws AbstractApplicationException 
{
    // The noun to build.
    TutorialStoreType store = (TutorialStoreType) aLogicalEntityType;
    // The physical SDO containing the stores unique ID (STOREENT.STOREENT_ID).
    Storeent aPhysicalStoreEntity = (Storeent) aPhysicalEntityType;
  // Get the physical SDO for the STORE table, to be used to populate data.
    Store aPhysicalStore = (Store) aPhysicalStoreEntity.getStoreFORStoreent();
        
    // Create and populate the store identifier type.
    StoreIdentifierType storeIdentifier = getCommerceFoundationFactory().createStoreIdentifierType();
    storeIdentifier.setUniqueID(Integer.toString(aPhysicalStoreEntity.getStoreent_id()));
    StoreExternalIdentifierType storeExternalIdentifier = getCommerceFoundationFactory().createStoreExternalIdentifierType();
    storeExternalIdentifier.setNameIdentifier(aPhysicalStoreEntity.getIdentifier());
    storeIdentifier.setExternalIdentifier(storeExternalIdentifier);
    store.setStoreIdentifier(storeIdentifier);
        
    // Populate the store path and store category from the Store physical SDO.
    store.setStorePath(aPhysicalStore.getDirectory());
    store.setStoreCategory(StoreCategoryType.get(aPhysicalStore.getStoretype()));
        
    // Use helper methods to populate the remaining areas of the TutorialStore noun.
    buildInventorySystem(store, aPhysicalStore);
    buildStoreState(store, aPhysicalStore);
    buildUserData(store, aPhysicalStoreEntity);
}

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:

The following diagram shows how the business object mediators fit into the overall customization process:

To import the mediators:


Procedure

  1. The WC_EAR\xml\config\com.mycompany.commerce.bodtutorialstore\wc-component.xml file defines the following data service configuration:

    <_config:dataservice 
                dataMediatorType="JDBC" 
                metadataClass="com.mycompany.commerce.bodtutorialstore.facade.server.metadata.BODTutorialStoreMetadata">
    </_config:dataservice> 
    

    The BODTutorialStoreMetadata class provides configuration information for the Data Service Layer.

    To update the BODTutorialStore-Server data service configuration:

    1. Open the BODTutorialStoreMetadata class.

    2. Implement the getRootEClass() method to return the Root physical SDO object. Replace the body of the getRootEClass() method with the following:

      return BODTutorialStoreEntityPackage.eINSTANCE.getBODTutorialStoreRoot();
      

    3. Add the STORE_STATE_ENUMERATION constant used for the value-mapping service. Add the following constant to the BODTutorialStoreMetadata class:

      public static final String STORE_STATE_ENUMERATION = "StoreStateFormat";
      

    4. Save the file.

  2. Import the TutorialStore mediators:

    1. Right-click the com.mycompany.commerce.bodtutorialstore.facade.server.services.dataaccess.bom.mediator package.

    2. Select Import > Filesystem

    3. Click Next.

    4. Browse to the temporary location where you unzipped TutorialStore.zip.

    5. Select the following files:

      • ReadTutorialStoreDescriptionMediator.java

      • ReadTutorialStoreSupportedLanguagesMediator.java

      • ReadTutorialStoreSupportedCurrenciesMediator.java

      • ReadTutorialStoreMediator.java

      • ChangeTutorialStoreMediator.java

      • ChangeTutorialStoreBasePartMediator.java

      • ChangeTutorialStoreDescriptionMediator.java

    6. Click Finish. Click Yes to All to overwrite any existing files.

  3. Organize the imports for the BODTutorialStore-Server project:

    1. Open the Java perspective in WebSphere Commerce Developer.

    2. Right-click the BODTutorialStore-Server\ejbModule folder and select Source.

    3. Select Organize Imports.

< Previous | Next >


+

Search Tips   |   Advanced Search