IDEMPIERE-3017 CSV Importer leaving open trx (DB locks) / fix error reported by Andrea Belloto https://groups.google.com/d/msg/idempiere/6L0B7H2pDvo/FHVRirSTGQAJ

This commit is contained in:
Carlos Ruiz 2016-02-06 16:31:04 +01:00
parent c072828a97
commit 8d7cd2bed3
1 changed files with 21 additions and 5 deletions

View File

@ -23,6 +23,7 @@ import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.sql.SQLException;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.text.DecimalFormatSymbols; import java.text.DecimalFormatSymbols;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
@ -315,10 +316,16 @@ public class GridTabCSVImporter implements IGridTabImporter
/** /**
* Commit the trx and writes in the file * Commit the trx and writes in the file
*/ */
private void commitTrx(){ private String commitTrx(){
trx.commit(); try {
trx.commit(true);
} catch (SQLException e) {
setError(true);
return e.getLocalizedMessage();
}
for( String row : rowsTmpResult ) for( String row : rowsTmpResult )
logFileW.write(row); logFileW.write(row);
return null;
} }
/** /**
@ -533,6 +540,7 @@ public class GridTabCSVImporter implements IGridTabImporter
setError(false); setError(false);
}else { }else {
boolean commit = false;
if( isThereDocAction ){ if( isThereDocAction ){
boolean isError = false; boolean isError = false;
@ -553,11 +561,19 @@ public class GridTabCSVImporter implements IGridTabImporter
gridTab.dataDelete(); gridTab.dataDelete();
rollbackTrx(); rollbackTrx();
}else{ }else{
commitTrx(); commit = true;
} }
}else{ }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(); trx.close();