details:   /erp/devel/pi/rev/80a7075c7784
changeset: 10816:80a7075c7784
user:      Adrián Romero <adrianromero <at> openbravo.com>
date:      Mon Feb 21 16:59:34 2011 +0100
summary:   Fixes issue 0016001: error in add payment process when there are 
more than 1000 financial accounts
It has been splitted the long IN expresion in several IN expressions joined by 
OR to not go over 1000 values inside the IN expression

diffstat:

 
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/dao/AdvPaymentMngtDao.java
 |  52 ++++++++-
 1 files changed, 45 insertions(+), 7 deletions(-)

diffs (76 lines):

diff -r 95270558f5be -r 80a7075c7784 
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/dao/AdvPaymentMngtDao.java
--- 
a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/dao/AdvPaymentMngtDao.java
  Mon Feb 21 15:23:15 2011 +0100
+++ 
b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/dao/AdvPaymentMngtDao.java
  Mon Feb 21 16:59:34 2011 +0100
@@ -24,6 +24,7 @@
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
+import org.hibernate.criterion.Criterion;
 
 import org.hibernate.criterion.Expression;
 import org.hibernate.criterion.Restrictions;
@@ -934,20 +935,57 @@
           Currency.class, strCurrencyId)));
     }
 
-    List<String> finAccs = new ArrayList<String>();
     if (strPaymentMethodId != null && !strPaymentMethodId.isEmpty()) {
-      for (FinAccPaymentMethod finAccPayMethod : 
getObject(FIN_PaymentMethod.class,
-          strPaymentMethodId).getFinancialMgmtFinAccPaymentMethodList()) {
-        finAccs.add(finAccPayMethod.getAccount().getId());
-      }
-      if (finAccs.isEmpty()) {
+      List<FinAccPaymentMethod> finAccsMethods = 
getObject(FIN_PaymentMethod.class,
+          strPaymentMethodId).getFinancialMgmtFinAccPaymentMethodList();
+
+      if (finAccsMethods.isEmpty()) {
         return (new ArrayList<FIN_FinancialAccount>());
       }
-      obc.add(Expression.in("id", finAccs));
+      ExpressionForFinAccPayMethod exp = new ExpressionForFinAccPayMethod();
+
+      for (FinAccPaymentMethod finAccPayMethod : finAccsMethods) {
+        exp.addFinAccPaymentMethod(finAccPayMethod);
+      }
+
+      obc.add(exp.getCriterion()); // compoundexp will be always != null 
because
+                                   // finAccsMethods.isEmpty() == false
     }
     return obc.list();
   }
 
+  private static class ExpressionForFinAccPayMethod {
+
+    private int MAX = 999;
+
+    private Criterion compoundexp = null;
+    List<String> finAccs = new ArrayList<String>();
+
+    public void addFinAccPaymentMethod(FinAccPaymentMethod finAccPayMethod) {
+      finAccs.add(finAccPayMethod.getAccount().getId());
+      if (finAccs.size() >= MAX) {
+        refresh();
+      }
+    }
+
+    public Criterion getCriterion() {
+      if (finAccs.size() > 0) {
+        refresh();
+      }
+      return compoundexp;
+    }
+
+    private void refresh() {
+      // finAccs.size() must be > 0
+      if (compoundexp == null) {
+        compoundexp = Expression.in("id", finAccs);
+      } else {
+        compoundexp = Expression.or(compoundexp, Expression.in("id", finAccs));
+      }
+      finAccs = new ArrayList<String>();
+    }
+  }
+
   public FinAccPaymentMethod 
getFinancialAccountPaymentMethod(FIN_FinancialAccount account,
       FIN_PaymentMethod paymentMethod) {
     final OBCriteria<FinAccPaymentMethod> obc = 
OBDal.getInstance().createCriteria(

------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to