Related to ISSUE-43388. Code Review changes:
authorDavid Miguelez <david.miguelez@openbravo.com>
Fri, 06 Mar 2020 14:20:35 +0100
changeset 37152 9466c9337936
parent 37151 2e054b8f16dc
child 37153 345e75647853
Related to ISSUE 43388. Code Review changes:
Retrieve first the query into an object and then do the !list.isEmpty() comparison.
The reason for this change is to make more obvius the list empty comparison
while reading the code.
src/org/openbravo/event/ConversionRateEventHandler.java
--- a/src/org/openbravo/event/ConversionRateEventHandler.java	Tue Mar 03 09:59:55 2020 +0100
+++ b/src/org/openbravo/event/ConversionRateEventHandler.java	Fri Mar 06 14:20:35 2020 +0100
@@ -22,6 +22,7 @@
 
 import javax.enterprise.event.Observes;
 
+import org.hibernate.query.Query;
 import org.openbravo.base.exception.OBException;
 import org.openbravo.base.model.Entity;
 import org.openbravo.base.model.ModelProvider;
@@ -96,7 +97,7 @@
                   "     )";
     //@formatter:on
 
-    return !OBDal.getInstance()
+    final Query<String> query = OBDal.getInstance()
         .getSession()
         .createQuery(hql, String.class)
         .setParameter("currencyConversionRateId", id)
@@ -105,8 +106,8 @@
         .setParameter("currencyToId", currencyTo.getId())
         .setParameter("validFrom", validFrom)
         .setParameter("validTo", validTo)
-        .setMaxResults(1)
-        .list()
-        .isEmpty();
+        .setMaxResults(1);
+
+    return !query.list().isEmpty();
   }
 }