details:   https://code.openbravo.com/erp/devel/pi/rev/d9b490f70ad2
changeset: 21072:d9b490f70ad2
user:      Stefan Hühner <stefan.huehner <at> openbravo.com>
date:      Wed Sep 04 15:49:58 2013 +0200
summary:   Fixed 24680: Speed up translation import by not doing commits per 
_trl row.
This commit changes translation import to not do an implicit commit per row
updated but bigger transaction + a single commit per imported xml file.
This speed ups translation import greatly.

diffstat:

 src/org/openbravo/erpCommon/ad_forms/TranslationHandler.java |  12 +++++---
 src/org/openbravo/erpCommon/ad_forms/TranslationManager.java |  16 +++++++++---
 2 files changed, 19 insertions(+), 9 deletions(-)

diffs (102 lines):

diff -r 08a91cdea369 -r d9b490f70ad2 
src/org/openbravo/erpCommon/ad_forms/TranslationHandler.java
--- a/src/org/openbravo/erpCommon/ad_forms/TranslationHandler.java      Wed Sep 
04 19:10:24 2013 +0530
+++ b/src/org/openbravo/erpCommon/ad_forms/TranslationHandler.java      Wed Sep 
04 15:49:58 2013 +0200
@@ -10,10 +10,11 @@
  * 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-2010 Openbravo S.L.U.
+ * Contributions are Copyright (C) 2001-2013 Openbravo S.L.U.
  
******************************************************************************/
 package org.openbravo.erpCommon.ad_forms;
 
+import java.sql.Connection;
 import java.sql.Statement;
 
 import org.apache.log4j.Logger;
@@ -38,14 +39,16 @@
     DB = cDB;
   }
 
-  public TranslationHandler(int AD_Client_ID, ConnectionProvider cDB) {
+  public TranslationHandler(int AD_Client_ID, ConnectionProvider cDB, 
Connection con) {
 
     m_AD_Client_ID = AD_Client_ID;
     DB = cDB;
+    this.con = con;
 
   } // TranslationHandler
 
   private ConnectionProvider DB;
+  private Connection con;
 
   /** Client */
   private int m_AD_Client_ID = -1;
@@ -166,14 +169,13 @@
       //
       Statement st = null;
       try {
-        st = DB.getStatement();
+        st = DB.getStatement(con);
         no = st.executeUpdate(m_sql.toString());
       } catch (Exception e) {
         log4j.error("183:" + m_sql.toString() + e.toString());
       } finally {
         try {
-          if (st != null)
-            DB.releaseStatement(st);
+          DB.releaseTransactionalStatement(st);
         } catch (Exception ignored) {
         }
       }
diff -r 08a91cdea369 -r d9b490f70ad2 
src/org/openbravo/erpCommon/ad_forms/TranslationManager.java
--- a/src/org/openbravo/erpCommon/ad_forms/TranslationManager.java      Wed Sep 
04 19:10:24 2013 +0530
+++ b/src/org/openbravo/erpCommon/ad_forms/TranslationManager.java      Wed Sep 
04 15:49:58 2013 +0200
@@ -10,7 +10,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-2011 Openbravo S.L.U.
+ * Contributions are Copyright (C) 2001-2013 Openbravo S.L.U.
  
******************************************************************************/
 package org.openbravo.erpCommon.ad_forms;
 
@@ -19,7 +19,9 @@
 import java.io.FileReader;
 import java.io.FileWriter;
 import java.io.OutputStreamWriter;
+import java.sql.Connection;
 import java.sql.ResultSet;
+import java.sql.SQLException;
 import java.sql.Statement;
 
 import javax.xml.parsers.DocumentBuilder;
@@ -628,19 +630,25 @@
       return msg;
     }
 
+    Connection con = null;
     try {
-      final TranslationHandler handler = new TranslationHandler(AD_Client_ID, 
conn);
+      con = conn.getTransactionConnection();
+      final TranslationHandler handler = new TranslationHandler(AD_Client_ID, 
conn, con);
       final SAXParserFactory factory = SAXParserFactory.newInstance();
       // factory.setValidating(true);
       final SAXParser parser = factory.newSAXParser();
       parser.parse(in, handler);
+      conn.releaseCommitConnection(con);
       log4j
           .info("importTrl - Updated=" + handler.getUpdateCount() + " - from 
file " + in.getName());
-      // return Msg.getMsg(Env.getCtx(), "Updated") + "=" +
-      // handler.getUpdateCount();
       return "";
     } catch (final Exception e) {
       log4j.error("importTrlFile - error parsing file: " + fileName, e);
+      try {
+        conn.releaseRollbackConnection(con);
+      } catch (SQLException e1) {
+        log4j.error("Error on releaseRollbackConnection", e1);
+      }
       throw new OBException(fileName);
     }
   }

------------------------------------------------------------------------------
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to