From 3837a8e32b9a04ffaec3c22c8447d4bb954e8a5b Mon Sep 17 00:00:00 2001 From: hengsin Date: Fri, 29 May 2020 19:58:46 +0800 Subject: [PATCH] IDEMPIERE-4312 Implement cache for list reference at MLookupFactory (#87) Fix clone of MLookupInfo Add list reference cache to MLookupFactory --- .../org/compiere/model/MLookupFactory.java | 21 +++++++++++++++++++ .../src/org/compiere/model/MLookupInfo.java | 15 ++++++++++--- .../src/org/compiere/model/MQuery.java | 15 ++++++++++++- 3 files changed, 47 insertions(+), 4 deletions(-) diff --git a/org.adempiere.base/src/org/compiere/model/MLookupFactory.java b/org.adempiere.base/src/org/compiere/model/MLookupFactory.java index ef6e1039cc..d6fd02381d 100644 --- a/org.adempiere.base/src/org/compiere/model/MLookupFactory.java +++ b/org.adempiere.base/src/org/compiere/model/MLookupFactory.java @@ -55,6 +55,8 @@ public class MLookupFactory private static CLogger s_log = CLogger.getCLogger(MLookupFactory.class); /** Table Reference Cache */ private static CCache s_cacheRefTable = new CCache(I_AD_Ref_Table.Table_Name, 30, 60); // 1h + /** List Reference Cache */ + private static CCache s_cacheRefList = new CCache(I_AD_Ref_List.Table_Name, 30, 60); // 1h /** @@ -295,6 +297,23 @@ public class MLookupFactory */ static public MLookupInfo getLookup_List(Language language, int AD_Reference_Value_ID) { + String lang; + if (language == null) { + lang = Env.getAD_Language(Env.getCtx()); + } else { + lang = language.getAD_Language(); + } + StringBuilder key = new StringBuilder() + .append(Env.getAD_Client_ID(Env.getCtx())).append("|") + .append(lang).append("|") + .append(String.valueOf(AD_Reference_Value_ID)); + MLookupInfo retValue = (MLookupInfo)s_cacheRefList.get(key.toString()); + if (retValue != null) + { + if (s_log.isLoggable(Level.FINEST)) s_log.finest("Cache: " + retValue); + return retValue.cloneIt(); + } + String byValue = DB.getSQLValueString(null, "SELECT IsOrderByValue FROM AD_Reference WHERE AD_Reference_ID = ? ", AD_Reference_Value_ID); StringBuilder realSQL = new StringBuilder ("SELECT NULL, AD_Ref_List.Value,"); MClient client = MClient.get(Env.getCtx()); @@ -333,6 +352,8 @@ public class MLookupFactory 101,101, MQuery.getEqualQuery("AD_Reference_ID", AD_Reference_Value_ID)); // Zoom Window+Query info.QueryDirect = directSql; + s_cacheRefList.put(key.toString(), info.cloneIt()); + return info; } // getLookup_List diff --git a/org.adempiere.base/src/org/compiere/model/MLookupInfo.java b/org.adempiere.base/src/org/compiere/model/MLookupInfo.java index 800a296232..9372f56d77 100644 --- a/org.adempiere.base/src/org/compiere/model/MLookupInfo.java +++ b/org.adempiere.base/src/org/compiere/model/MLookupInfo.java @@ -230,13 +230,22 @@ public class MLookupInfo implements Serializable, Cloneable try { MLookupInfo clone = (MLookupInfo)super.clone(); + clone.parsedValidationCode = ""; + clone.IsValidated = false; + clone.ctx = null; + if (ZoomQuery != null) + clone.ZoomQuery = ZoomQuery.clone(); return clone; } - catch (Exception e) + catch (CloneNotSupportedException e) { - CLogger.get().log(Level.SEVERE, "", e); + throw new RuntimeException(e); } - return null; } // clone + @Override + public MLookupInfo clone() { + return cloneIt(); + } + } // MLookupInfo diff --git a/org.adempiere.base/src/org/compiere/model/MQuery.java b/org.adempiere.base/src/org/compiere/model/MQuery.java index 4bb6479fd6..580c526582 100644 --- a/org.adempiere.base/src/org/compiere/model/MQuery.java +++ b/org.adempiere.base/src/org/compiere/model/MQuery.java @@ -44,7 +44,7 @@ import org.compiere.util.ValueNamePair; *
  • BF [ 2860022 ] MQuery.get() is generating restrictions for non-existent column * https://sourceforge.net/tracker/?func=detail&aid=2860022&group_id=176962&atid=879332 */ -public class MQuery implements Serializable +public class MQuery implements Serializable, Cloneable { /** * @@ -1047,6 +1047,19 @@ public class MQuery implements Serializable public MQuery getReportProcessQuery() { return m_reportProcessQuery; } + + @Override + public MQuery clone() { + try { + MQuery clone = (MQuery) super.clone(); + clone.m_recordCount = 999999; + if (m_reportProcessQuery != null) + clone.m_reportProcessQuery = m_reportProcessQuery.clone(); + return clone; + } catch (CloneNotSupportedException e) { + throw new RuntimeException(e); + } + } } // MQuery /*****************************************************************************