From 51b8033632b7bb07509bdd2057bb3d76216c7b7e Mon Sep 17 00:00:00 2001 From: hieplq Date: Tue, 13 Oct 2015 06:33:36 +0800 Subject: [PATCH 1/5] IDEMPIERE-2886:leak database resource --- org.adempiere.base/src/org/compiere/model/MRole.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/org.adempiere.base/src/org/compiere/model/MRole.java b/org.adempiere.base/src/org/compiere/model/MRole.java index 185d8b6ef3..03f6e43133 100644 --- a/org.adempiere.base/src/org/compiere/model/MRole.java +++ b/org.adempiere.base/src/org/compiere/model/MRole.java @@ -2598,6 +2598,8 @@ public final class MRole extends X_AD_Role } } } + + DB.close(rs, pstmt); } validOptions.toArray(options); From 136b0f147d35fff43c9d7e30fb145c3e22977aa4 Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Wed, 14 Oct 2015 19:51:32 -0500 Subject: [PATCH 2/5] IDEMPIERE-2889 Reservations wrong after a MR with three lines of same PO Line --- org.adempiere.base/src/org/compiere/model/MInOut.java | 2 ++ org.adempiere.ui/src/org/compiere/grid/CreateFrom.java | 2 +- .../src/org/compiere/grid/CreateFromShipment.java | 4 +++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/org.adempiere.base/src/org/compiere/model/MInOut.java b/org.adempiere.base/src/org/compiere/model/MInOut.java index a45bcaf788..6fa87fa356 100644 --- a/org.adempiere.base/src/org/compiere/model/MInOut.java +++ b/org.adempiere.base/src/org/compiere/model/MInOut.java @@ -1350,6 +1350,8 @@ public class MInOut extends X_M_InOut implements DocAction { BigDecimal toDelivered = oLine.getQtyOrdered() .subtract(oLine.getQtyDelivered()); + if (toDelivered.signum() < 0) // IDEMPIERE-2889 + toDelivered = Env.ZERO; if (sLine.getMovementQty().compareTo(toDelivered) > 0) overReceipt = sLine.getMovementQty().subtract( toDelivered); diff --git a/org.adempiere.ui/src/org/compiere/grid/CreateFrom.java b/org.adempiere.ui/src/org/compiere/grid/CreateFrom.java index 507bf499f2..455f886440 100644 --- a/org.adempiere.ui/src/org/compiere/grid/CreateFrom.java +++ b/org.adempiere.ui/src/org/compiere/grid/CreateFrom.java @@ -111,7 +111,7 @@ public abstract class CreateFrom implements ICreateFrom { sql = sql.append(" AND o.M_Warehouse_ID=? "); } - sql = sql.append("ORDER BY o.DateOrdered"); + sql = sql.append("ORDER BY o.DateOrdered,o.DocumentNo"); // PreparedStatement pstmt = null; ResultSet rs = null; diff --git a/org.adempiere.ui/src/org/compiere/grid/CreateFromShipment.java b/org.adempiere.ui/src/org/compiere/grid/CreateFromShipment.java index d38cca72fd..d54397655f 100644 --- a/org.adempiere.ui/src/org/compiere/grid/CreateFromShipment.java +++ b/org.adempiere.ui/src/org/compiere/grid/CreateFromShipment.java @@ -192,7 +192,9 @@ public abstract class CreateFromShipment extends CreateFrom Vector> data = new Vector>(); StringBuilder sql = new StringBuilder("SELECT " - + "l.QtyOrdered-SUM(COALESCE(m.Qty,0))," // 1 + + "l.QtyOrdered-SUM(COALESCE(m.Qty,0))" + // subtract drafted lines from this or other orders IDEMPIERE-2889 + + "-COALESCE((SELECT SUM(MovementQty) FROM M_InOutLine iol JOIN M_InOut io ON iol.M_InOut_ID=io.M_InOut_ID WHERE l.C_OrderLine_ID=iol.C_OrderLine_ID AND io.Processed='N'),0)," // 1 + "CASE WHEN l.QtyOrdered=0 THEN 0 ELSE l.QtyEntered/l.QtyOrdered END," // 2 + " l.C_UOM_ID,COALESCE(uom.UOMSymbol,uom.Name)," // 3..4 + " p.M_Locator_ID, loc.Value, " // 5..6 From c6bf87ef057ef92a53696e064ddbc7212f01ba90 Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Wed, 14 Oct 2015 20:19:13 -0500 Subject: [PATCH 3/5] IDEMPIERE-2756 Background threads losing context when user log out - fix validation / integrate fix from hengsin: error when user close the browser tab while a report/process is still running --- .../src/org/compiere/process/SvrProcess.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/org.adempiere.base/src/org/compiere/process/SvrProcess.java b/org.adempiere.base/src/org/compiere/process/SvrProcess.java index 67ca51f844..deb3c2430f 100644 --- a/org.adempiere.base/src/org/compiere/process/SvrProcess.java +++ b/org.adempiere.base/src/org/compiere/process/SvrProcess.java @@ -563,8 +563,13 @@ public abstract class SvrProcess implements ProcessCall */ private void unlock () { + boolean noContext = Env.getCtx().isEmpty() && Env.getCtx().getProperty("#AD_Client_ID") == null; try { + //save logging info even if context is lost + if (noContext) + Env.getCtx().put("#AD_Client_ID", m_pi.getAD_Client_ID()); + MPInstance mpi = new MPInstance (getCtx(), m_pi.getAD_PInstance_ID(), null); if (mpi.get_ID() == 0) { @@ -583,6 +588,11 @@ public abstract class SvrProcess implements ProcessCall { log.severe("unlock() - " + e.getLocalizedMessage()); } + finally + { + if (noContext) + Env.getCtx().remove("#AD_Client_ID"); + } } // unlock /** From 6522a64289dfa72a916a9ecda4387cb35e0170c3 Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Wed, 14 Oct 2015 20:24:44 -0500 Subject: [PATCH 4/5] IDEMPIERE-2756 Background threads losing context when user log out - fix validation / integrate fix from hengsin: Allow null context parameter for PO. Run pipodictionaryservice as system client ( ad_client_id=0 ). --- org.adempiere.base/src/org/compiere/model/PO.java | 4 +--- .../src/org/adempiere/pipo/srv/PipoDictionaryService.java | 3 +++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/org.adempiere.base/src/org/compiere/model/PO.java b/org.adempiere.base/src/org/compiere/model/PO.java index 6de7d06921..0e776ca2bd 100644 --- a/org.adempiere.base/src/org/compiere/model/PO.java +++ b/org.adempiere.base/src/org/compiere/model/PO.java @@ -186,9 +186,7 @@ public abstract class PO */ public PO (Properties ctx, int ID, String trxName, ResultSet rs) { - if (ctx == null) - throw new IllegalArgumentException ("No Context"); - p_ctx = ctx; + p_ctx = ctx != null ? ctx : Env.getCtx(); m_trxName = trxName; p_info = initPO(ctx); diff --git a/org.adempiere.pipo/src/org/adempiere/pipo/srv/PipoDictionaryService.java b/org.adempiere.pipo/src/org/adempiere/pipo/srv/PipoDictionaryService.java index 74a54130fe..e92e2f0032 100644 --- a/org.adempiere.pipo/src/org/adempiere/pipo/srv/PipoDictionaryService.java +++ b/org.adempiere.pipo/src/org/adempiere/pipo/srv/PipoDictionaryService.java @@ -59,6 +59,9 @@ public class PipoDictionaryService implements IDictionaryService { packIn = new PackIn(); packIn.setPackageName(context.getBundle().getSymbolicName()); + if (Env.getCtx().getProperty("#AD_Client_ID") == null) { + Env.getCtx().put("#AD_Client_ID", 0); + } //get package version from file name suffix or bundle header String packageVersion = null; String fileName = packageFile.getName(); From 8e193dad3dbe0a3924ff8da3f129bb39e7b39c1a Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Wed, 14 Oct 2015 20:29:42 -0500 Subject: [PATCH 5/5] IDEMPIERE-2756 Background threads losing context when user log out - fix validation / integrate fix from hengsin: Improve handling of context lost ( due to user close browser ) exception for document workflow. --- .../src/org/compiere/wf/MWFActivity.java | 46 ++++++++++++++----- .../webui/apps/AbstractProcessDialog.java | 15 +++--- 2 files changed, 43 insertions(+), 18 deletions(-) diff --git a/org.adempiere.base/src/org/compiere/wf/MWFActivity.java b/org.adempiere.base/src/org/compiere/wf/MWFActivity.java index d6185dcac8..32b4110713 100644 --- a/org.adempiere.base/src/org/compiere/wf/MWFActivity.java +++ b/org.adempiere.base/src/org/compiere/wf/MWFActivity.java @@ -916,19 +916,41 @@ public class MWFActivity extends X_AD_WF_Activity implements Runnable processMsg = e.getMessage(); setTextMsg(processMsg); // addTextMsg(e); // do not add the exception text - setWFState (StateEngine.STATE_Terminated); // unlocks - // Set Document Status - if (m_po != null && m_po instanceof DocAction && m_docStatus != null) + boolean contextLost = false; + if (e instanceof AdempiereException && "Context lost".equals(e.getMessage())) { - m_po.load(get_TrxName()); - DocAction doc = (DocAction)m_po; - doc.setDocStatus(m_docStatus); - m_po.saveEx(); - } - if (m_process != null) - { - m_process.setProcessMsg(this.getTextMsg()); - m_process.saveEx(); + contextLost = true; + m_docStatus = DocAction.STATUS_Invalid; + } + try { + if (contextLost) + { + Env.getCtx().setProperty("#AD_Client_ID", (m_po != null ? Integer.toString(m_po.getAD_Client_ID()) : "0") ); + m_state = new StateEngine(WFSTATE_Running); + setProcessed(true); + setWFState (StateEngine.STATE_Aborted); + } + else + { + setWFState (StateEngine.STATE_Terminated); // unlocks + } + + // Set Document Status + if (m_po != null && m_po instanceof DocAction && m_docStatus != null) + { + m_po.load(get_TrxName()); + DocAction doc = (DocAction)m_po; + doc.setDocStatus(m_docStatus); + m_po.saveEx(); + } + if (m_process != null) + { + m_process.setProcessMsg(this.getTextMsg()); + m_process.saveEx(); + } + } finally { + if (contextLost) + Env.getCtx().remove("#AD_Client_ID"); } } finally diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/AbstractProcessDialog.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/AbstractProcessDialog.java index f21892a2fb..e7e2ba6da0 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/AbstractProcessDialog.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/AbstractProcessDialog.java @@ -462,13 +462,16 @@ public abstract class AbstractProcessDialog extends Window implements IProcessUI if (Executions.getCurrent() == null) { - Executions.schedule(getDesktop(), new EventListener() + if (getDesktop() != null) { - @Override - public void onEvent(Event event) throws Exception { - doUnlockUI(); - } - }, new Event("onUnLockUI")); + Executions.schedule(getDesktop(), new EventListener() + { + @Override + public void onEvent(Event event) throws Exception { + doUnlockUI(); + } + }, new Event("onUnLockUI")); + } } else { doUnlockUI(); }