From d3717bc1fa3d1b2ebc649b5ee9f88a66b8b0d1b1 Mon Sep 17 00:00:00 2001 From: hengsin Date: Tue, 21 Jul 2020 06:10:49 +0800 Subject: [PATCH] IDEMPIERE-4373 Bug fixes for CSV Import loader (#174) close trx in finally block. m_directNullKey interfere with CSV Import Loader due to trx that's not committed yet. insert mode: update window/tab context after save. --- .../adempiere/impexp/GridTabCSVImporter.java | 97 ++++++++++--------- .../src/org/compiere/model/MLookup.java | 5 - 2 files changed, 52 insertions(+), 50 deletions(-) diff --git a/org.adempiere.base/src/org/adempiere/impexp/GridTabCSVImporter.java b/org.adempiere.base/src/org/adempiere/impexp/GridTabCSVImporter.java index b92420dea8..1e497fd31f 100644 --- a/org.adempiere.base/src/org/adempiere/impexp/GridTabCSVImporter.java +++ b/org.adempiere.base/src/org/adempiere/impexp/GridTabCSVImporter.java @@ -539,53 +539,52 @@ public class GridTabCSVImporter implements IGridTabImporter * @param childs */ private void manageMasterTrx(GridTab gridTab, List childs){ - - if( trx != null ){ - - if( isError() ) { - gridTab.dataDelete(); - rollbackTrx(); - setError(false); - }else { - - boolean commit = false; - if( isThereDocAction ){ - - boolean isError = false; - int AD_Process_ID = MColumn.get(Env.getCtx(), gridTab.getField("DocAction").getAD_Column_ID()).getAD_Process_ID(); - - if( AD_Process_ID > 0 ){ - String docResult = processDocAction(masterRecord, AD_Process_ID); - - if(docResult.contains("error")) - isError = true; - - rowsTmpResult.set(0,rowsTmpResult.get(0).replace(quoteChar + "\n",docResult + quoteChar + "\n")); - }else { - throwAdempiereException("No Process found for document action."); - } - - if( isError ){ - gridTab.dataDelete(); - rollbackTrx(); - }else{ + if (trx != null) { + try { + if (isError()) { + gridTab.dataDelete(); + rollbackTrx(); + setError(false); + } else { + boolean commit = false; + if (isThereDocAction) { + + boolean isError = false; + int AD_Process_ID = MColumn.get(Env.getCtx(), gridTab.getField("DocAction").getAD_Column_ID()).getAD_Process_ID(); + + if (AD_Process_ID > 0){ + String docResult = processDocAction(masterRecord, AD_Process_ID); + + if (docResult.contains("error")) + isError = true; + + rowsTmpResult.set(0,rowsTmpResult.get(0).replace(quoteChar + "\n",docResult + quoteChar + "\n")); + } else { + throwAdempiereException("No Process found for document action."); + } + + if (isError){ + gridTab.dataDelete(); + rollbackTrx(); + } else { + commit = true; + } + } else { commit = true; } - }else{ - commit = true; - } - if (commit) { - String commitResult = commitTrx(); - if (isError()) { - rowsTmpResult.set(0,rowsTmpResult.get(0).replace(quoteChar + "\n",commitResult + quoteChar + "\n")); - gridTab.dataDelete(); - rollbackTrx(); + if (commit) { + String commitResult = commitTrx(); + if (isError()) { + rowsTmpResult.set(0,rowsTmpResult.get(0).replace(quoteChar + "\n",commitResult + quoteChar + "\n")); + gridTab.dataDelete(); + rollbackTrx(); + } } } + } finally { + trx.close(); + trx=null; } - - trx.close(); - trx=null; } }//manageMasterTrx @@ -687,9 +686,17 @@ public class GridTabCSVImporter implements IGridTabImporter if(currentGridTab.equals(gridTab)) masterRecord = po; - if( isInsertMode() ) - logMsg = Msg.getMsg(Env.getCtx(), "Inserted") + " " + po.toString(); - else{ + if( isInsertMode() ) { + logMsg = Msg.getMsg(Env.getCtx(), "Inserted") + " " + po.toString(); + if (!Util.isEmpty(currentGridTab.getKeyColumnName()) && currentGridTab.getKeyColumnName().endsWith("_ID")) { + int recordId = currentGridTab.getRecord_ID(); + if (recordId > 0) { + if (currentGridTab.getTabNo() == 0) + Env.setContext(Env.getCtx(), currentGridTab.getWindowNo(), currentGridTab.getKeyColumnName(), recordId); + Env.setContext(Env.getCtx(), currentGridTab.getWindowNo(), currentGridTab.getTabNo(), currentGridTab.getKeyColumnName(), Integer.toString(recordId)); + } + } + } else { logMsg = Msg.getMsg(Env.getCtx(), "Updated") + " " + po.toString(); if( currentGridTab.equals(gridTab) && sortedtTabMapIndexes.size()>1 ) currentGridTab.dataRefresh(true); diff --git a/org.adempiere.base/src/org/compiere/model/MLookup.java b/org.adempiere.base/src/org/compiere/model/MLookup.java index 3853ee5bd9..97e8221569 100644 --- a/org.adempiere.base/src/org/compiere/model/MLookup.java +++ b/org.adempiere.base/src/org/compiere/model/MLookup.java @@ -512,8 +512,6 @@ public final class MLookup extends Lookup implements Serializable /** Save getDirect last return value */ private HashMap m_lookupDirect = null; - /** Save last unsuccessful */ - private Object m_directNullKey = null; private Future m_loaderFuture; public NamePair getDirect (Object key, boolean saveInCache, boolean cacheLocal) @@ -533,8 +531,6 @@ public final class MLookup extends Lookup implements Serializable // Nothing to query if (key == null || m_info.QueryDirect == null || m_info.QueryDirect.length() == 0) return null; - if (key.equals(m_directNullKey)) - return null; if (key.toString().trim().length() == 0) return null; // @@ -609,7 +605,6 @@ public final class MLookup extends Lookup implements Serializable } else { - m_directNullKey = key; directValue = null; }