Merge mode

Last modified by prodexa Admin on 23.02.2021, 15:26

The Merge mode is an element in the CML/Context, that controls how '1 to many'-related objects will be treated in an update command.

The Syntax is as follows:

<CML>
 <Context>
   <MergeModes>
     <String mapKey="com.jcatalog.product.Product.contractedProducts">insert-update-delete</String>
   </MergeModes>
 </Context>

 <Command> ....
 </Command>
</CML>

MergeModes is in fact a map structure that uses classname[.collectionPropertyName] as key and the desired merge mode as value.
 When collectionPropertyName is ommitted in the key, the merge mode value is applied to all collections of the specified class.
 The fallback default merge mode for all collections is insert-update.

The following merge modes are valid:

  • full-replace = insert-replace-delete (all existing replaced, all deleted,
     all new inserted).
     Delete all collections items in database and insert
     all collection items from CML as new
  • insert-update (new items inserted, existing items updated)
     Update all existing in CML and database simultaneously. Insert existing in CML but not existing in database. All other items which exist in database but do not exist in
     CML are stayed as are
  • insert-replace (all existing replaced, all new inserted).
     Delete all existing in CML and database simultaneously and insert them as new items.
     Existing in CML but not existing in database are inserted too. All other items which exist in database but do not exist in CML are stayed as are.
  • replace-delete (all existing replaced, all missing deleted).
     All that exist in database but not in CML are simply deleted All that exist in database and in CML are replaced. So far it is same as full-replace. But in contrast to full-replace, objects that exist in CML but not in database will NOT be inserted
  • update-delete (existing items updated, missing items deleted).
     Delete objects in remove-objects from database Update objects in update-replace-objects set with new Version from CML recursively. Objects in CML but not in database will not be inserted!
  • insert-delete (new items inserted, missing items deleted).
     Insert existing in CML but not existing in database. Delete existing in database but not existing in CML. All other items which exist in database and exist in CML simultaneously are stayed as are.
  • insert (new items inserted).
     Insert all existing in CML but not existing in database as new items.
  • delete (missing items deleted).
     This means delete items from database that are not in CML collection. But generally this is a merge operation, it works different than delete command! Think of it as updating a collection with mergeMode a rule for modification during update. insert, delete, update and replace tokens in the command modes are just rules for treatment of objects in a certain state, one of not existing any more in CML not existing yet in datbase, new version in CML respectively
  • update (all existing updated).<p>Update all existing in CML and database simultaneously with new value from CML. Objects from update-replace-objects are updated without exception, all others are NOT updated.
  • replace (existing items replaced).
     Delete all existing in CML and database simultaneously and insert them as new items. Replace will only be performed on objects from update-replace-objects set, so all of them will just be replaced without exception.
  • insert-update-delete (new items inserted, existing updated, missing items deleted).
     Difference to update-delete is that in update-delete objects from new-objects set will not be inserted but for
     insert-update-delete they will be inserted
Use Carefullyerror

Merge Modes refer to all data, without restriction to data in CML. Example:

<MergeModes>
 <String mapKey="com.jcatalog.product.Product.classificationGroupAssociations">full-replace</String>
</MergeModes>

This will remove all ClassificationGroupAssociations of the Product - incl. those from Classification Basis - and put in only the Associations defined in CML.

Merge key (from PIM 6.1.3)

For one-to-many object relations, the Unique key of the related object is used for grouping. This is not desireable always, so an explicit override is possible.
 The merge key, that will be used for grouping instead of true unique key can be specified using nested property syntax as used in apache-commons beanutils.

Use case

The customer wants to import a classificationGroup assignment update for a catalog.
 For example the group assignments of products in catalog 'Hardware' should be updated for eClass.

By the import only the old assignments to eClass should be updated/replaced by the new eClass assignments.
 All other assignments (i.e. to basic classification) should be left untouched.

The collection item grouping by unique keys is not desired for this use case, since it will group Product2ClassificationGroup by ClassificationGroup, not Classification.

<Context>
   <MergeModes>
     <String mapKey="com.jcatalog.product.Product.classificationGroupAssociations">update</String>
   </MergeModes>
   <MergeKeys>
     <string-array mapKey="com.jcatalog.product.Product.classificationGroupAssociations">
       <string>classificationGroup.classification</string>
     </string-array>
   </MergeKeys>
 </Context>
Merge key restrictions

Merge key only takes effect in conjunction with merge mode "update".

Tags: