fixes BUG-42816:Applied new HQL Style
authorIñigo Lerga <inigo.lerga@openbravo.com>
Tue, 14 Jan 2020 10:03:49 +0100
changeset 36956 8e967c22d483
parent 36955 d98e412837b0
child 36957 95c3147aa768
fixes BUG 42816:Applied new HQL Style
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_BankStatementProcess.java
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_BankStatementProcess.java	Fri Jan 17 14:17:35 2020 +0100
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_BankStatementProcess.java	Tue Jan 14 10:03:49 2020 +0100
@@ -11,7 +11,7 @@
  * under the License.
  * The Original Code is Openbravo ERP.
  * The Initial Developer of the Original Code is Openbravo SLU
- * All portions are Copyright (C) 2018 Openbravo SLU
+ * All portions are Copyright (C) 2018-2020 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  *************************************************************************
@@ -20,9 +20,7 @@
 package org.openbravo.advpaymentmngt.process;
 
 import java.util.Date;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
@@ -34,7 +32,6 @@
 import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.service.OBCriteria;
 import org.openbravo.dal.service.OBDal;
-import org.openbravo.dal.service.OBQuery;
 import org.openbravo.database.ConnectionProvider;
 import org.openbravo.erpCommon.utility.OBError;
 import org.openbravo.erpCommon.utility.Utility;
@@ -166,24 +163,22 @@
 
   private Date getMaxBSLDate(FIN_BankStatement bankstatement) {
     // Get last transaction date from previous bank statements
-    final StringBuilder whereClause = new StringBuilder();
-    Map<String, Object> parameters = new HashMap<>(2);
-    whereClause.append(" as bsl ");
-    whereClause.append(" where bsl.");
-    whereClause.append(FIN_BankStatementLine.PROPERTY_BANKSTATEMENT);
-    whereClause.append("." + FIN_BankStatement.PROPERTY_ACCOUNT + " = :account");
-    parameters.put("account", bankstatement.getAccount());
-    whereClause
-        .append(" and bsl." + FIN_BankStatementLine.PROPERTY_BANKSTATEMENT + " <> :bankStatement");
-    parameters.put("bankStatement", bankstatement);
-    whereClause.append(" and bsl.bankStatement.processed = 'Y'");
-    whereClause.append(" order by bsl." + FIN_BankStatementLine.PROPERTY_TRANSACTIONDATE);
-    whereClause.append(" desc");
+    //@formatter:off
+    final String hql =
+                  "as bsl " +
+                  " where bsl.bankStatement.account = :account" +
+                  "   and bsl.bankStatement <> :bankStatement" +
+                  "   and bsl.bankStatement.processed = 'Y'" +
+                  " order by bsl.transactionDate desc";
+    //@formatter:on
 
-    final OBQuery<FIN_BankStatementLine> obData = OBDal.getInstance()
-        .createQuery(FIN_BankStatementLine.class, whereClause.toString(), parameters);
-    obData.setMaxResult(1);
-    FIN_BankStatementLine line = obData.uniqueResult();
+    FIN_BankStatementLine line = OBDal.getInstance()
+        .createQuery(FIN_BankStatementLine.class, hql)
+        .setNamedParameter("account", bankstatement.getAccount())
+        .setNamedParameter("bankStatement", bankstatement)
+        .setMaxResult(1)
+        .uniqueResult();
+
     if (line != null) {
       return line.getTransactionDate();
     }