IDEMPIERE-4312 Implement cache for list reference at MLookupFactory (#87)

Fix clone of MLookupInfo
Add list reference cache to MLookupFactory
This commit is contained in:
hengsin 2020-05-29 19:58:46 +08:00 committed by GitHub
parent fca0963fd9
commit 3837a8e32b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 47 additions and 4 deletions

View File

@ -55,6 +55,8 @@ public class MLookupFactory
private static CLogger s_log = CLogger.getCLogger(MLookupFactory.class); private static CLogger s_log = CLogger.getCLogger(MLookupFactory.class);
/** Table Reference Cache */ /** Table Reference Cache */
private static CCache<String,MLookupInfo> s_cacheRefTable = new CCache<String,MLookupInfo>(I_AD_Ref_Table.Table_Name, 30, 60); // 1h private static CCache<String,MLookupInfo> s_cacheRefTable = new CCache<String,MLookupInfo>(I_AD_Ref_Table.Table_Name, 30, 60); // 1h
/** List Reference Cache */
private static CCache<String,MLookupInfo> s_cacheRefList = new CCache<String,MLookupInfo>(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) 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); 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,"); StringBuilder realSQL = new StringBuilder ("SELECT NULL, AD_Ref_List.Value,");
MClient client = MClient.get(Env.getCtx()); 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 101,101, MQuery.getEqualQuery("AD_Reference_ID", AD_Reference_Value_ID)); // Zoom Window+Query
info.QueryDirect = directSql; info.QueryDirect = directSql;
s_cacheRefList.put(key.toString(), info.cloneIt());
return info; return info;
} // getLookup_List } // getLookup_List

View File

@ -230,13 +230,22 @@ public class MLookupInfo implements Serializable, Cloneable
try try
{ {
MLookupInfo clone = (MLookupInfo)super.clone(); MLookupInfo clone = (MLookupInfo)super.clone();
clone.parsedValidationCode = "";
clone.IsValidated = false;
clone.ctx = null;
if (ZoomQuery != null)
clone.ZoomQuery = ZoomQuery.clone();
return clone; return clone;
} }
catch (Exception e) catch (CloneNotSupportedException e)
{ {
CLogger.get().log(Level.SEVERE, "", e); throw new RuntimeException(e);
} }
return null;
} // clone } // clone
@Override
public MLookupInfo clone() {
return cloneIt();
}
} // MLookupInfo } // MLookupInfo

View File

@ -44,7 +44,7 @@ import org.compiere.util.ValueNamePair;
* <li>BF [ 2860022 ] MQuery.get() is generating restrictions for non-existent column * <li>BF [ 2860022 ] MQuery.get() is generating restrictions for non-existent column
* https://sourceforge.net/tracker/?func=detail&aid=2860022&group_id=176962&atid=879332 * 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() { public MQuery getReportProcessQuery() {
return m_reportProcessQuery; 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 } // MQuery
/***************************************************************************** /*****************************************************************************