Class MQuery

java.lang.Object
org.compiere.model.MQuery
All Implemented Interfaces:
Serializable, Cloneable

public class MQuery extends Object implements Serializable, Cloneable
Query Descriptor. Maintains restrictions (WHERE clause).
Version:
$Id: MQuery.java,v 1.4 2006/07/30 00:58:04 jjanke Exp $
Author:
Jorg Janke, Teo Sarca
  • BF [ 2860022 ] MQuery.get() is generating restrictions for non-existent column https://sourceforge.net/p/adempiere/bugs/2099/
  • See Also:
    • Field Details

    • Constructor Details

      • MQuery

        public MQuery()
        Constructor w/o table name
      • MQuery

        public MQuery(String TableName)
        Constructor
        Parameters:
        TableName - Table Name
      • MQuery

        public MQuery(int AD_Table_ID)
        Constructor get TableName from table id
        Parameters:
        AD_Table_ID -
    • Method Details

      • get

        public static MQuery get(Properties ctx, int AD_PInstance_ID, String TableName)
        Create new Query for report
        Parameters:
        ctx - context
        AD_PInstance_ID - process instance for report
        TableName - table name
        Returns:
        MQuery
      • getZoomColumnName

        public static String getZoomColumnName(String columnName)
        Get Zoom Column Name.
        Convert well known synonyms like SalesRep_ID to AD_User_ID.
        Parameters:
        columnName - column name
        Returns:
        zoom column name
      • getZoomTableName

        public static String getZoomTableName(String columnName)
        Derive Zoom Table Name from column name (drop _ID or _UU).
        Parameters:
        columnName - column name
        Returns:
        table name
      • getEqualQuery

        public static MQuery getEqualQuery(String columnName, Object value)
        Create simple Equal Query.
        Create restriction of columnName=value or columnName='value'
        Parameters:
        columnName - columnName
        value - value
        Returns:
        query
      • getEqualQuery

        public static MQuery getEqualQuery(String columnName, int value)
        Create simple Equal Query. Create restriction of columnName=value.
        Parameters:
        columnName - columnName
        value - value
        Returns:
        query
      • getNoRecordQuery

        public static MQuery getNoRecordQuery(String tableName, boolean newRecord)
        Create No Record query.
        Parameters:
        tableName - table name
        newRecord - new Record Indicator. if true, add restriction of "2=3", otherwise add restriction of "1-2"
        Returns:
        query
      • getZoomWindowID

        public int getZoomWindowID()
        Returns:
        zoom AD_Window_ID
      • setZoomWindowID

        public void setZoomWindowID(int m_zoomWindow_ID)
        Parameters:
        m_zoomWindow_ID - AD_Window_ID for zoom
      • getRecordCount

        public int getRecordCount()
        Get Record Count
        Returns:
        count - default 999999
      • setRecordCount

        public void setRecordCount(int count)
        Set Record Count
        Parameters:
        count - count
      • addRestriction

        public void addRestriction(String ColumnName, String Operator, Object Code, String InfoName, String InfoDisplay, boolean andCondition, int depth)
        Add Restriction
        Parameters:
        ColumnName - ColumnName
        Operator - Operator, e.g. = != ..
        Code - query value, e.g 0, All%
        InfoName - Display Name
        InfoDisplay - Display of Code (Lookup)
        andCondition - true=and, false=or
        depth - number of parenthesis
      • addRestriction

        public void addRestriction(String ColumnName, String Operator, Object Code, String InfoName, String InfoDisplay, boolean andCondition, boolean notCondition, int depth)
        Add Restriction
        Parameters:
        ColumnName - ColumnName
        Operator - Operator, e.g. = != ..
        Code - query value, e.g 0, All%
        InfoName - Display Name
        InfoDisplay - Display of Code (Lookup)
        andCondition - true=and, false=or
        notCondition - true=not
        depth - number of parenthesis
      • addRangeRestriction

        public void addRangeRestriction(String ColumnName, Object Code, Object Code_to, String InfoName, String InfoDisplay, String InfoDisplay_to, boolean andCondition, boolean notCondition, int depth)
        Add Range Restriction (BETWEEN)
        Parameters:
        ColumnName - ColumnName
        Code - from value, e.g 0, All%
        Code_to - to value, e.g 0, All%
        InfoName - Display Name
        InfoDisplay - Display of Code (Lookup)
        InfoDisplay_to - Display of Code_to (Lookup)
        andCondition - true=and, false=or
        notCondition - true=not
        depth - number of parenthesis
      • addRestriction

        public void addRestriction(String ColumnName, String Operator, Object Code, String InfoName, String InfoDisplay, String andOrCondition, int depth)
        Add Restriction
        Parameters:
        ColumnName - ColumnName
        Operator - Operator, e.g. = != ..
        Code - query value, e.g 0, All%
        InfoName - Display Name
        InfoDisplay - Display of Code (Lookup)
        andOrCondition - AND/OR/AND NOT/OR NOT - concatenation of parenthesis
        depth - number of parenthesis
      • addRestriction

        public void addRestriction(String ColumnName, String Operator, Object Code, String InfoName, String InfoDisplay)
        Add Restriction
        Parameters:
        ColumnName - ColumnName
        Operator - Operator, e.g. = != ..
        Code - query value, e.g 0, All%
        InfoName - Display Name
        InfoDisplay - Display of Code (Lookup)
      • addRestriction

        public void addRestriction(String ColumnName, String Operator, Object Code)
        Add Restriction
        Parameters:
        ColumnName - ColumnName
        Operator - Operator, e.g. = != ..
        Code - query value, e.g 0, All%
      • addRestriction

        public void addRestriction(String ColumnName, String Operator, int Code)
        Add Restriction
        Parameters:
        ColumnName - ColumnName
        Operator - Operator, e.g. = != ..
        Code - query value, e.g 0
      • addRangeRestriction

        public void addRangeRestriction(String ColumnName, Object Code, Object Code_to, String InfoName, String InfoDisplay, String InfoDisplay_to, boolean andCondition, int depth)
        Add Range Restriction (BETWEEN)
        Parameters:
        ColumnName - ColumnName
        Code - from value, e.g 0, All%
        Code_to - to value, e.g 0, All%
        InfoName - Display Name
        InfoDisplay - Display of Code (Lookup)
        InfoDisplay_to - Display of Code_to (Lookup)
        andCondition - true=and, false=or
        depth - number of parenthesis
      • addRangeRestriction

        public void addRangeRestriction(String ColumnName, Object Code, Object Code_to, String InfoName, String InfoDisplay, String InfoDisplay_to, String andOrCondition, int depth)
        Add Range Restriction (BETWEEN)
        Parameters:
        ColumnName - ColumnName
        Code - from value, e.g 0, All%
        Code_to - to value, e.g 0, All%
        InfoName - Display Name
        InfoDisplay - Display of Code (Lookup)
        InfoDisplay_to - Display of Code_to (Lookup)
        andOrCondition - AND/OR/AND NOT/OR NOT - concatenation of parenthesis
        depth - number of parenthesis
      • addRangeRestriction

        public void addRangeRestriction(String ColumnName, Object Code, Object Code_to, String InfoName, String InfoDisplay, String InfoDisplay_to)
        Add Range Restriction (BETWEEN)
        Parameters:
        ColumnName - ColumnName
        Code - from value, e.g 0, All%
        Code_to - to value, e.g 0, All%
        InfoName - Display Name
        InfoDisplay - Display of Code (Lookup)
        InfoDisplay_to - Display of Code_to (Lookup)
      • addRangeRestriction

        public void addRangeRestriction(String ColumnName, Object Code, Object Code_to)
        Add Range Restriction (BETWEEN)
        Parameters:
        ColumnName - ColumnName
        Code - from value, e.g 0, All%
        Code_to - to value, e.g 0, All%
      • addRestriction

        protected void addRestriction(org.compiere.model.Restriction r)
        Add Restriction
        Parameters:
        r - Restriction
      • addRestriction

        public void addRestriction(String whereClause, boolean andCondition, int joinDepth)
        Add Restriction
        Parameters:
        whereClause - SQL WHERE clause
        andCondition - true=and, false=or
        joinDepth - number of parenthesis
      • addRestriction

        public void addRestriction(String whereClause, boolean andCondition, boolean notCondition, int joinDepth)
        Add Restriction
        Parameters:
        whereClause - SQL WHERE clause
        andCondition - true=and, false=or
        notCondition - true=not
        joinDepth - number of parenthesis
      • addRestriction

        public void addRestriction(String whereClause, boolean andCondition, boolean notCondition, boolean existsCondition, int joinDepth)
        Add Restriction
        Parameters:
        whereClause - SQL WHERE clause
        andCondition - true=and, false=or
        notCondition - true=not
        existsCondition - true=exists
        joinDepth - number of parenthesis
      • addRestriction

        public void addRestriction(String whereClause, int joinDepth, String andOrCondition)
        Add Restriction
        Parameters:
        whereClause - SQL WHERE clause
        joinDepth - number of parenthesis
        andOrCondition -
      • addRestriction

        public void addRestriction(String whereClause)
        Add Restriction
        Parameters:
        whereClause - SQL WHERE clause
      • addRestriction

        public void addRestriction(String whereClause, String Operator, String InfoName, String InfoDisplay)
        Add restriction
        Parameters:
        whereClause -
        Operator -
        InfoName -
        InfoDisplay -
      • isNewRecordQuery

        public boolean isNewRecordQuery()
        New Record Query
        Returns:
        true if new record query
      • getWhereClause

        public String getWhereClause()
        Create the resulting Query WHERE Clause
        Returns:
        Where Clause
      • getWhereClause

        public String getWhereClause(boolean fullyQualified)
        Create the resulting Query WHERE Clause
        Parameters:
        fullyQualified - fully qualified Table.ColumnName
        Returns:
        Where Clause
      • getInfo

        public String getInfo()
        Get printable Query Info
        Returns:
        info
      • getWhereClause

        public String getWhereClause(int index)
        Create Query WHERE Clause. Not fully qualified.
        Parameters:
        index - restriction index
        Returns:
        Where Clause or "" if not valid
      • getRestrictionCount

        public int getRestrictionCount()
        Get Restriction Count
        Returns:
        number of restrictions
      • isActive

        public boolean isActive()
        Is Query Active
        Returns:
        true if number of restrictions > 0
      • getTableName

        public String getTableName()
        Get Table Name
        Returns:
        Table Name
      • setTableName

        public void setTableName(String TableName)
        Set Table Name
        Parameters:
        TableName - Table Name
      • getColumnName

        public String getColumnName(int index)
        Get ColumnName of index
        Parameters:
        index - index
        Returns:
        ColumnName or null
      • setColumnName

        protected void setColumnName(int index, String ColumnName)
        Set ColumnName of index
        Parameters:
        index - index
        ColumnName - new column name
      • getOperator

        public String getOperator(int index)
        Get Operator of index
        Parameters:
        index - index
        Returns:
        Operator or null
      • getCode

        public Object getCode(int index)
        Get Operator of index
        Parameters:
        index - index
        Returns:
        Operator or null
      • getCode_to

        public Object getCode_to(int index)
        Get Operator of index
        Parameters:
        index - index
        Returns:
        Operator or null
      • getInfoDisplay

        public String getInfoDisplay(int index)
        Get display text of index
        Parameters:
        index - index
        Returns:
        Display Text
      • getInfoDisplay_to

        public String getInfoDisplay_to(int index)
        Get display text of to restriction
        Parameters:
        index - index of restriction
        Returns:
        Display Text
      • getInfoName

        public String getInfoName(int index)
        Get Info Name
        Parameters:
        index - index
        Returns:
        Info Name
      • getInfoOperator

        public String getInfoOperator(int index)
        Get Info Operator
        Parameters:
        index - index
        Returns:
        info Operator
      • getInfoDisplayAll

        public String getInfoDisplayAll(int index)
        Get Display with optional To
        Parameters:
        index - index
        Returns:
        info display
      • toString

        public String toString()
        String representation
        Overrides:
        toString in class Object
        Returns:
        info
      • getDisplayName

        public String getDisplayName(Properties ctx)
        Get Display Name
        Parameters:
        ctx - context
        Returns:
        display Name
      • deepCopy

        public MQuery deepCopy()
        Clone Query
        Returns:
        Query
      • getAD_PInstance_ID

        public int getAD_PInstance_ID()
        Returns:
        AD_PInstance_ID; this value is set if you created this query by using get(Properties, int, String)
      • setZoomTableName

        public void setZoomTableName(String tableName)
        Parameters:
        tableName -
      • getZoomTableName

        public String getZoomTableName()
        Returns:
        zoom table name
      • setZoomColumnName

        public void setZoomColumnName(String column)
        Parameters:
        column -
      • getZoomColumnName

        public String getZoomColumnName()
        Returns:
        zoom column name
      • setZoomValue

        public void setZoomValue(Object value)
        Parameters:
        value -
      • getZoomValue

        public Object getZoomValue()
        Returns:
        zoom value, usually an integer
      • setReportProcessQuery

        public void setReportProcessQuery(MQuery query)
        Parameters:
        query -
      • getReportProcessQuery

        public MQuery getReportProcessQuery()
        Returns:
        query
      • getRestrictionSQL

        public String getRestrictionSQL(String ColumnName, String Operator, Object Code, String InfoName, String InfoDisplay, boolean andCondition, int depth)
        Parameters:
        ColumnName -
        Operator -
        Code - query value
        InfoName -
        InfoDisplay - display text of code
        andCondition - true=and, false=or
        depth - number of parenthesis
        Returns:
        SQL
      • getRestrictionSQL

        public String getRestrictionSQL(String ColumnName, Object Code, Object Code_To, String InfoName, String InfoDisplay, String InfoDisplay_To, boolean andCondition, int depth)
        Parameters:
        ColumnName -
        Code - from value
        Code_To - to value
        InfoName -
        InfoDisplay - display text of from value
        InfoDisplay_To - display text of to value
        andCondition - true=and, false=or
        depth - number of parenthesis
        Returns:
        SQL
      • clone

        public MQuery clone()
        Overrides:
        clone in class Object