Class 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:
    Serialized Form
    • Constructor Detail

      • 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
        Parameters:
        AD_Table_ID - Table_ID
    • Method Detail

      • get

        public static MQuery get​(Properties ctx,
                                 int AD_PInstance_ID,
                                 String TableName)
        Get Query from Parameter
        Parameters:
        ctx - context (to determine language)
        AD_PInstance_ID - instance
        TableName - table name
        Returns:
        where clause
      • getZoomColumnName

        public static String getZoomColumnName​(String columnName)
        Get Zoom Column Name. Converts Synonyms like SalesRep_ID to AD_User_ID
        Parameters:
        columnName - column name
        Returns:
        column name
      • getZoomTableName

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

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

        public static MQuery getEqualQuery​(String columnName,
                                           int value)
        Create simple Equal Query. Creates 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 (2=3)
        Returns:
        query
      • getZoomWindowID

        public int getZoomWindowID()
      • setZoomWindowID

        public void setZoomWindowID​(int m_zoomWindow_ID)
      • 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 - Code, e.g 0, All%
        InfoName - Display Name
        InfoDisplay - Display of Code (Lookup)
        andCondition - true=and, false=or
        depth - ( = no open brackets )
      • 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 - Code, e.g 0, All%
        InfoName - Display Name
        InfoDisplay - Display of Code (Lookup)
        andCondition - true=and, false=or
        notCondition - true=not, false=empty
        depth - ( = no open brackets )
      • 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 - Code, e.g 0, All%
        Code_to - Code, e.g 0, All%
        InfoName - Display Name
        InfoDisplay - Display of Code (Lookup)
        InfoDisplay_to - Display of Code (Lookup)
        andCondition - true=and, false=or
        notCondition - true=not, false=empty
        depth - ( = no open brackets )
      • 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 - Code, e.g 0, All%
        InfoName - Display Name
        InfoDisplay - Display of Code (Lookup)
        andOrCondition - AND/OR/AND NOT/OR NOT - concatenation of parenthesis
        depth - ( = no open brackets )
      • addRestriction

        public void addRestriction​(String ColumnName,
                                   String Operator,
                                   Object Code,
                                   String InfoName,
                                   String InfoDisplay)
        Add Restriction
        Parameters:
        ColumnName - ColumnName
        Operator - Operator, e.g. = != ..
        Code - Code, 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 - Code, e.g 0, All%
      • addRestriction

        public void addRestriction​(String ColumnName,
                                   String Operator,
                                   int Code)
        Add Restriction
        Parameters:
        ColumnName - ColumnName
        Operator - Operator, e.g. = != ..
        Code - Code, 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 - Code, e.g 0, All%
        Code_to - Code, e.g 0, All%
        InfoName - Display Name
        InfoDisplay - Display of Code (Lookup)
        InfoDisplay_to - Display of Code (Lookup)
        andCondition - true=and, false=or
        depth - ( = no open brackets )
      • 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 - Code, e.g 0, All%
        Code_to - Code, e.g 0, All%
        InfoName - Display Name
        InfoDisplay - Display of Code (Lookup)
        InfoDisplay_to - Display of Code (Lookup)
        andOrCondition - AND/OR/AND NOT/OR NOT - concatenation of parenthesis
        depth - ( = no open brackets )
      • 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 - Code, e.g 0, All%
        Code_to - Code, e.g 0, All%
        InfoName - Display Name
        InfoDisplay - Display of Code (Lookup)
        InfoDisplay_to - Display of Code (Lookup)
      • addRangeRestriction

        public void addRangeRestriction​(String ColumnName,
                                        Object Code,
                                        Object Code_to)
        Add Range Restriction (BETWEEN)
        Parameters:
        ColumnName - ColumnName
        Code - Code, e.g 0, All%
        Code_to - Code, 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 -
        joinDepth -
      • addRestriction

        public void addRestriction​(String whereClause,
                                   boolean andCondition,
                                   boolean notCondition,
                                   int joinDepth)
        Add Restriction
        Parameters:
        whereClause - SQL WHERE clause
      • addRestriction

        public void addRestriction​(String whereClause,
                                   boolean andCondition,
                                   boolean notCondition,
                                   boolean existsCondition,
                                   int joinDepth)
        Add Restriction
        Parameters:
        whereClause - SQL WHERE clause
      • addRestriction

        public void addRestriction​(String whereClause,
                                   int joinDepth,
                                   String andOrCondition)
        Add Restriction
        Parameters:
        whereClause - SQL WHERE clause
        joinDepth -
        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)
      • 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
      • 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
      • getCode

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

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

        public String getInfoDisplay​(int index)
        Get Restriction Display of index
        Parameters:
        index - index
        Returns:
        Restriction Display
      • getInfoDisplay_to

        public String getInfoDisplay_to​(int index)
        Get TO Restriction Display of index
        Parameters:
        index - index
        Returns:
        Restriction Display
      • 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)
      • getReportProcessQuery

        public MQuery getReportProcessQuery()
      • getRestrictionSQL

        public String getRestrictionSQL​(String ColumnName,
                                        String Operator,
                                        Object Code,
                                        String InfoName,
                                        String InfoDisplay,
                                        boolean andCondition,
                                        int depth)
        Parameters:
        ColumnName -
        Operator -
        Code -
        InfoName -
        InfoDisplay -
        andCondition -
        depth -
        Returns:
      • 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 -
        Code_To -
        InfoName -
        InfoDisplay -
        InfoDisplay_To -
        andCondition -
        depth -
        Returns: