WCS | Dataload Utility | Writing Custom Dataload

If you wanted to do standard Catalog Dataload using Dataload utility in WebSphere Commerce and your input sources are not CSV or XML files then you need to go with custom dataload. WebSphere Commerce dataload supports only CSV or XML file approaches and if your input source is a property file or a ResultSet or something else, you need to write custom dataload to read source file/application and a mediator to push it to WebSphere Commerce Database.

Here are the steps required for custom dataload:

Reader:
1. Write your Data Reader class (Eg: com.samples.dataload.reader.CatentryExtnReader, which you might need to extended functionality of OOB CatalogEntryDataReader - It might read the input from some other database tables related to SAP), which extends com.ibm.commerce.foundation.dataload.datareader.AbstractDataReader
2. Override the following methods,
    a. init() - You can do initialization of resources like connecting to source database/application/property files, preparing the required resources etc.
    b. next() - This method holds actual business logic. Here you have to loop through all the records, which has been fetched from source. Prepare BOD Object for each record, set it to DataLoadBusinessObject and returns the same. This method returns one chunk of data read from a data source.
    c. close() - Closing of opened resources like JDBC/Application connections can be handled in this method.

Mediator:
If your target tables are standard Catalog tables, then you can use OOB mediators itself and no need to write explicit mediators. Most of the times, the existing OOB Mediators should be enough for pushing data to DB. In the next post, I am going explain what are all the mediators you need to use for different dataloads. If you feel the existing mediator should be overridden to have additional functionality/checks then you can go ahead with the custom mediator.
1. Write the Mediator class (Eg: com.samples.dataload.mediator.CatentryExtnMediator, which pushes the information WebSphere Commerce dataload) which extends com.ibm.commerce.foundation.dataload.businessobjectmediator.AbstractBusinessObjectMediator
2. Override the following methods,
    a. transform() - It transforms the custom business objects into a list of physical objects using the TableDataObject class. Write populate methods to load the data to your custom tables and call them from transform method
   
Update the following files to have your Reader & Mediators instead of OOB Readers & Mediators,
wc-loader-catalog-entry.xml:
<_config:DataloadBusinessObjectConfiguration
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.ibm.com/xmlns/prod/commerce/foundation/config xsd/wc-dataload-businessobject.xsd"
    xmlns:_config="http://www.ibm.com/xmlns/prod/commerce/foundation/config">
  <_config:DataLoader className="com.ibm.commerce.foundation.dataload.BusinessObjectLoader">
     <_config:DataReader className="com.samples.dataload.reader.CatentryExtnReader" />
       <_config:BusinessObjectBuilder className="" >   
       <_config:BusinessObjectMediator className="com.samples.dataload.mediator.CatentryExtnMediator" componentId="com.ibm.commerce.catalog"/>      
    </_config:BusinessObjectBuilder>
  </_config:DataLoader>
</_config:DataloadBusinessObjectConfiguration>

2 comments:

  1. very useful concept without CSV or XML for Custom DataLoad Utility...
    keep it up ...Sir.

    ReplyDelete
  2. Your post is really collection of such useful information and I personally would like to appreciate the efforts. Once again thanks for your post.

    ReplyDelete

My Writings........

HCL Commerce v9.1 | Local Store Vs Remote Store

  Local Store Remote Store Project Type Migrated (Lift & Shift) - Newly Imp...