Tutorials > Program model > Web services > Create a new WebSphere Commerce BOD service module
Configure the data service layer for the TutorialStore service module
In this lesson we will configure the data service layer for the TutorialStore service module.
The next steps for the customization of the new service module are:
- Define two query templates
- wc-query-BODTutorialStore-get.tpl: A query template file mapping each get request XPath statement and access profile to a SQL template query.
- wc-query-BODTutorialStore-update.tpl: A query template file mapping each change request XPath statement to a SQL template query.
- Define the logical to physical SDO mapping
- Defines the wc-business-object-mediator.xml file to relate logical nouns to physical data objects.
- Update the TutorialStore service configuration (wc-component.xml) to
- Use the DSL value-mapping to map between internal database codes and external logical values.
The wc-query-TutorialStore-get.tpl file defines the query templates used to fetch the physical data objects. This template file defines the following symbols:
- STOREENT
- To represent all columns of the STOREENT table.
- STORE
- To represent all columns of the STORE table.
- STORE_SUMMARY
- To represent specific columns of the store table used for the Summary access profile. Note that the OPTCOUNTER column should always be included to enable optimistic concurrency control.
- STOREENTDS
- To represent all columns of the STOREENTDS table.
- STORELANG
- To represent all columns of the STORELANG table.
COLS:STOREENT=STOREENT:* COLS:STORE=STORE:* COLS:STORE_SUMMARY=STORE:STORE_ID,STATUS,DIRECTORY,STORETYPE,OPTCOUNTER COLS:STOREENTDS=STOREENTDS:* COLS:STORELANG=STORELANG:*
The following query example query:
- Relates the XPath key "/BODTutorialStore[StoreIdentifier[(UniqueID=)]]" and access profile "MyCompany_Details" to the listed SQL template.
- Uses the data language values of the request in the from clause STOREENTDS.LANGUAGE_ID in ($CONTROL:LANGUAGES$). The value of the ($CONTROL:LANGUAGES$) parameter is passed in along with a request. This substitution allows parameters a request to support multiple languages.
- The where clause uses the value specified by the XPath statement STOREENT.STOREENT_ID = ?UniqueID?. If the XPath statement was /TutorialStore[StoreIdentifier[(UniqueID="123")]], the where clause would be STOREENT.STOREENT_ID = "123".
BEGIN_XPATH_TO_SQL_STATEMENT <!-- FindByStoreId --> name=/BODTutorialStore[StoreIdentifier[(UniqueID=)]]+MyCompany_Details base_table=STOREENT sql= SELECT STOREENT.$COLS:STOREENT$, STORE.$COLS:STORE$, STOREENTDS.$COLS:STOREENTDS$, STORELANG.$COLS:STORELANG$ FROM STOREENT JOIN STORE ON (STORE.STORE_ID = STOREENT.STOREENT_ID) LEFT OUTER JOIN STOREENTDS ON (STOREENTDS.STOREENT_ID = STOREENT.STOREENT_ID AND STOREENTDS.LANGUAGE_ID in ($CONTROL:LANGUAGES$)) JOIN STORELANG ON (STORELANG.STOREENT_ID = STOREENT.STOREENT_ID) WHERE STOREENT.STOREENT_ID = ?UniqueID? END_XPATH_TO_SQL_STATEMENT
The following query example query:
- Relates the XPath key "/BODTutorialStore[StoreIdentifier[(UniqueID=)]]" and access profile "MyCompany_Summary" to the listed SQL template. Each XPath key and access profile pairing must be unique, one XPath key could have many different access profiles and each access profile could apply to many different XPath keys.
- Selects from STORE.$COLS:STORE_SUMMARY$ instead of STORE.$COLS:STORE$. This query selects a subset of the STORE table as the MyCompany_Summary access profile returns different data then the MyCompany_Details access profile.
- Does not include the STOREENTDS or STORELANG tables in the from clause as the MyCompany_Summary access profile returns different data then the MyCompany_Details access profile.
BEGIN_XPATH_TO_SQL_STATEMENT <!-- FindByStoreId --> name=/BODTutorialStore[StoreIdentifier[(UniqueID=)]]+MyCompany_Summary base_table=STOREENT sql= SELECT STOREENT.$COLS:STOREENT$, STORE.$COLS:STORE_SUMMARY$ FROM STOREENT JOIN STORE ON (STORE.STORE_ID = STOREENT.STOREENT_ID) WHERE STOREENT.STOREENT_ID = ?UniqueID? END_XPATH_TO_SQL_STATEMENT
The following diagram shows configuration of the data service layer in the overall customization process:
Procedure
- Import the TutorialStore query template files:
- In the Enterprise Explorer view, right-click the WC\xml\config\com.mycompany.commerce.bodtutorialstore folder.
- Select Import > FileSystem Click Next.
- Browse to the temporary location where you unzipped TutorialStore.zip.
- Browse to the xml\config\com.mycompany.commerce.bodtutorialstore folder.
- Select wc-query-BODTutorialStore-get.tpl and wc-query-BODTutorialStore-update.tpl.
- Click Finish. Click Yes to All to overwrite any existing files.
- Next, we will define the logical to physical mapping in the wc-business-object-mediator.xml file. This files relates a logical type (noun) to the physical type (physical SDO) that contains its unique ID. For example, the following relates the TutorialStore noun to the STOREENT table physical SDO:
<object logicalType="com.mycompany.commerce.bodtutorialstore.facade.datatypes.TutorialStoreType" physicalType="com.mycompany.commerce.bodtutorialstore.facade.server.entity.datatypes.Storeent">To define the logical to physical mapping:
- In the project-explorer, open WC\xml\config\com.mycompany.commerce.bodtutorialstore\wc-business-object-mediator.xml.
- Replace the sample file with the following:
<?xml version="1.0" encoding="UTF-8"?> <_config:BusinessObjectMediatorConfiguration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.ibm.com/xmlns/prod/commerce/foundation/config ../xsd/wc-business-object-mediator.xsd" xmlns:_config="http://www.ibm.com/xmlns/prod/commerce/foundation/config"> <_config:object logicalType="com.mycompany.commerce.bodtutorialstore.facade.datatypes.TutorialStoreType" physicalType="com.mycompany.commerce.bodtutorialstore.facade.server.entity.datatypes.Storeent"> <_config:mediator interfaceName="com.ibm.commerce.foundation.server.services.dataaccess.bom.mediator.ReadBusinessObjectMediator" className="com.mycompany.commerce.bodtutorialstore.facade.server.services.dataaccess.bom.mediator.ReadTutorialStoreMediator"> <_config:part-mediator interfaceName="com.ibm.commerce.foundation.server.services.dataaccess.bom.mediator.ReadBusinessObjectPartMediator"> <_config:part-mediator-implementation className="com.mycompany.commerce.bodtutorialstore.facade.server.services.dataaccess.bom.mediator.ReadTutorialStoreDescriptionMediator"/> <_config:part-mediator-implementation className="com.mycompany.commerce.bodtutorialstore.facade.server.services.dataaccess.bom.mediator.ReadTutorialStoreSupportedLanguagesMediator"/> <_config:part-mediator-implementation className="com.mycompany.commerce.bodtutorialstore.facade.server.services.dataaccess.bom.mediator.ReadTutorialStoreSupportedCurrenciesMediator"/> </_config:part-mediator> </_config:mediator> <_config:mediator interfaceName="com.ibm.commerce.foundation.server.services.dataaccess.bom.mediator.ChangeBusinessObjectMediator" className="com.mycompany.commerce.bodtutorialstore.facade.server.services.dataaccess.bom.mediator.ChangeTutorialStoreMediator"> <_config:part-mediator interfaceName="com.ibm.commerce.foundation.server.services.dataaccess.bom.mediator.ChangeBusinessObjectPartMediator"> <_config:part-mediator-implementation className="com.mycompany.commerce.bodtutorialstore.facade.server.services.dataaccess.bom.mediator.ChangeTutorialStoreDescriptionMediator"/> <_config:part-mediator-implementation className="com.mycompany.commerce.bodtutorialstore.facade.server.services.dataaccess.bom.mediator.ChangeTutorialStoreBasePartMediator"/> </_config:part-mediator> </_config:mediator> </_config:object> </_config:BusinessObjectMediatorConfiguration>
- The Data Service Layer provides a customization point to map between internal database codes and external logical values. The <_config:valuemappingservice> element is a customization point within the service module's wc-component.xml file that allows you to configure this conversion. WebSphere Commerce uses 1 to represent an open store, 0 for a closed store, and -1 for a suspended store. This step will configure the Data Service Layer to handle this conversion.
- Open WC\xml\config\com.mycompany.commerce.bodtutorialstore\wc-component.xml.
- Copy and paste the following inside the <_config:valuemappingservice> element:
<_config:valuemapping externalName="StoreStateFormat" internalName="StoreStateFormat"> <_config:valuemap externalValue="Open" internalValue="1"/> <_config:valuemap externalValue="Closed" internalValue="0"/> <_config:valuemap externalValue="Suspended" internalValue="-1"/> </_config:valuemapping>
- Save the file (Ctrl + S).
- Organize the imports for the BODTutorialStore-Server project to resolve any errors reported by WebSphere Commerce Developer:
- Open the Java perspective in WebSphere Commerce Developer.
- Right-click the BODTutorialStore-Server\EJBModule folder and select Source.
- Select Organize Imports.
- Save the file.