Related to ISSUE-42736: Code Review Changes:
authorDavid Miguelez <david.miguelez@openbravo.com>
Thu, 16 Jan 2020 16:24:48 +0100
changeset 36929 29e254d4f560
parent 36928 82e1d231e16b
child 36930 e4c208a269ae
Related to ISSUE 42736: Code Review Changes:

* Simplified expression to generate the query object
* Use id's instead of objects in the query
* Changed names to be more descriptive
src/org/openbravo/materialmgmt/VariantChDescUpdateProcess.java
--- a/src/org/openbravo/materialmgmt/VariantChDescUpdateProcess.java	Mon Jan 13 14:43:32 2020 +0530
+++ b/src/org/openbravo/materialmgmt/VariantChDescUpdateProcess.java	Thu Jan 16 16:24:48 2020 +0100
@@ -106,12 +106,13 @@
              + "              where chv.characteristicValue.id = :chvid) ";
       }
       //@formatter:on
-      OBQuery<Product> productQuery = OBDal.getInstance().createQuery(Product.class, hql);
+      OBQuery<Product> productQuery = OBDal.getInstance()
+          .createQuery(Product.class, hql)
+          .setFilterOnReadableOrganization(false)
+          .setFilterOnActive(false);
       if (StringUtils.isNotBlank(strChValueId)) {
         productQuery.setNamedParameter("chvid", strChValueId);
       }
-      productQuery.setFilterOnReadableOrganization(false);
-      productQuery.setFilterOnActive(false);
 
       ScrollableResults products = productQuery.scroll(ScrollMode.FORWARD_ONLY);
       int i = 0;
@@ -139,14 +140,15 @@
     StringBuilder strChDesc = new StringBuilder();
     //@formatter:off
     String hql = " as pch "
-               + " where pch.product = :product "
+               + " where pch.product.id = :productId "
                + " order by pch.sequenceNumber ";
     //@formatter:on
     OBQuery<ProductCharacteristic> pchQuery = OBDal.getInstance()
-        .createQuery(ProductCharacteristic.class, hql);
-    pchQuery.setFilterOnActive(false);
-    pchQuery.setFilterOnReadableOrganization(false);
-    pchQuery.setNamedParameter("product", product);
+        .createQuery(ProductCharacteristic.class, hql)
+        .setFilterOnActive(false)
+        .setFilterOnReadableOrganization(false)
+        .setNamedParameter("productId", product.getId());
+
     for (ProductCharacteristic pch : pchQuery.list()) {
       if (StringUtils.isNotBlank(strChDesc.toString())) {
         strChDesc.append(", ");
@@ -154,15 +156,16 @@
       strChDesc.append(pch.getCharacteristic().getName() + ":");
       //@formatter:off
       hql = " as pchv "
-          + " where pchv.characteristic.id = :ch "
-          + " and pchv.product.id = :product ";
+          + " where pchv.characteristic.id = :chId "
+          + " and pchv.product.id = :productId ";
       //@formatter:on
       OBQuery<ProductCharacteristicValue> pchvQuery = OBDal.getInstance()
-          .createQuery(ProductCharacteristicValue.class, hql);
-      pchvQuery.setFilterOnActive(false);
-      pchvQuery.setFilterOnReadableOrganization(false);
-      pchvQuery.setNamedParameter("ch", pch.getCharacteristic().getId());
-      pchvQuery.setNamedParameter("product", product.getId());
+          .createQuery(ProductCharacteristicValue.class, hql)
+          .setFilterOnActive(false)
+          .setFilterOnReadableOrganization(false)
+          .setNamedParameter("chId", pch.getCharacteristic().getId())
+          .setNamedParameter("productId", product.getId());
+
       for (ProductCharacteristicValue pchv : pchvQuery.list()) {
         strChDesc.append(" " + pchv.getCharacteristicValue().getName());
       }