From cf40117547766227c99ef64f4e285be586cd8801 Mon Sep 17 00:00:00 2001 From: Heng Sin Low Date: Tue, 20 Feb 2007 13:23:47 +0000 Subject: [PATCH] * [ 1659623 ] MLookups & ValidationCode are not working * Added lookupinfo cache for lookup type of tabledir --- dbPort/src/org/compiere/model/MLookup.java | 19 ++++++++++++++++--- .../org/compiere/model/MLookupFactory.java | 19 ++++++++++++++----- .../src/org/compiere/model/MLookupInfo.java | 1 + 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/dbPort/src/org/compiere/model/MLookup.java b/dbPort/src/org/compiere/model/MLookup.java index 7b54d9b442..de6778816e 100644 --- a/dbPort/src/org/compiere/model/MLookup.java +++ b/dbPort/src/org/compiere/model/MLookup.java @@ -341,10 +341,13 @@ public final class MLookup extends Lookup implements Serializable refresh (loadParent); // already validation included - if (m_info.IsValidated) + //if (m_info.IsValidated) + boolean validated = this.isValidated(m_info); + if (validated) return new ArrayList(m_lookup.values()); - if (!m_info.IsValidated && onlyValidated) + //if (!m_info.IsValidated && onlyValidated) + if (!validated && onlyValidated) { refresh (loadParent); log.fine(m_info.KeyColumn + ": Validated - #" + m_lookup.size()); @@ -576,6 +579,15 @@ public final class MLookup extends Lookup implements Serializable m_lookupDirect.clear(); } // removeAllElements + private boolean isValidated(MLookupInfo info) + { + if (info.IsValidated) return true; + if (info.ValidationCode.length() == 0) return true; + String validation = Env.parseContext(m_info.ctx, m_info.WindowNo, m_info.ValidationCode, false); + if (validation.equals(info.parsedValidationCode)) return true; + return false; + } + /************************************************************************** * MLookup Loader */ @@ -613,6 +625,7 @@ public final class MLookup extends Lookup implements Serializable } else { + m_info.parsedValidationCode = validation; log.fine(m_info.KeyColumn + ": Loader Validated: " + validation); int posFrom = sql.lastIndexOf(" FROM "); boolean hasWhere = sql.indexOf(" WHERE ", posFrom) != -1; @@ -642,7 +655,7 @@ public final class MLookup extends Lookup implements Serializable Env.setContext(m_info.ctx, Env.WINDOW_MLOOKUP, m_info.Column_ID, m_info.KeyColumn, sql); if (CLogMgt.isLevelFinest()) log.fine(m_info.KeyColumn + ": " + sql); - + // Reset m_lookup.clear(); boolean isNumber = m_info.KeyColumn.endsWith("_ID"); diff --git a/dbPort/src/org/compiere/model/MLookupFactory.java b/dbPort/src/org/compiere/model/MLookupFactory.java index 9b9da8cbda..73112da08d 100644 --- a/dbPort/src/org/compiere/model/MLookupFactory.java +++ b/dbPort/src/org/compiere/model/MLookupFactory.java @@ -216,18 +216,22 @@ public class MLookupFactory + (hasWhere ? " AND " : " WHERE ") + info.KeyColumn + "=?"; // Validation - String local_validationCode = ""; + //String local_validationCode = ""; if (info.ValidationCode.length() == 0) info.IsValidated = true; + else { + /* local_validationCode = Env.parseContext (ctx, WindowNo, info.ValidationCode, true); if (local_validationCode.length() == 0) // returns "" if not all variables were parsed info.IsValidated = false; else info.IsValidated = true; + */ + info.IsValidated = false; } - + /* // Add Local Validation if (local_validationCode.length() != 0) { @@ -239,7 +243,7 @@ public class MLookupFactory else info.Query = info.Query + (hasWhere ? " AND " : " WHERE ") + local_validationCode; - } + }*/ // Add Security if (needToAddSecurity) @@ -554,9 +558,15 @@ public class MLookupFactory ColumnName = "AD_Org_ID"; String TableName = ColumnName.substring(0,ColumnName.length()-3); + String KeyColumn = ColumnName; boolean isSOTrx = !"N".equals(Env.getContext(ctx, WindowNo, "IsSOTrx")); int ZoomWindow = 0; int ZoomWindowPO = 0; + + //try cache + String cacheKey = TableName + "." + KeyColumn; + if (s_cacheRefTable.containsKey(cacheKey)) + return s_cacheRefTable.get(cacheKey).cloneIt(); // get display column names String sql0 = "SELECT c.ColumnName,c.IsTranslated,c.AD_Reference_ID," @@ -567,8 +577,6 @@ public class MLookupFactory + " AND c.IsIdentifier='Y' " + "ORDER BY c.SeqNo"; // - String KeyColumn = ColumnName; - // ArrayList list = new ArrayList(); boolean isTranslated = false; // @@ -674,6 +682,7 @@ public class MLookupFactory s_log.fine("ColumnName=" + ColumnName + " - " + realSQL); MLookupInfo lInfo = new MLookupInfo(realSQL.toString(), TableName, TableName + "." + KeyColumn, ZoomWindow, ZoomWindowPO, zoomQuery); + s_cacheRefTable.put(cacheKey, lInfo.cloneIt()); return lInfo; } // getLookup_TableDir diff --git a/dbPort/src/org/compiere/model/MLookupInfo.java b/dbPort/src/org/compiere/model/MLookupInfo.java index e683fc19c4..dd8331934c 100644 --- a/dbPort/src/org/compiere/model/MLookupInfo.java +++ b/dbPort/src/org/compiere/model/MLookupInfo.java @@ -95,6 +95,7 @@ public class MLookupInfo implements Serializable, Cloneable /** CreadedBy?updatedBy */ public boolean IsCreadedUpdatedBy = false; + public String parsedValidationCode = ""; /** * String representation