Example: Inserting and replacing price rule

Use the Data Load utility to load price rule data into the PRICERULE table. The Data Load utility provides two modes for loading price rule: insert and replace. Use the insert modes for a new price rule. Use the replace mode to update an existing price rule.

Do not use the insert mode if a price rule with the same price rule name, or if a uniqueId exists in database. In insert mode, if a price rule with the same price rule name or uniqueId exists in database, the record is not inserted. In the replace mode, if the price rule name or the uniqueId in the load file does not exist in database, the price rule is inserted.

This example uses a CSV file to demonstrate how to insert, replace, or delete your data. We can also create and use an XML formatted file to insert, replace, or delete your data. If you choose to create and use an XML formatted file, ensure that your XML elements use the same names as are used for CSV column names.


Prerequisites

Before you run this example, ensure that the following prerequisites are fulfilled:


CSV file with sample price rule data

In this example, the data source is a CSV file named PriceRule.csv. The file contains sample price rule data. Each column is delimited by a comma.

Formatted CSV file with column headings
Name Description State Dependency Format
PriceRule001 This price rule is just for UT 1 TRUE 1
PriceRule002 This price rule is just for UT 0 FALSE 0


CSV column and XML element definitions

The column order is defined in the price rule data load configuration file. See the number attribute in the <_config:Data> element.

Other optional fields not included in the example are:


Business context data

The following code snippet from the wc-dataload-env.xml configuration file provides the business context data necessary for loading the price rule data:


Mapping data

The following snippet from the sample configuration file demonstrates how to map each column of data in the source CSV file to a value.

The following snippet from the sample configuration file demonstrates how to map each column of the data in the CSV file to a business object logical schema path. The attribute 'value' represents the name of a column of the CSV file, which is defined in the preceding configuration snippet. Each column in the CSV file must have a mapping to the logical schema path. If the optional fields are present in the CSV file, the mapping for them must be added.


Business object mediator

The mediator class name is com.ibm.commerce.price.dataload.mediator.PriceRuleMediator. The corresponding logical schema is defined in PriceRule.xsd.

Note: When we use a mediator that is provided with WebSphere Commerce with the Data Load utility, the utility assumes that we are loading data for all columns for a business object. To update the data in only specific columns, configure a column exclusion list for the load process. A column exclusion list causes the Data Load utility to ignore specific columns during the load operation. If you do not use a column exclusion list, the utility updates all columns in the row of a database table row when the utility updates the row. If no value is set in the input file, the utility can replace the existing column value with a default value or set the value to be null. See Configure a column exclusion list.