IDEMPIERE-635 Reference validation behaving different than Dynamic Validation.

This commit is contained in:
Heng Sin Low 2013-02-20 20:08:30 +08:00
parent d8e7b6ee67
commit 4c6032b193
1 changed files with 23 additions and 20 deletions

View File

@ -24,7 +24,6 @@ import java.util.Properties;
import java.util.logging.Level; import java.util.logging.Level;
import org.compiere.util.CCache; import org.compiere.util.CCache;
import org.compiere.util.CLogMgt;
import org.compiere.util.CLogger; import org.compiere.util.CLogger;
import org.compiere.util.DB; import org.compiere.util.DB;
import org.compiere.util.DisplayType; import org.compiere.util.DisplayType;
@ -211,7 +210,6 @@ public class MLookupFactory
// Variables in SQL WHERE // Variables in SQL WHERE
if (info.Query.indexOf('@') != -1) if (info.Query.indexOf('@') != -1)
{ {
// String newSQL = Env.parseContext(ctx, WindowNo, info.Query, false);
String newSQL = Env.parseContext(ctx, 0, info.Query, false); // only global String newSQL = Env.parseContext(ctx, 0, info.Query, false); // only global
if (newSQL.length() == 0) if (newSQL.length() == 0)
{ {
@ -219,26 +217,23 @@ public class MLookupFactory
return null; return null;
} }
info.Query = newSQL; info.Query = newSQL;
s_log.fine("getLookupInfo, newSQL ="+newSQL); //jz if (s_log.isLoggable(Level.FINE))
s_log.fine("getLookupInfo, newSQL ="+newSQL); //jz
} }
// Direct Query - NO Validation/Security // Direct Query - NO Validation/Security
int posOrder = info.Query.lastIndexOf(" ORDER BY "); if (info.QueryDirect.indexOf('@') != -1)
boolean hasWhere = info.Query.lastIndexOf(" WHERE ") != -1;
if (hasWhere) // might be for a select sub-query
{ {
// SELECT (SELECT .. FROM .. WHERE ..) FROM .. String newSQL = Env.parseContext(ctx, 0, info.QueryDirect, false); // only global
// SELECT .. FROM .. WHERE EXISTS (SELECT .. FROM .. WHERE ..) if (newSQL.length() == 0)
AccessSqlParser asp = new AccessSqlParser(info.Query); {
String mainQuery = asp.getMainSql(); s_log.severe ("SQL parse error: " + info.QueryDirect);
hasWhere = mainQuery.indexOf(" WHERE ") != -1; return null;
}
info.QueryDirect = newSQL;
if (s_log.isLoggable(Level.FINE))
s_log.fine("getLookupInfo, newSQL ="+newSQL); //jz
} }
if (posOrder == -1)
info.QueryDirect = info.Query
+ (hasWhere ? " AND " : " WHERE ") + info.KeyColumn + "=?";
else
info.QueryDirect = info.Query.substring(0, posOrder)
+ (hasWhere ? " AND " : " WHERE ") + info.KeyColumn + "=?";
// Validation // Validation
//String local_validationCode = ""; //String local_validationCode = "";
@ -366,7 +361,8 @@ public class MLookupFactory
MLookupInfo retValue = (MLookupInfo)s_cacheRefTable.get(key.toString()); MLookupInfo retValue = (MLookupInfo)s_cacheRefTable.get(key.toString());
if (retValue != null) if (retValue != null)
{ {
s_log.finest("Cache: " + retValue); if (s_log.isLoggable(Level.FINEST))
s_log.finest("Cache: " + retValue);
return retValue.cloneIt(); return retValue.cloneIt();
} }
// //
@ -519,6 +515,8 @@ public class MLookupFactory
realSQL.append(" FROM ").append(TableName); realSQL.append(" FROM ").append(TableName);
} }
String directQuery = realSQL.toString() + " WHERE " + KeyColumn + "=?";
// add WHERE clause // add WHERE clause
MQuery zoomQuery = null; MQuery zoomQuery = null;
if (WhereClause != null && WhereClause.length() > 0) if (WhereClause != null && WhereClause.length() > 0)
@ -552,7 +550,8 @@ public class MLookupFactory
else else
realSQL.append(" ORDER BY 3"); realSQL.append(" ORDER BY 3");
s_log.finest("AD_Reference_Value_ID=" + AD_Reference_Value_ID + " - " + realSQL); if (s_log.isLoggable(Level.FINEST))
s_log.finest("AD_Reference_Value_ID=" + AD_Reference_Value_ID + " - " + realSQL);
if (overrideZoomWindow > 0) if (overrideZoomWindow > 0)
{ {
ZoomWindow = overrideZoomWindow; ZoomWindow = overrideZoomWindow;
@ -563,6 +562,7 @@ public class MLookupFactory
msginf.toString(), ZoomWindow, ZoomWindowPO, zoomQuery); msginf.toString(), ZoomWindow, ZoomWindowPO, zoomQuery);
retValue.DisplayColumn = lookupDisplayColumn; retValue.DisplayColumn = lookupDisplayColumn;
retValue.InfoWindowId = infoWindowId; retValue.InfoWindowId = infoWindowId;
retValue.QueryDirect = directQuery;
s_cacheRefTable.put(key.toString(), retValue.cloneIt()); s_cacheRefTable.put(key.toString(), retValue.cloneIt());
return retValue; return retValue;
} // getLookup_Table } // getLookup_Table
@ -749,17 +749,20 @@ public class MLookupFactory
{ {
realSQL.append(" FROM ").append(TableName); realSQL.append(" FROM ").append(TableName);
} }
String directQuery = realSQL.toString() + " WHERE " + KeyColumn + "=?";
// Order by Display // Order by Display
realSQL.append(" ORDER BY 3"); realSQL.append(" ORDER BY 3");
MQuery zoomQuery = null; // corrected in VLookup MQuery zoomQuery = null; // corrected in VLookup
if (CLogMgt.isLevelFinest()) if (s_log.isLoggable(Level.FINE))
s_log.fine("ColumnName=" + ColumnName + " - " + realSQL); s_log.fine("ColumnName=" + ColumnName + " - " + realSQL);
StringBuilder msginf = new StringBuilder().append(TableName).append(".").append(KeyColumn); StringBuilder msginf = new StringBuilder().append(TableName).append(".").append(KeyColumn);
MLookupInfo lInfo = new MLookupInfo(realSQL.toString(), TableName, MLookupInfo lInfo = new MLookupInfo(realSQL.toString(), TableName,
msginf.toString(), ZoomWindow, ZoomWindowPO, zoomQuery); msginf.toString(), ZoomWindow, ZoomWindowPO, zoomQuery);
lInfo.DisplayColumn = displayColumn.toString(); lInfo.DisplayColumn = displayColumn.toString();
lInfo.QueryDirect = directQuery;
s_cacheRefTable.put(cacheKey.toString(), lInfo.cloneIt()); s_cacheRefTable.put(cacheKey.toString(), lInfo.cloneIt());
return lInfo; return lInfo;
} // getLookup_TableDir } // getLookup_TableDir