Related to issue 29110: Added a clear inside the loop
authorAlvaro Ferraz <alvaro.ferraz@openbravo.com>
Wed, 11 Mar 2015 13:23:31 +0100
changeset 26165 ac9670b7bfdd
parent 26164 bb7b3752a14d
child 26166 4f8a4e2f76d2
child 26167 e282c64e6e90
Related to issue 29110: Added a clear inside the loop

Added a clear inside the loop to avoid performance problems
src/org/openbravo/event/GLJournalEventHandler.java
--- a/src/org/openbravo/event/GLJournalEventHandler.java	Wed Mar 11 11:48:22 2015 +0530
+++ b/src/org/openbravo/event/GLJournalEventHandler.java	Wed Mar 11 13:23:31 2015 +0100
@@ -60,6 +60,7 @@
       ScrollableResults scrollLines = gljournallineCriteria.scroll(ScrollMode.FORWARD_ONLY);
       if (gljournallineCriteria.count() > 0) {
         try {
+          int i = 0;
           while (scrollLines.next()) {
             final GLJournalLine journalLine = (GLJournalLine) scrollLines.get()[0];
             if (!glj.getCurrency().getId().equals(journalLine.getCurrency().getId())) {
@@ -70,6 +71,11 @@
               journalLine.setRate(glj.getRate());
               OBDal.getInstance().save(journalLine);
             }
+            i++;
+            if (i % 100 == 0) {
+              OBDal.getInstance().flush();
+              OBDal.getInstance().getSession().clear();
+            }
           }
         } finally {
           scrollLines.close();