Solr

We all know that we use impex to insert,update and remove the data
You can read Impex basics here Overview Of Impex

Sometime its required for us to update value of few attributes (columns in table) for more than one instance (row in table)

Example :
I want to update the maxOrderQty and minOrderQty of all products

Here, We can do this using traditional way by specifying an each product’s unique code and updating values as below

  1. Insert_update product; code[unique=true];minOrderQty;maxOrderQty
  2. 10001;1;99
  3. 10002;1;99
  4. 10003;1;99
Insert_update product; code[unique=true];minOrderQty;maxOrderQty
10001;1;99
10002;1;99
10003;1;99

In this way we have to specify unique attribute of Product for each instance and this is quiet manageable if we have few products to update.

Let us assume we have to update this to all products in our application

Let’s say volume is around 2000 products.

It’s very difficult to specify all 2000 products in impex to update these 2 attributes.
So, solution to achieve this without specifying all products in impex is Batch Mode.

Batch Mode: It’s a feature within Hybris Impex which allows to update more than one instance of item type.

In other words it allows us to do bulk update
We just need to use [batchmode=true] in the impex header

1. If the batch mode is not specified (as by default), the hybris throws an exception if more than one instance matches for a value line.

2. If the batch mode is enabled, the hybris modifies all instances that matches the value line

Solution to above problem(updating all products) with Batch mode is as below

  1. $productCatalog=powertoolsProductCatalog
  2. $catalogVersion=catalogversion(catalog(id[default=$productCatalog]),version[default='Staged'])[unique=true,default=$productCatalog:Staged]
  3.  
  4. # Language
  5. $lang=en
  6.  
  7. # Update All Products of powertoolsProductCatalog Staged version
  8. UPDATE Product[batchmode=true]; $catalogVersion; minOrderQty ; maxOrderQty
  9. ;;1;99
$productCatalog=powertoolsProductCatalog
$catalogVersion=catalogversion(catalog(id[default=$productCatalog]),version[default='Staged'])[unique=true,default=$productCatalog:Staged]

# Language
$lang=en

# Update All Products of powertoolsProductCatalog Staged version
UPDATE Product[batchmode=true]; $catalogVersion; minOrderQty ; maxOrderQty
;;1;99

In the above example, we specify $catalogVersion as unique column
So all product instances belonging to Staged version of powertoolsProductCatalog will be updated

Example: Update All customers without specifying any unique value

  1. # set all BundleTemplates in approved status
  2. UPDATE Customer[batchmode=true];itemtype(code)[unique=true];emailPreference
  3. ;Customer;true
# set all BundleTemplates in approved status
UPDATE Customer[batchmode=true];itemtype(code)[unique=true];emailPreference
;Customer;true


We can also use Batch mode on Remove operation

Example: If we want to remove all customers
We can use Batchmode with remove as below

  1. REMOVE Customer[ batchmode=true];itemtype (code)[unique=true]
  2. ;Customer
REMOVE Customer[ batchmode=true];itemtype (code)[unique=true]
;Customer


Some more examples


Update with item type as unique column

  1. # set all BundleTemplates in approved status
  2. UPDATE BundleTemplateStatus[batchmode=true];itemtype(code)[unique=true];status(code)
  3. ;BundleTemplateStatus;approved
# set all BundleTemplates in approved status
UPDATE BundleTemplateStatus[batchmode=true];itemtype(code)[unique=true];status(code)
;BundleTemplateStatus;approved


Update with unique column other than item type

  1. $productCatalog=powertoolsProductCatalog
  2. $catalogVersion=catalogversion(catalog(id[default=$productCatalog]),version[default='Staged'])[unique=true,default=$productCatalog:Staged]
  3.  
  4. # Update All Products
  5. UPDATE Product[batchmode=true]; $catalogVersion; unitOfMeasure ; unspcs
  6. ;   ;   C62 ;   23291500
$productCatalog=powertoolsProductCatalog
$catalogVersion=catalogversion(catalog(id[default=$productCatalog]),version[default='Staged'])[unique=true,default=$productCatalog:Staged]

# Update All Products
UPDATE Product[batchmode=true]; $catalogVersion; unitOfMeasure ; unspcs
;	;	C62	;	23291500


Remove with item type as unique column

  1. REMOVE SapB2BDocument[ batchmode=true];itemtype (code)[unique=true]
  2. ;SapB2BDocument
REMOVE SapB2BDocument[ batchmode=true];itemtype (code)[unique=true]
;SapB2BDocument


Remove with unique column other than item type

  1. REMOVE ValidComponentTypesForContentSlots[batchMode=true];target(code)[unique=true]
  2. ;CMSImageComponent
REMOVE ValidComponentTypesForContentSlots[batchMode=true];target(code)[unique=true]
;CMSImageComponent


Note:
We can use item type as one of the unique value in header if we want to update all instances of that type

We can specify unique value in header other than item type if we want to update matching instances for that unique value rather than all instances

Share this article on

Comment (9)

    1. Karibasappa G C (KB)

      First thing, static variables will never be a part of method, it will be a part of class always.

      So only we cant declare any static variables inside a method but we can access them inside a method.

      All static variables will be stored in separate segment inside Heap area only.

      1. The blog is very helpful. Thanks a lot for sharing! Also the “Inheritance in interface” page is not opening. Can you please fix that?

Leave a Comment

  • You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code lang=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre lang="" extra="">

    • Please answer this simple challenge to post your valuable comment *