details: https://code.openbravo.com/erp/devel/pi/rev/80dac576712c changeset: 30881:80dac576712c user: Atul Gaware <atul.gaware <at> openbravo.com> date: Wed Dec 14 15:54:12 2016 +0530 summary: Fixes issue 34599: Bad performance when posting reconciliation with many lines
** Add m_RecordID2 member variable, getter and setter method in FactLine.java ** Set RecordID2 while Creating FactLine in Fact.java ** After successfully creation of FactLine, add RecordID2 to Set. ** Move UpdateBalancedDate in Fact.java ** For every 1000 records in RecordID2 Set, call UpdateBalancedDate method ** Set of 1000 records is nescessary to meet Oracle In clause restrictions. details: https://code.openbravo.com/erp/devel/pi/rev/ebd14e85e73d changeset: 30882:ebd14e85e73d user: Alvaro Ferraz <alvaro.ferraz <at> openbravo.com> date: Thu Dec 15 12:39:26 2016 +0100 summary: Related to issue 34599: Code review improvements Improve splitRecordID2Set method. diffstat: src/org/openbravo/erpCommon/ad_forms/Fact.java | 42 ++++++++++++++++- src/org/openbravo/erpCommon/ad_forms/FactLine.java | 35 ++++++++----- src/org/openbravo/erpCommon/ad_forms/FactLine_data.xsql | 6 +- 3 files changed, 66 insertions(+), 17 deletions(-) diffs (202 lines): diff -r 9129ff0ef022 -r ebd14e85e73d src/org/openbravo/erpCommon/ad_forms/Fact.java --- a/src/org/openbravo/erpCommon/ad_forms/Fact.java Wed Nov 23 22:45:47 2016 +0530 +++ b/src/org/openbravo/erpCommon/ad_forms/Fact.java Thu Dec 15 12:39:26 2016 +0100 @@ -11,7 +11,7 @@ * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved. * Contributor(s): Openbravo SLU - * Contributions are Copyright (C) 2001-2015 Openbravo S.L.U. + * Contributions are Copyright (C) 2001-2016 Openbravo S.L.U. ****************************************************************************** */ package org.openbravo.erpCommon.ad_forms; @@ -20,7 +20,10 @@ import java.sql.Connection; import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; +import java.util.List; +import java.util.Set; import javax.servlet.ServletException; @@ -28,6 +31,7 @@ import org.apache.log4j.Logger; import org.openbravo.base.secureApp.VariablesSecureApp; import org.openbravo.database.ConnectionProvider; +import org.openbravo.erpCommon.utility.Utility; public class Fact { static Logger log4jFact = Logger.getLogger(Fact.class); @@ -289,6 +293,15 @@ + " - m_lines.size() - " + m_lines.size()); line.roundToCurrencyPrecision(); + String Record_ID2 = null; + if (docLine != null) { + Record_ID2 = docLine.m_Record_Id2; + } + if (StringUtils.isEmpty(Record_ID2)) { + Record_ID2 = m_doc.m_Record_Id2; + } + line.setM_RecordID2(Record_ID2); + log4jFact.debug("Fact - createLine - Record_ID2 = " + Record_ID2); m_lines.add(line); return line; @@ -467,16 +480,43 @@ log4jFact.debug(" Fact - save() - m_lines.size - " + m_lines.size()); if (m_lines.size() == 0) return true; + Set<String> recordID2Set = new HashSet<String>(); for (int i = 0; i < m_lines.size(); i++) { FactLine fl = (FactLine) m_lines.get(i); if (!fl.save(con, conn, vars)) { // abort on first error log4jFact.warn("Save (fact): aborted. i=" + i); return false; } + if (StringUtils.isNotEmpty(fl.getM_RecordID2())) { + recordID2Set.add(fl.getM_RecordID2()); + } + } + if (!recordID2Set.isEmpty()) { + for (Set<String> recordID2 : splitRecordID2Set(recordID2Set, 1000)) { + // Update Balancing Date [Open Balances project] + FactLineData.updateDateBalanced(con, conn, Utility.getInStrSet(recordID2)); + } } return true; } // commit + public List<Set<String>> splitRecordID2Set(Set<String> recordID2Set, int maxSize) { + List<Set<String>> recordIDSetList = new ArrayList<Set<String>>(); + int recordID2SetSize = recordID2Set.size(); + + if (recordID2SetSize <= maxSize) { + recordIDSetList.add(recordID2Set); + return recordIDSetList; + } + + List<String> recordID2List = new ArrayList<String>(recordID2Set); + for (int i = 0; i < recordID2SetSize; i += maxSize) { + recordIDSetList.add(new HashSet<String>(recordID2List.subList(i, + Math.min(recordID2SetSize, i + maxSize)))); + } + return recordIDSetList; + } + /** * Are all segments balanced * diff -r 9129ff0ef022 -r ebd14e85e73d src/org/openbravo/erpCommon/ad_forms/FactLine.java --- a/src/org/openbravo/erpCommon/ad_forms/FactLine.java Wed Nov 23 22:45:47 2016 +0530 +++ b/src/org/openbravo/erpCommon/ad_forms/FactLine.java Thu Dec 15 12:39:26 2016 +0100 @@ -11,7 +11,7 @@ * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved. * Contributor(s): Openbravo SLU - * Contributions are Copyright (C) 2001-2014 Openbravo S.L.U. + * Contributions are Copyright (C) 2001-2016 Openbravo S.L.U. ****************************************************************************** */ package org.openbravo.erpCommon.ad_forms; @@ -65,6 +65,7 @@ // Doc ID private String m_AD_Table_ID; private String m_Record_ID; + private String m_Record_ID2; private String m_Line_ID; /** * Public variables are set by Fact.createLine @@ -569,12 +570,7 @@ if (DateAcct == null || DateAcct.equals("")) DateAcct = m_docVO.DateAcct; log4jFactLine.debug("FactLine - save - before Record_ID2 " + m_Record_ID); - String Record_ID2 = ""; - if (m_docLine != null) - Record_ID2 = m_docLine.m_Record_Id2; - if (Record_ID2 == null || Record_ID2.equals("")) - Record_ID2 = m_docVO.m_Record_Id2; - log4jFactLine.debug("FactLine - save - after Record_ID2 = " + Record_ID2); + String C_Period_ID = ""; if (m_docLine != null) C_Period_ID = setC_Period_ID(m_docVO, m_docLine.m_DateAcct, conn); @@ -815,7 +811,7 @@ log4jFactLine.debug("FactLine - m_Fact_Acct_Group_ID " + m_Fact_Acct_Group_ID + " - m_SeqNo " + m_SeqNo); log4jFactLine.debug("FactLine - m_DocBaseType " + m_DocBaseType + " - Record_ID2 " - + Record_ID2); + + m_Record_ID2); log4jFactLine.debug("FactLine - m_A_Asset_ID " + ((m_docLine != null) ? m_docLine.m_A_Asset_ID : "")); log4jFactLine.debug("FactLine - m_C_WithHolding_ID " @@ -828,14 +824,10 @@ m_AmtSourceCr, m_AmtAcctDr, m_AmtAcctCr, C_UOM_ID, Qty, m_M_Locator_ID, M_Product_ID, C_BPartner_ID, AD_OrgTrx_ID, C_LocFrom_ID, C_LocTo_ID, C_SalesRegion_ID, C_Project_ID, C_Campaign_ID, C_Activity_ID, User1_ID, User2_ID, description.toString(), - m_Fact_Acct_Group_ID, m_SeqNo, m_DocBaseType, Record_ID2, + m_Fact_Acct_Group_ID, m_SeqNo, m_DocBaseType, m_Record_ID2, (m_docLine != null) ? m_docLine.m_A_Asset_ID : "", (m_docLine != null) ? m_docLine.m_C_WithHolding_ID : "", m_docVO.C_DocType_ID, C_Costcenter_ID, (m_docVO.m_IsOpening.equals("Y")) ? "O" : "N"); - // Update Balancing Date [Open Balances project] - if (Record_ID2 != null && !"".equals(Record_ID2)) { - FactLineData.updateDateBalanced(con, conn, Record_ID2); - } log4jFactLine.debug("FactLine - After insertFactAct"); } // if (m_docVO.m_IsOpening.equals("Y")) @@ -1122,4 +1114,21 @@ return m_C_Currency_ID; } + /** + * @return the record_ID2 + */ + public String getM_RecordID2() { + return m_Record_ID2; + } + + /** + * Set Record_ID2 from docLine or docVo + * + * @param record_ID2 + * m_RecordID2 + * + */ + public void setM_RecordID2(String record_ID2) { + m_Record_ID2 = record_ID2; + } } diff -r 9129ff0ef022 -r ebd14e85e73d src/org/openbravo/erpCommon/ad_forms/FactLine_data.xsql --- a/src/org/openbravo/erpCommon/ad_forms/FactLine_data.xsql Wed Nov 23 22:45:47 2016 +0530 +++ b/src/org/openbravo/erpCommon/ad_forms/FactLine_data.xsql Thu Dec 15 12:39:26 2016 +0100 @@ -12,7 +12,7 @@ * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved. * Contributor(s): Openbravo SLU - * Contributions are Copyright (C) 2001-2014 Openbravo S.L.U. + * Contributions are Copyright (C) 2001-2016 Openbravo S.L.U. ****************************************************************************** --> @@ -144,7 +144,7 @@ group by financialm1_.Record_ID2 having sum(financialm1_.AmtAcctCr-financialm1_.AmtAcctDr)=0) where - Record_ID2 = ? + Record_ID2 IN ('1') and Datebalanced is null and exists (select 1 from Fact_Acct financialm2_ @@ -155,7 +155,7 @@ having sum(financialm2_.AmtAcctCr-financialm2_.AmtAcctDr)=0) ]]> </Sql> - <Parameter name="recordID2"/> + <Parameter name="recordID2" optional="false" type="replace" after="Record_ID2 IN (" text="'1'"/> </SqlMethod> <SqlMethod name="updateFactAcct" type="preparedStatement" connection="true" return="rowCount"> <SqlMethodComment></SqlMethodComment> ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot _______________________________________________ Openbravo-commits mailing list Openbravo-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbravo-commits