From 8d7cd2bed3814459919a1c25a4c7c49aeaae068c Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Sat, 6 Feb 2016 16:31:04 +0100 Subject: [PATCH] IDEMPIERE-3017 CSV Importer leaving open trx (DB locks) / fix error reported by Andrea Belloto https://groups.google.com/d/msg/idempiere/6L0B7H2pDvo/FHVRirSTGQAJ --- .../adempiere/impexp/GridTabCSVImporter.java | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/org.adempiere.base/src/org/adempiere/impexp/GridTabCSVImporter.java b/org.adempiere.base/src/org/adempiere/impexp/GridTabCSVImporter.java index 81d0f909a3..e6904bddf8 100644 --- a/org.adempiere.base/src/org/adempiere/impexp/GridTabCSVImporter.java +++ b/org.adempiere.base/src/org/adempiere/impexp/GridTabCSVImporter.java @@ -23,6 +23,7 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.nio.charset.Charset; +import java.sql.SQLException; import java.sql.Timestamp; import java.text.DecimalFormatSymbols; import java.text.SimpleDateFormat; @@ -315,10 +316,16 @@ public class GridTabCSVImporter implements IGridTabImporter /** * Commit the trx and writes in the file */ - private void commitTrx(){ - trx.commit(); + private String commitTrx(){ + try { + trx.commit(true); + } catch (SQLException e) { + setError(true); + return e.getLocalizedMessage(); + } for( String row : rowsTmpResult ) logFileW.write(row); + return null; } /** @@ -533,6 +540,7 @@ public class GridTabCSVImporter implements IGridTabImporter setError(false); }else { + boolean commit = false; if( isThereDocAction ){ boolean isError = false; @@ -553,11 +561,19 @@ public class GridTabCSVImporter implements IGridTabImporter gridTab.dataDelete(); rollbackTrx(); }else{ - commitTrx(); + commit = true; } }else{ - commitTrx(); - } + commit = true; + } + if (commit) { + String commitResult = commitTrx(); + if (isError()) { + rowsTmpResult.set(0,rowsTmpResult.get(0).replace(quoteChar + "\n",commitResult + quoteChar + "\n")); + gridTab.dataDelete(); + rollbackTrx(); + } + } } trx.close();