IDEMPIERE-6029 Extract @SQL= and @SQLFIND= to constant (#2230)

This commit is contained in:
hengsin 2024-02-08 17:38:28 +08:00 committed by Carlos Ruiz
parent 7224009efc
commit 6302f6f5fd
22 changed files with 94 additions and 55 deletions

View File

@ -304,7 +304,7 @@ public class GridField
Evaluator.parseDepends(list, m_vo.ReadOnlyLogic);
Evaluator.parseDepends(list, m_vo.MandatoryLogic);
// Virtual UI Column
if (m_vo.ColumnSQL != null && m_vo.ColumnSQL.length() > 0 && m_vo.ColumnSQL.startsWith("@SQL="))
if (m_vo.ColumnSQL != null && m_vo.ColumnSQL.length() > 0 && m_vo.ColumnSQL.startsWith(MColumn.VIRTUAL_UI_COLUMN_PREFIX))
Evaluator.parseDepends(list, m_vo.ColumnSQL.substring(5));
// Lookup
if (m_lookup != null)
@ -349,7 +349,7 @@ public class GridField
if (checkContext && m_vo.MandatoryLogic.length() > 0)
{
boolean retValue = false;
if (m_vo.MandatoryLogic != null && m_vo.MandatoryLogic.startsWith("@SQL=")) {
if (m_vo.MandatoryLogic != null && m_vo.MandatoryLogic.startsWith(MColumn.VIRTUAL_UI_COLUMN_PREFIX)) {
retValue = Evaluator.parseSQLLogic(m_vo.MandatoryLogic, m_vo.ctx, m_vo.WindowNo, m_vo.TabNo, m_vo.ColumnName);
} else{
@ -390,7 +390,7 @@ public class GridField
public boolean isEditablePara(boolean checkContext) {
if (checkContext && m_vo.ReadOnlyLogic.length() > 0)
{
if (m_vo.ReadOnlyLogic.startsWith("@SQL="))
if (m_vo.ReadOnlyLogic.startsWith(MColumn.VIRTUAL_UI_COLUMN_PREFIX))
{
boolean retValue = !Evaluator.parseSQLLogic(m_vo.ReadOnlyLogic, m_vo.ctx, m_vo.WindowNo, m_vo.TabNo, m_vo.ColumnName);
if (!retValue)
@ -462,7 +462,7 @@ public class GridField
if (checkContext && m_vo.AlwaysUpdatableLogic.length() > 0)
{
boolean isAlwaysUpdatable = false;
if (m_vo.AlwaysUpdatableLogic.startsWith("@SQL=")) {
if (m_vo.AlwaysUpdatableLogic.startsWith(MColumn.VIRTUAL_UI_COLUMN_PREFIX)) {
isAlwaysUpdatable = Evaluator.parseSQLLogic(m_vo.AlwaysUpdatableLogic, ctx, m_vo.WindowNo,
m_vo.TabNo, m_vo.ColumnName);
} else {
@ -543,7 +543,7 @@ public class GridField
// Do we have a readonly rule
if (checkContext && m_vo.ReadOnlyLogic.length() > 0)
{
if (m_vo.ReadOnlyLogic.startsWith("@SQL="))
if (m_vo.ReadOnlyLogic.startsWith(MColumn.VIRTUAL_UI_COLUMN_PREFIX))
{
boolean retValue = !Evaluator.parseSQLLogic(m_vo.ReadOnlyLogic, ctx, m_vo.WindowNo, m_vo.TabNo, m_vo.ColumnName);
if (!retValue)
@ -821,7 +821,7 @@ public class GridField
* (b) SQL Statement (for data integity & consistency)
*/
String defStr = "";
if (m_vo.DefaultValue != null && m_vo.DefaultValue.startsWith("@SQL="))
if (m_vo.DefaultValue != null && m_vo.DefaultValue.startsWith(MColumn.VIRTUAL_UI_COLUMN_PREFIX))
{
String sql = m_vo.DefaultValue.substring(5); // w/o tag
//hengsin, capture unparseable error to avoid subsequent sql exception
@ -878,7 +878,7 @@ public class GridField
/**
* (c) Field DefaultValue === similar code in AStartRPDialog.getDefault ===
*/
if (m_vo.DefaultValue != null && !m_vo.DefaultValue.equals("") && !m_vo.DefaultValue.startsWith("@SQL="))
if (m_vo.DefaultValue != null && !m_vo.DefaultValue.equals("") && !m_vo.DefaultValue.startsWith(MColumn.VIRTUAL_UI_COLUMN_PREFIX))
{
String defStr = ""; // problem is with texts like 'sss;sss'
// It is one or more variables/constants
@ -1297,7 +1297,7 @@ public class GridField
// ** dynamic content **
if (checkContext)
{
if (m_vo.DisplayLogic.startsWith("@SQL=")) {
if (m_vo.DisplayLogic.startsWith(MColumn.VIRTUAL_UI_COLUMN_PREFIX)) {
return Evaluator.parseSQLLogic(m_vo.DisplayLogic, m_vo.ctx, m_vo.WindowNo, m_vo.TabNo, m_vo.ColumnName);
}
Evaluatee evaluatee = new Evaluatee() {
@ -1342,7 +1342,7 @@ public class GridField
// ** dynamic content **
if (checkContext)
{
if (m_vo.DisplayLogic.startsWith("@SQL=")) {
if (m_vo.DisplayLogic.startsWith(MColumn.VIRTUAL_UI_COLUMN_PREFIX)) {
return Evaluator.parseSQLLogic(m_vo.DisplayLogic, ctx, m_vo.WindowNo, m_vo.TabNo, m_vo.ColumnName);
}
Evaluatee evaluatee = new Evaluatee() {
@ -1434,7 +1434,7 @@ public class GridField
if (m_vo.ColumnSQL != null && m_vo.ColumnSQL.length() > 0)
{
String query;
if (m_vo.ColumnSQL.startsWith("@SQL=") || m_vo.ColumnSQL.startsWith("@SQLFIND="))
if (m_vo.ColumnSQL.startsWith(MColumn.VIRTUAL_UI_COLUMN_PREFIX) || m_vo.ColumnSQL.startsWith(MColumn.VIRTUAL_SEARCH_COLUMN_PREFIX))
query = "NULL";
else
query = m_vo.ColumnSQL;
@ -1455,9 +1455,9 @@ public class GridField
if (m_vo.ColumnSQL != null && m_vo.ColumnSQL.length() > 0)
{
String query;
if (m_vo.ColumnSQL.startsWith("@SQL="))
if (m_vo.ColumnSQL.startsWith(MColumn.VIRTUAL_UI_COLUMN_PREFIX))
query = "NULL";
else if (m_vo.ColumnSQL.startsWith("@SQLFIND="))
else if (m_vo.ColumnSQL.startsWith(MColumn.VIRTUAL_SEARCH_COLUMN_PREFIX))
query = m_vo.ColumnSQL.substring(9);
else
query = m_vo.ColumnSQL;
@ -1481,7 +1481,7 @@ public class GridField
*/
public boolean isVirtualDBColumn()
{
return (m_vo.ColumnSQL != null && m_vo.ColumnSQL.length() > 0 && !m_vo.ColumnSQL.startsWith("@SQL="));
return (m_vo.ColumnSQL != null && m_vo.ColumnSQL.length() > 0 && !m_vo.ColumnSQL.startsWith(MColumn.VIRTUAL_UI_COLUMN_PREFIX));
} // isVirtualDBColumn
/**
@ -1490,7 +1490,7 @@ public class GridField
*/
public boolean isVirtualUIColumn()
{
return (m_vo.ColumnSQL != null && m_vo.ColumnSQL.length() > 0 && m_vo.ColumnSQL.startsWith("@SQL="));
return (m_vo.ColumnSQL != null && m_vo.ColumnSQL.length() > 0 && m_vo.ColumnSQL.startsWith(MColumn.VIRTUAL_UI_COLUMN_PREFIX));
} // isVirtualUIColumn
/**
@ -1499,7 +1499,7 @@ public class GridField
*/
public boolean isVirtualSearchColumn()
{
return (m_vo.ColumnSQL != null && m_vo.ColumnSQL.length() > 0 && m_vo.ColumnSQL.startsWith("@SQLFIND="));
return (m_vo.ColumnSQL != null && m_vo.ColumnSQL.length() > 0 && m_vo.ColumnSQL.startsWith(MColumn.VIRTUAL_SEARCH_COLUMN_PREFIX));
} // isVirtualDBColumn
/**

View File

@ -280,7 +280,7 @@ public class GridFieldVO implements Serializable, Cloneable
vo.IsQuickForm = "Y".equals(rs.getString ("IsQuickForm"));
{
vo.ColumnSQL = rs.getString("ColumnSQL");
if (vo.ColumnSQL != null && !vo.ColumnSQL.startsWith("@SQL=") && !vo.ColumnSQL.startsWith("@SQLFIND=") && vo.ColumnSQL.contains("@")) {
if (vo.ColumnSQL != null && !vo.ColumnSQL.startsWith(MColumn.VIRTUAL_UI_COLUMN_PREFIX) && !vo.ColumnSQL.startsWith(MColumn.VIRTUAL_SEARCH_COLUMN_PREFIX) && vo.ColumnSQL.contains("@")) {
// NOTE: cannot use window context because this is set globally on the query, not per record
vo.ColumnSQL = Env.parseContext(ctx, -1, vo.ColumnSQL, false, true);
}

View File

@ -217,7 +217,7 @@ public class InfoRelatedVO implements Serializable, Cloneable, IInfoColumn {
if (Util.isEmpty(getDisplayLogic()))
return true;
if (getDisplayLogic().startsWith("@SQL=")) {
if (getDisplayLogic().startsWith(MColumn.VIRTUAL_UI_COLUMN_PREFIX)) {
return Evaluator.parseSQLLogic(DisplayLogic, ctx, WindowNo, 0, infoRelated.toString());
}
Evaluatee evaluatee = new Evaluatee() {

View File

@ -66,7 +66,7 @@ public class LookupDisplayColumn implements Serializable
IsTranslated = isTranslated;
DisplayType = ad_Reference_ID;
AD_Reference_ID = ad_Reference_Value_ID;
if (columnSQL != null && columnSQL.length() > 0 && (columnSQL.startsWith("@SQL=") || columnSQL.startsWith("@SQLFIND=")))
if (columnSQL != null && columnSQL.length() > 0 && (columnSQL.startsWith(MColumn.VIRTUAL_UI_COLUMN_PREFIX) || columnSQL.startsWith(MColumn.VIRTUAL_SEARCH_COLUMN_PREFIX)))
ColumnSQL = "NULL";
else
ColumnSQL = columnSQL;

View File

@ -51,6 +51,10 @@ import org.idempiere.expression.logic.LogicEvaluator;
*/
public class MColumn extends X_AD_Column implements ImmutablePOSupport
{
public static final String VIRTUAL_SEARCH_COLUMN_PREFIX = "@SQLFIND=";
public static final String VIRTUAL_UI_COLUMN_PREFIX = "@SQL=";
/**
* generated serial id
*/
@ -311,7 +315,7 @@ public class MColumn extends X_AD_Column implements ImmutablePOSupport
public boolean isVirtualDBColumn()
{
String s = getColumnSQL();
return s != null && s.length() > 0 && !s.startsWith("@SQL=");
return s != null && s.length() > 0 && !s.startsWith(VIRTUAL_UI_COLUMN_PREFIX) && !s.startsWith(VIRTUAL_SEARCH_COLUMN_PREFIX);
} // isVirtualDBColumn
/**
@ -321,7 +325,7 @@ public class MColumn extends X_AD_Column implements ImmutablePOSupport
public boolean isVirtualUIColumn()
{
String s = getColumnSQL();
return s != null && s.length() > 0 && s.startsWith("@SQL=");
return s != null && s.length() > 0 && s.startsWith(VIRTUAL_UI_COLUMN_PREFIX);
} // isVirtualUIColumn
/**
@ -331,7 +335,7 @@ public class MColumn extends X_AD_Column implements ImmutablePOSupport
public boolean isVirtualSearchColumn()
{
String s = getColumnSQL();
return s != null && s.length() > 0 && s.startsWith("@SQLFIND=");
return s != null && s.length() > 0 && s.startsWith(VIRTUAL_SEARCH_COLUMN_PREFIX);
} // isVirtualSearchColumn
/**
@ -540,7 +544,7 @@ public class MColumn extends X_AD_Column implements ImmutablePOSupport
//validate readonly logic expression
if (newRecord || is_ValueChanged(COLUMNNAME_ReadOnlyLogic)) {
if (isActive() && !Util.isEmpty(getReadOnlyLogic(), true) && !getReadOnlyLogic().startsWith("@SQL=")) {
if (isActive() && !Util.isEmpty(getReadOnlyLogic(), true) && !getReadOnlyLogic().startsWith(VIRTUAL_UI_COLUMN_PREFIX)) {
LogicEvaluator.validate(getReadOnlyLogic());
}
}
@ -1375,11 +1379,11 @@ public class MColumn extends X_AD_Column implements ImmutablePOSupport
public String getColumnSQL(boolean nullForUI, boolean nullForSearch) {
String query = getColumnSQL();
if (query != null && query.length() > 0) {
if (query.startsWith("@SQL=") && nullForUI)
if (query.startsWith(VIRTUAL_UI_COLUMN_PREFIX) && nullForUI)
query = "NULL";
else if (query.startsWith("@SQLFIND=") && nullForSearch)
else if (query.startsWith(VIRTUAL_SEARCH_COLUMN_PREFIX) && nullForSearch)
query = "NULL";
else if (query.startsWith("@SQLFIND=") && !nullForSearch)
else if (query.startsWith(VIRTUAL_SEARCH_COLUMN_PREFIX) && !nullForSearch)
query = query.substring(9);
}
return query;

View File

@ -236,17 +236,17 @@ public class MField extends X_AD_Field implements ImmutablePOSupport
//validate logic expression
if (newRecord || is_ValueChanged(COLUMNNAME_ReadOnlyLogic)) {
if (isActive() && !Util.isEmpty(getReadOnlyLogic(), true) && !getReadOnlyLogic().startsWith("@SQL=")) {
if (isActive() && !Util.isEmpty(getReadOnlyLogic(), true) && !getReadOnlyLogic().startsWith(MColumn.VIRTUAL_UI_COLUMN_PREFIX)) {
LogicEvaluator.validate(getReadOnlyLogic());
}
}
if (newRecord || is_ValueChanged(COLUMNNAME_DisplayLogic)) {
if (isActive() && !Util.isEmpty(getDisplayLogic(), true) && !getDisplayLogic().startsWith("@SQL=")) {
if (isActive() && !Util.isEmpty(getDisplayLogic(), true) && !getDisplayLogic().startsWith(MColumn.VIRTUAL_UI_COLUMN_PREFIX)) {
LogicEvaluator.validate(getDisplayLogic());
}
}
if (newRecord || is_ValueChanged(COLUMNNAME_MandatoryLogic)) {
if (isActive() && !Util.isEmpty(getMandatoryLogic(), true) && !getMandatoryLogic().startsWith("@SQL=")) {
if (isActive() && !Util.isEmpty(getMandatoryLogic(), true) && !getMandatoryLogic().startsWith(MColumn.VIRTUAL_UI_COLUMN_PREFIX)) {
LogicEvaluator.validate(getMandatoryLogic());
}
}

View File

@ -436,7 +436,7 @@ public class MLookupFactory
ZoomWindow = rs.getInt(8);
ZoomWindowPO = rs.getInt(9);
displayColumnSQL = rs.getString(11);
if (displayColumnSQL != null && displayColumnSQL.length() > 0 && (displayColumnSQL.startsWith("@SQL=") || displayColumnSQL.startsWith("@SQLFIND=")))
if (displayColumnSQL != null && displayColumnSQL.length() > 0 && (displayColumnSQL.startsWith(MColumn.VIRTUAL_UI_COLUMN_PREFIX) || displayColumnSQL.startsWith(MColumn.VIRTUAL_SEARCH_COLUMN_PREFIX)))
displayColumnSQL = "NULL";
if (displayColumnSQL != null && displayColumnSQL.contains("@"))
displayColumnSQL = Env.parseContext(Env.getCtx(), -1, displayColumnSQL, false, true);

View File

@ -358,12 +358,12 @@ public class MProcessPara extends X_AD_Process_Para implements ImmutablePOSuppor
//validate logic expression
if (newRecord || is_ValueChanged(COLUMNNAME_ReadOnlyLogic)) {
if (isActive() && !Util.isEmpty(getReadOnlyLogic(), true) && !getReadOnlyLogic().startsWith("@SQL=")) {
if (isActive() && !Util.isEmpty(getReadOnlyLogic(), true) && !getReadOnlyLogic().startsWith(MColumn.VIRTUAL_UI_COLUMN_PREFIX)) {
LogicEvaluator.validate(getReadOnlyLogic());
}
}
if (newRecord || is_ValueChanged(COLUMNNAME_DisplayLogic)) {
if (isActive() && !Util.isEmpty(getDisplayLogic(), true) && !getDisplayLogic().startsWith("@SQL=")) {
if (isActive() && !Util.isEmpty(getDisplayLogic(), true) && !getDisplayLogic().startsWith(MColumn.VIRTUAL_UI_COLUMN_PREFIX)) {
LogicEvaluator.validate(getDisplayLogic());
}
}

View File

@ -213,17 +213,17 @@ public class MUserDefField extends X_AD_UserDef_Field implements ImmutablePOSupp
//validate logic expression
if (newRecord || is_ValueChanged(COLUMNNAME_ReadOnlyLogic)) {
if (isActive() && !Util.isEmpty(getReadOnlyLogic(), true) && !getReadOnlyLogic().startsWith("@SQL=")) {
if (isActive() && !Util.isEmpty(getReadOnlyLogic(), true) && !getReadOnlyLogic().startsWith(MColumn.VIRTUAL_UI_COLUMN_PREFIX)) {
LogicEvaluator.validate(getReadOnlyLogic());
}
}
if (newRecord || is_ValueChanged(COLUMNNAME_DisplayLogic)) {
if (isActive() && !Util.isEmpty(getDisplayLogic(), true) && !getDisplayLogic().startsWith("@SQL=")) {
if (isActive() && !Util.isEmpty(getDisplayLogic(), true) && !getDisplayLogic().startsWith(MColumn.VIRTUAL_UI_COLUMN_PREFIX)) {
LogicEvaluator.validate(getDisplayLogic());
}
}
if (newRecord || is_ValueChanged(COLUMNNAME_MandatoryLogic)) {
if (isActive() && !Util.isEmpty(getMandatoryLogic(), true) && !getMandatoryLogic().startsWith("@SQL=")) {
if (isActive() && !Util.isEmpty(getMandatoryLogic(), true) && !getMandatoryLogic().startsWith(MColumn.VIRTUAL_UI_COLUMN_PREFIX)) {
LogicEvaluator.validate(getMandatoryLogic());
}
}

View File

@ -340,7 +340,7 @@ public class MUserQuery extends X_AD_UserQuery
get_Value(COLUMNNAME_AD_User_ID) == null) //Cannot save privately (user-specific) an already existing global query
return false;
return !getCode().startsWith("@SQL=");
return !getCode().startsWith(MColumn.VIRTUAL_UI_COLUMN_PREFIX);
}
/**
@ -353,7 +353,7 @@ public class MUserQuery extends X_AD_UserQuery
getAD_Client_ID() != Env.getAD_Client_ID(Env.getCtx())) //Cannot modify a query from another client (e.g. System)
return false;
return !getCode().startsWith("@SQL=");
return !getCode().startsWith(MColumn.VIRTUAL_UI_COLUMN_PREFIX);
}
} // MUserQuery

View File

@ -202,7 +202,7 @@ public class POInfo implements Serializable
//
m_AccessLevel = rs.getString(18);
String ColumnSQL = rs.getString(19);
if (ColumnSQL != null && ColumnSQL.length() > 0 && (ColumnSQL.startsWith("@SQL=") || ColumnSQL.startsWith("@SQLFIND=")))
if (ColumnSQL != null && ColumnSQL.length() > 0 && (ColumnSQL.startsWith(MColumn.VIRTUAL_UI_COLUMN_PREFIX) || ColumnSQL.startsWith(MColumn.VIRTUAL_SEARCH_COLUMN_PREFIX)))
ColumnSQL = "NULL";
if (ColumnSQL != null && ColumnSQL.contains("@"))
ColumnSQL = Env.parseContext(Env.getCtx(), -1, ColumnSQL, false, true);
@ -381,7 +381,7 @@ public class POInfo implements Serializable
if (index < 0 || index >= m_columns.length)
return null;
if (m_columns[index].ColumnSQL != null && m_columns[index].ColumnSQL.length() > 0) {
if (m_columns[index].ColumnSQL.startsWith("@SQL=") || m_columns[index].ColumnSQL.startsWith("@SQLFIND="))
if (m_columns[index].ColumnSQL.startsWith(MColumn.VIRTUAL_UI_COLUMN_PREFIX) || m_columns[index].ColumnSQL.startsWith(MColumn.VIRTUAL_SEARCH_COLUMN_PREFIX))
return "NULL AS " + m_columns[index].ColumnName;
return m_columns[index].ColumnSQL + " AS " + m_columns[index].ColumnName;
}
@ -412,7 +412,7 @@ public class POInfo implements Serializable
return true;
return m_columns[index].ColumnSQL != null
&& m_columns[index].ColumnSQL.length() > 0
&& !m_columns[index].ColumnSQL.startsWith("@SQL=");
&& !m_columns[index].ColumnSQL.startsWith(MColumn.VIRTUAL_UI_COLUMN_PREFIX);
} // isVirtualDBColumn
/**
@ -426,7 +426,7 @@ public class POInfo implements Serializable
return true;
return m_columns[index].ColumnSQL != null
&& m_columns[index].ColumnSQL.length() > 0
&& m_columns[index].ColumnSQL.startsWith("@SQL=");
&& m_columns[index].ColumnSQL.startsWith(MColumn.VIRTUAL_UI_COLUMN_PREFIX);
} // isVirtualUIColumn
/**
@ -440,7 +440,7 @@ public class POInfo implements Serializable
return true;
return m_columns[index].ColumnSQL != null
&& m_columns[index].ColumnSQL.length() > 0
&& m_columns[index].ColumnSQL.startsWith("@SQLFIND=");
&& m_columns[index].ColumnSQL.startsWith(MColumn.VIRTUAL_SEARCH_COLUMN_PREFIX);
} // isVirtualSearchColumn
/**

View File

@ -34,6 +34,7 @@ import java.util.logging.Level;
import java.util.regex.Pattern;
import org.adempiere.exceptions.AdempiereException;
import org.compiere.model.MColumn;
import org.compiere.model.MLookupFactory;
import org.compiere.model.MQuery;
import org.compiere.model.MReportView;
@ -340,9 +341,9 @@ public class DataEngine
int AD_PrintFormatItem_ID = rs.getInt("AD_PrintFormatItem_ID");
String ColumnName = rs.getString(2);
String ColumnSQL = rs.getString(24);
if (ColumnSQL != null && ColumnSQL.length() > 0 && ColumnSQL.startsWith("@SQLFIND="))
if (ColumnSQL != null && ColumnSQL.length() > 0 && ColumnSQL.startsWith(MColumn.VIRTUAL_SEARCH_COLUMN_PREFIX))
ColumnSQL = ColumnSQL.substring(9);
if (ColumnSQL != null && ColumnSQL.length() > 0 && ColumnSQL.startsWith("@SQL="))
if (ColumnSQL != null && ColumnSQL.length() > 0 && ColumnSQL.startsWith(MColumn.VIRTUAL_UI_COLUMN_PREFIX))
ColumnSQL = "NULL";
if (ColumnSQL != null && ColumnSQL.contains("@"))
ColumnSQL = Env.parseContext(Env.getCtx(), m_windowNo, ColumnSQL, false, true);
@ -424,9 +425,9 @@ public class DataEngine
// => (..) AS AName, Table.ID,
if (script != null && !script.isEmpty())
{
if (script.startsWith("@SQL="))
if (script.startsWith(MColumn.VIRTUAL_UI_COLUMN_PREFIX))
{
script = "(" + script.replace("@SQL=", "").trim() + ")";
script = "(" + script.replace(MColumn.VIRTUAL_UI_COLUMN_PREFIX, "").trim() + ")";
script = Env.parseContext(Env.getCtx(), m_windowNo, script, false);
}
else

View File

@ -39,6 +39,7 @@ import org.adempiere.base.upload.UploadResponse;
import org.compiere.model.MAttachment;
import org.compiere.model.MAuthorizationAccount;
import org.compiere.model.MClient;
import org.compiere.model.MColumn;
import org.compiere.model.MMailText;
import org.compiere.model.MNote;
import org.compiere.model.MOrgInfo;
@ -683,7 +684,7 @@ public class Scheduler extends AdempiereServer
if (variable == null
|| (variable != null && variable.length() == 0))
value = null;
else if (variable.startsWith("@SQL=")) {
else if (variable.startsWith(MColumn.VIRTUAL_UI_COLUMN_PREFIX)) {
String defStr = "";
String sql = variable.substring(5); // w/o tag
//sql = Env.parseContext(m_vo.ctx, m_vo.WindowNo, sql, false, true); // replace variables

View File

@ -17,6 +17,7 @@ import org.adempiere.base.IServiceHolder;
import org.adempiere.webui.action.Actions;
import org.adempiere.webui.action.IAction;
import org.adempiere.webui.component.ToolBarButton;
import org.compiere.model.MColumn;
import org.compiere.model.MToolBarButton;
import org.compiere.util.Env;
import org.compiere.util.Evaluatee;
@ -120,7 +121,7 @@ public class ToolbarCustomButton implements EventListener<Event>, Evaluatee {
return;
boolean visible = true;
if (displayLogic.startsWith("@SQL=")) {
if (displayLogic.startsWith(MColumn.VIRTUAL_UI_COLUMN_PREFIX)) {
ADWindow adwindow = ADWindow.get(windowNo);
if (adwindow == null)
return;
@ -200,7 +201,7 @@ public class ToolbarCustomButton implements EventListener<Event>, Evaluatee {
private boolean validateLogic(String logic, int tabNo) {
boolean isValid = false;
if (logic.startsWith("@SQL="))
if (logic.startsWith(MColumn.VIRTUAL_UI_COLUMN_PREFIX))
{
isValid = Evaluator.parseSQLLogic(logic, Env.getCtx(), windowNo, tabNo, "");
}

View File

@ -17,6 +17,7 @@ import org.adempiere.webui.editor.IProcessButton;
import org.adempiere.webui.event.ActionEvent;
import org.adempiere.webui.event.ActionListener;
import org.compiere.model.I_AD_Process;
import org.compiere.model.MColumn;
import org.compiere.model.MProcess;
import org.compiere.model.MToolBarButton;
import org.compiere.util.Env;
@ -189,7 +190,7 @@ public class ToolbarProcessButton implements IProcessButton, Evaluatee {
*/
private boolean validateLogic(String logic, int tabNo) {
boolean isValid = false;
if (logic.startsWith("@SQL=")) {
if (logic.startsWith(MColumn.VIRTUAL_UI_COLUMN_PREFIX)) {
isValid = Evaluator.parseSQLLogic(logic, Env.getCtx(), windowNo, tabNo, getColumnName());
} else {
isValid = Evaluator.evaluateLogic(this, logic);

View File

@ -64,6 +64,7 @@ import org.adempiere.webui.window.ZkReportViewerProvider;
import org.compiere.Adempiere;
import org.compiere.model.I_AD_Menu;
import org.compiere.model.MChart;
import org.compiere.model.MColumn;
import org.compiere.model.MDashboardContent;
import org.compiere.model.MDashboardContentAccess;
import org.compiere.model.MDashboardPreference;
@ -1732,7 +1733,7 @@ public class DashboardController implements EventListener<Event> {
if (paramValue == null
|| (paramValue != null && paramValue.length() == 0))
value = null;
else if (paramValue.startsWith("@SQL=")) {
else if (paramValue.startsWith(MColumn.VIRTUAL_UI_COLUMN_PREFIX)) {
String sql = paramValue.substring(5);
sql = Env.parseContext(Env.getCtx(), 0, sql, false, false); // replace variables
if (!Util.isEmpty(sql)) {

View File

@ -550,7 +550,7 @@ public class InfoGeneralPanel extends InfoPanel implements EventListener<Event>
boolean isDisplayed = rs.getString(4).equals("Y");
int AD_Reference_Value_ID = rs.getInt(5);
String columnSql = rs.getString(6);
if (columnSql != null && columnSql.length() > 0 && (columnSql.startsWith("@SQL=") || columnSql.startsWith("@SQLFIND=")))
if (columnSql != null && columnSql.length() > 0 && (columnSql.startsWith(MColumn.VIRTUAL_UI_COLUMN_PREFIX) || columnSql.startsWith(MColumn.VIRTUAL_SEARCH_COLUMN_PREFIX)))
columnSql = "NULL";
if (columnSql != null && columnSql.contains("@"))
columnSql = Env.parseContext(Env.getCtx(), -1, columnSql, false, true);

View File

@ -2052,7 +2052,7 @@ public class FindWindow extends Window implements EventListener<Event>, ValueCha
return;
String code = userQuery.getCode();
if (code.startsWith("@SQL=")) {
if (code.startsWith(MColumn.VIRTUAL_UI_COLUMN_PREFIX)) {
m_whereUserQuery = "(" + code.substring(code.indexOf("=")+1, code.length()) + ")";
if (log.isLoggable(Level.INFO))
log.log(Level.INFO, m_whereUserQuery);

View File

@ -40,6 +40,7 @@ import java.util.Map.Entry;
import java.util.logging.Level;
import org.adempiere.exceptions.AdempiereException;
import org.compiere.model.MColumn;
import org.compiere.model.MProcess;
import org.compiere.model.MProcessDrillRule;
import org.compiere.model.MProcessDrillRulePara;
@ -660,7 +661,7 @@ public class DrillReportCtl {
if (variable == null
|| (variable != null && variable.length() == 0))
value = null;
else if (variable.startsWith("@SQL=")) {
else if (variable.startsWith(MColumn.VIRTUAL_UI_COLUMN_PREFIX)) {
String defStr = "";
String sql = variable.substring(5); // w/o tag
//hengsin, capture unparseable error to avoid subsequent sql exception

View File

@ -580,7 +580,7 @@ public class LogicExpressionTest extends AbstractTestCase {
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
String expr = rs.getString(mc.getColumnName());
if (expr.startsWith("@SQL=") || expr.startsWith("SQL="))
if (expr.startsWith(MColumn.VIRTUAL_UI_COLUMN_PREFIX) || expr.startsWith("SQL="))
continue;
try {
LogicEvaluator.validate(expr);

View File

@ -43,10 +43,12 @@ import org.compiere.model.I_AD_UserPreference;
import org.compiere.model.MAcctSchema;
import org.compiere.model.MBPartner;
import org.compiere.model.MClient;
import org.compiere.model.MColumn;
import org.compiere.model.MMessage;
import org.compiere.model.MProduct;
import org.compiere.model.MProductCategory;
import org.compiere.model.MProductCategoryAcct;
import org.compiere.model.MProductionLine;
import org.compiere.model.MTest;
import org.compiere.model.POInfo;
import org.compiere.util.DB;
@ -553,4 +555,30 @@ public class POTest extends AbstractTestCase
assertTrue(file.exists(), "Not found: " + folderOr + fileName);
file.delete();
}
@Test
public void testIsVirtualColumnMethods() {
//column sql with no prefix
MColumn column = MColumn.get(Env.getCtx(), MTest.Table_Name, MTest.COLUMNNAME_TestVirtualQty);
assertTrue(column.isVirtualColumn(), "MColumn.isVirtualColumn() not working as expected for ColumnSQL="+column.getColumnSQL());
assertTrue(column.isVirtualDBColumn(), "MColumn.isVirtualDBColumn() not working as expected for ColumnSQL="+column.getColumnSQL());
assertFalse(column.isVirtualUIColumn(), "MColumn.isVirtualUIColumn() not working as expected for ColumnSQL="+column.getColumnSQL());
assertFalse(column.isVirtualSearchColumn(), "MColumn.isVirtualSearchColumn() not working as expected for ColumnSQL="+column.getColumnSQL());
//column sql with @SQLFIND= prefix
column = MColumn.get(Env.getCtx(), MProductionLine.Table_Name, "ProductType");
assertTrue(column.isVirtualColumn(), "MColumn.isVirtualColumn() not working as expected for ColumnSQL="+column.getColumnSQL());
assertFalse(column.isVirtualDBColumn(), "MColumn.isVirtualDBColumn() not working as expected for ColumnSQL="+column.getColumnSQL());
assertFalse(column.isVirtualUIColumn(), "MColumn.isVirtualUIColumn() not working as expected for ColumnSQL="+column.getColumnSQL());
assertTrue(column.isVirtualSearchColumn(), "MColumn.isVirtualSearchColumn() not working as expected for ColumnSQL="+column.getColumnSQL());
//column sql with @SQL= prefix
column = MColumn.get(Env.getCtx(), MTest.Table_Name, MTest.COLUMNNAME_TestVirtualQty);
column = new MColumn(column);
column.setColumnSQL(MColumn.VIRTUAL_UI_COLUMN_PREFIX+column.getColumnSQL());
assertTrue(column.isVirtualColumn(), "MColumn.isVirtualColumn() not working as expected for ColumnSQL="+column.getColumnSQL());
assertFalse(column.isVirtualDBColumn(), "MColumn.isVirtualDBColumn() not working as expected for ColumnSQL="+column.getColumnSQL());
assertTrue(column.isVirtualUIColumn(), "MColumn.isVirtualUIColumn() not working as expected for ColumnSQL="+column.getColumnSQL());
assertFalse(column.isVirtualSearchColumn(), "MColumn.isVirtualSearchColumn() not working as expected for ColumnSQL="+column.getColumnSQL());
}
}

View File

@ -33,6 +33,7 @@ import org.adempiere.base.equinox.EquinoxExtensionLocator;
import org.adempiere.exceptions.AdempiereException;
import org.apache.commons.codec.binary.Base64;
import org.compiere.model.Lookup;
import org.compiere.model.MColumn;
import org.compiere.model.MUser;
import org.compiere.model.PO;
import org.compiere.model.POInfo;
@ -390,7 +391,7 @@ public class AbstractService {
* @throws AdempiereException
*/
protected String parseSQL(String sql, ArrayList<Object> sqlParas, PO po,POInfo poInfo, Map<String, Object> requestCtx) throws AdempiereException {
if (sql.startsWith("@SQL="))
if (sql.startsWith(MColumn.VIRTUAL_UI_COLUMN_PREFIX))
sql = sql.substring(5);
if (sql.toLowerCase().indexOf(" where ") == -1)