From f15abe65222c326156b9d76f1d9ca7d1e789636e Mon Sep 17 00:00:00 2001 From: hengsin Date: Tue, 15 Mar 2022 16:30:11 +0800 Subject: [PATCH] IDEMPIERE-5224 Locator Field type Caching Improvement (#1242) * IDEMPIERE-5224 Locator Field type Caching Improvement - Replace M_Locator.get with MLocator ResultSet constructor - Implement lazy loading for MLocatorLookup * IDEMPIERE-5224 Locator Field type Caching Improvement - Implement lazy loading without new constructor (as suggested by Carlos) --- .../org/compiere/model/MLocatorLookup.java | 21 ++++++++++--------- .../apps/form/WCreateFromShipmentUI.java | 2 +- .../webui/apps/form/WTrxMaterial.java | 2 +- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/org.adempiere.base/src/org/compiere/model/MLocatorLookup.java b/org.adempiere.base/src/org/compiere/model/MLocatorLookup.java index a2ef8e6c17..5e31882d5a 100644 --- a/org.adempiere.base/src/org/compiere/model/MLocatorLookup.java +++ b/org.adempiere.base/src/org/compiere/model/MLocatorLookup.java @@ -73,9 +73,6 @@ public final class MLocatorLookup extends Lookup implements Serializable super (DisplayType.TableDir, WindowNo); m_ctx = ctx; m_validationCode = validationCode; - // - m_loader = new Loader(); - m_loader.start(); } // MLocator /** Context */ @@ -183,7 +180,7 @@ public final class MLocatorLookup extends Lookup implements Serializable return new KeyNamePair (loc.getM_Locator_ID(), loc.toString()); // Not found and waiting for loader - if (m_loader.isAlive()) + if (m_loader != null && m_loader.isAlive()) { log.fine("Waiting for Loader"); loadComplete(); @@ -372,7 +369,7 @@ public final class MLocatorLookup extends Lookup implements Serializable int local_only_warehouse_id = getOnly_Warehouse_ID(); // [ 1674891 ] MLocatorLookup - weird error int local_only_product_id = getOnly_Product_ID(); - StringBuilder sql = new StringBuilder("SELECT M_Locator.M_Locator_ID FROM M_Locator ") + StringBuilder sql = new StringBuilder("SELECT M_Locator.* FROM M_Locator ") .append(" INNER JOIN M_Warehouse wh ON (wh.M_Warehouse_ID=M_Locator.M_Warehouse_ID) ") .append(" WHERE M_Locator.IsActive='Y' ") .append(" AND wh.IsActive='Y'"); @@ -431,8 +428,8 @@ public final class MLocatorLookup extends Lookup implements Serializable // while (rs.next()) { - int M_Locator_ID = rs.getInt(1); - MLocator loc = MLocator.get(m_ctx, M_Locator_ID); + MLocator loc = new MLocator(Env.getCtx(), rs, null); + int M_Locator_ID = loc.getM_Locator_ID(); m_lookup.put(Integer.valueOf(M_Locator_ID), loc); } } @@ -457,9 +454,13 @@ public final class MLocatorLookup extends Lookup implements Serializable */ public Collection getData () { - if (m_loader.isAlive()) + if (m_loader == null) { - log.fine("Waiting for Loader"); + refresh(); + } + else if (m_loader.isAlive()) + { + if (log.isLoggable(Level.FINE)) log.fine("Waiting for Loader"); try { m_loader.join(); @@ -503,7 +504,7 @@ public final class MLocatorLookup extends Lookup implements Serializable */ public int refresh() { - log.fine("start"); + if (log.isLoggable(Level.FINE)) log.fine("start"); m_loader = new Loader(); m_loader.start(); try diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromShipmentUI.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromShipmentUI.java index 948cc1cf25..50212e6455 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromShipmentUI.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromShipmentUI.java @@ -138,7 +138,7 @@ public class WCreateFromShipmentUI extends CreateFromShipment implements EventLi sameWarehouseCb.setSelected(true); sameWarehouseCb.addActionListener(this); // load Locator - MLocatorLookup locator = new MLocatorLookup(Env.getCtx(), p_WindowNo); + MLocatorLookup locator = new MLocatorLookup(Env.getCtx(), p_WindowNo, (String)null); locatorField = new WLocatorEditor ("M_Locator_ID", true, false, true, locator, p_WindowNo); initBPartner(false); diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WTrxMaterial.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WTrxMaterial.java index 5fa7a07a12..8e011be49a 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WTrxMaterial.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WTrxMaterial.java @@ -231,7 +231,7 @@ public class WTrxMaterial extends TrxMaterial orgField = new WTableDirEditor("AD_Org_ID", false, false, true, orgLookup); // orgField.addVetoableChangeListener(this); // Locator - MLocatorLookup locatorLookup = new MLocatorLookup(ctx, m_WindowNo); + MLocatorLookup locatorLookup = new MLocatorLookup(ctx, m_WindowNo, null); locatorField = new WLocatorEditor ("M_Locator_ID", false, false, true, locatorLookup, m_WindowNo); // locatorField.addVetoableChangeListener(this); // Product