## org.eclipse.datatools.sqltools.sqlbuilder.model
Class SearchConditionHelper

    java.lang.Object
      org.eclipse.datatools.sqltools.sqlbuilder.model.SearchConditionHelper

    public class SearchConditionHelper

extends java.lang.Object

This class provides "helper" functions for building and manipulating query search conditions. The Query Builder builds search conditions in a particular way. Conditions are structured as a tree of Predicate and SearchConditionCombined objects that "grows" from the bottom left as new conditions are added to the condition grid. That is, new Predicate and SearchConditionCombined objects are added to the right, creating a new "root" SearchConditionCombined as each predicate is added. Let's say you have a single condition in the Conditions grid in the UI. This condition is represented in the model as a single Predicate object, call it P1. When the user adds a new condition as the 2nd row of the Condition grid, another Predicate, P2, is created, and P1 and P2 are combined using a SearchConditionCombined (call it SCC1), like this: SCC1 / \ P1 P2 When another condition is added in the third row of the Conditions grid, the model is modified like this: SCC2 / \ SCC1 P3 / \ P1 P2 Adding a fourth condition results in the following tree: SCC3 / \ SCC2 P4 / \ SCC1 P3 / \ P1 P2 And so on. Navigating the search condition tree in the code can be confusing. The model provides calls to get the left or right parent SearchConditionCombined (if any) of a node, and to get the left or right child condition (if any) of a SearchConditionCombined. (The child can be a Predicate or a SearchConditionCombined.) Considering a node in the tree (the node can be either a Predicate or a SearchConditionCombined), the other nodes in relation to it are as follows: combinedRight combinedLeft \ / node / \ leftCondition rightCondition The methods in the model for navigating the tree are named accordingly: getCombinedRight - get the SearchConditionCombined for which this node is the right child getCombinedLeft - get the SearchConditionCombined for which this node is the left child getLeftCondition - get the condition (Predicate or SearchConditionCombined) that is the left child of this node (which must be a SearchConditionCombined) getRightCondition - get the condition (Predicate or SearchConditionCombined) that is the right child of this node (which must be a SearchConditionCombined) Notes: 1. For any node, getCombinedLeft and getCombinedRight cannot both return non-null. (Both may return null, which indicates the node is the root of the condition tree.) 2. In the trees built by the Query Builder, getRightCondition will always return a Predicate, never a SearchConditionCombined.

Field Summary
`static java.lang.String[]` `operators`

Constructor Summary
`SearchConditionHelper(SQLDomainModel domainModel)` Constructs an instance of this class, with the given domain model object.

Method Summary
`static Predicate` `buildEmptyPredicate()` Creates an empty predicate.
`Predicate` `buildNewPredicate(SQLQueryObject currStmt, QueryValueExpression left, java.lang.String right, java.lang.String comparisonKind)` Builds the Predicate for the given comparison kind.
`static PredicateBasic` `buildPredicateBasic(QueryValueExpression leftExpr, QueryValueExpression rightExpr, java.lang.String oper)` Creates a PredicateBasic object using the given expressions and operator
`static QuerySearchCondition` `buildSearchCondition(QuerySearchCondition currentSearchCon, QueryValueExpression leftExpr, QueryValueExpression rightExpr, java.lang.String oper)` Creates a new predicate and adds it to the given search condition.
`QuerySearchCondition` `buildSearchCondition(SQLQueryObject currStmt, QuerySearchCondition currentSearchCon, QueryValueExpression left, java.lang.String right, java.lang.String comparisonKind)` Creates a new predicate with the given values and append it to the give search condition.
`static java.util.List` `getAllPredicates(QuerySearchCondition condition)`
`QueryValueExpression` `getDefaultLeft(java.lang.String predOpr)` Returns the default left side of a predicate for the given operator.
`java.lang.String` `getDefaultRight(java.lang.String predOpr)` Returns the default right side of a predicate for the given operator.
`QueryValueExpression` `getLeftFromPredicate(Predicate pred)` Returns the left value for the given predicate
`java.lang.String` `getPredicateOperator(Predicate pred)` Returns the operator for the given predicate
`java.lang.String` `getRightFromPredicate(Predicate pred)` Returns the right value for the given predicate
`boolean` `isHavingClause()`
`static QuerySearchCondition` `removePredicateFromCondition(Predicate pred, QuerySearchCondition searchCon)` Removes the given predicate from the search condition.
`void` `removePredicateFromCondition(Predicate pred, QuerySearchCondition searchCon, SQLQueryObject currStmt)` Removes the given predicate from the search condition.
`static QuerySearchCondition` `replacePredicate(QuerySearchCondition searchCon, Predicate oldPred, Predicate newPred)`
`void` `replacePredicate(SQLQueryObject stmt, QuerySearchCondition searchCon, Predicate oldPred, Predicate newPred)` Replaces the given predicate with the new predicate
`void` `replaceSearchCondition(SQLQueryObject statement, QuerySearchCondition searchCon)`
`QuerySearchCondition` `setAndOrInSearchCondition(SQLQueryObject currStmt, QuerySearchCondition searchCon, Predicate pred, java.lang.String andOrValue)` Sets the And/Or for the condition, creates the new predicate if needed and returns the searchCondition with new added predicate.
`void` `setHavingClause(boolean havingClause)`
`boolean` `setLeftInPredicate(Predicate pred, QueryValueExpression value)` Sets the ValueExpression as Left value in the given predicate.
`boolean` `setOperatorInPredicate(SQLQueryObject currStmt, QuerySearchCondition searchCon, Predicate pred, java.lang.String value)` Sets the given value as the operator in the given predicate.

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### operators

    public static final java.lang.String[] operators

Constructor Detail

### SearchConditionHelper

    public SearchConditionHelper(SQLDomainModel domainModel)

  Constructs an instance of this class, with the given domain model object.

  Parameters:
    `domainModel` - the query builder domain model to use

Method Detail

### buildNewPredicate

    public Predicate buildNewPredicate(SQLQueryObject currStmt,
                                       QueryValueExpression left,
                                       java.lang.String right,
                                       java.lang.String comparisonKind)

  Builds the Predicate for the given comparison kind.

  Parameters:
    `currStmt` - the SQL statement for which new predicate will be part of
    `left` - the QueryValueExpression represents left side of the predicate
    `right` - the String value for right side of the predicate
    `comparisonKind` - String value that indicates what type of Predicate it is going to be
  Returns:
    the built predicate

### buildEmptyPredicate

    public static Predicate buildEmptyPredicate()

  Creates an empty predicate.

  Returns:
    an empty predicate

### buildSearchCondition

    public static QuerySearchCondition buildSearchCondition(QuerySearchCondition currentSearchCon,
                                                            QueryValueExpression leftExpr,
                                                            QueryValueExpression rightExpr,
                                                            java.lang.String oper)

  Creates a new predicate and adds it to the given search condition.

  Parameters:
    `currentSearchCon` - the existing search condition or null
    `leftExpr` - the left side expression of the new predicate
    `rightExpr` - the right side expression of the new predicate
    `oper` - the operator string (eg: "=" )
  Returns:
    the new search condition object

### buildPredicateBasic

    public static PredicateBasic buildPredicateBasic(QueryValueExpression leftExpr,
                                                     QueryValueExpression rightExpr,
                                                     java.lang.String oper)

  Creates a PredicateBasic object using the given expressions and operator

  Parameters:
    `leftExpr` - the left side expression
    `rightExpr` - the right side expression
    `oper` - the operator
  Returns:
    the new PredicateBasic object

### buildSearchCondition

    public QuerySearchCondition buildSearchCondition(SQLQueryObject currStmt,
                                                     QuerySearchCondition currentSearchCon,
                                                     QueryValueExpression left,
                                                     java.lang.String right,
                                                     java.lang.String comparisonKind)

  Creates a new predicate with the given values and append it to the give search condition.

  Parameters:
    `currentSearchCon` - the current QuerySearchCondition, null is passed if building search condition first time.
    `left` - the QueryValueExpression represents left side of the predicate
    `right` - the String value for right side of the predicate
    `comparisonKind` - String value that indicates what type of Predicate needs to build
  Returns:
    the new search condition

### removePredicateFromCondition

    public static QuerySearchCondition removePredicateFromCondition(Predicate pred,
                                                                    QuerySearchCondition searchCon)

  Removes the given predicate from the search condition.

  Parameters:
    `pred` - the Predicate which needs to be removed from the condition
    `searchCon` - the SearchCondition from which predicate needs to be removed

### removePredicateFromCondition

    public void removePredicateFromCondition(Predicate pred,
                                             QuerySearchCondition searchCon,
                                             SQLQueryObject currStmt)

  Removes the given predicate from the search condition.

  Parameters:
    `pred` - the Predicate which needs to be removed from the condition
    `searchCon` - the SearchCondition from which predicate needs to be removed
    `currStmt` - the statement containing the search condition

### getLeftFromPredicate

    public QueryValueExpression getLeftFromPredicate(Predicate pred)

  Returns the left value for the given predicate

  Parameters:
    `pred` - the predicate for which left expression needs to be returned
  Returns:
    the left expression

### getRightFromPredicate

    public java.lang.String getRightFromPredicate(Predicate pred)

  Returns the right value for the given predicate

  Parameters:
    `pred` - the predicate for which right expression needs to be returned
  Returns:
    the string value for right side expression

### getPredicateOperator

    public java.lang.String getPredicateOperator(Predicate pred)

  Returns the operator for the given predicate

  Parameters:
    `pred` - the predicate for which operator needs to be returned
  Returns:
    the string value for the operator

### getAllPredicates

    public static java.util.List getAllPredicates(QuerySearchCondition condition)

  Parameters:
    `condition` -
  Returns:

### setLeftInPredicate

    public boolean setLeftInPredicate(Predicate pred,
                                      QueryValueExpression value)

  Sets the ValueExpression as Left value in the given predicate. Returns true if value is successfully set otherwise returns false.

  Parameters:
    `pred` - the Predicate for which left expression needs to be set
    `value` - the QueryValueExpression needs to set for the predicate
  Returns:
    the status for set operation.

### setOperatorInPredicate

    public boolean setOperatorInPredicate(SQLQueryObject currStmt,
                                          QuerySearchCondition searchCon,
                                          Predicate pred,
                                          java.lang.String value)

  Sets the given value as the operator in the given predicate. It also changes the nature of current predicate. Returns true if value is successfully set otherwise returns false.

  Parameters:
    `pred` - the Predicate for which operator needs to be set
    `value` - the String value needs to set as operator for the predicate
  Returns:
    the status for set operation.

### getDefaultRight

    public java.lang.String getDefaultRight(java.lang.String predOpr)

  Returns the default right side of a predicate for the given operator.

  Parameters:
    `predOpr` - the String predicate operator for which default value is needed
  Returns:
    the default right value

### getDefaultLeft

    public QueryValueExpression getDefaultLeft(java.lang.String predOpr)

  Returns the default left side of a predicate for the given operator.

  Parameters:
    `predOpr` - the String predicate operator for which default value is needed
  Returns:
    the default left value

### setAndOrInSearchCondition

    public QuerySearchCondition setAndOrInSearchCondition(SQLQueryObject currStmt,
                                                          QuerySearchCondition searchCon,
                                                          Predicate pred,
                                                          java.lang.String andOrValue)

  Sets the And/Or for the condition, creates the new predicate if needed and returns the searchCondition with new added predicate.

  Parameters:
    `currStmt` - the current QueryStatement
    `searchCon` - the QuerySearchCondition to which predicate is added if needed
    `pred` - the current Predicate on which And/Or needs to be set
    `andOrValue` - the String And/Or value
  Returns:
    the updated QuerySearchCondition

### replacePredicate

    public static QuerySearchCondition replacePredicate(QuerySearchCondition searchCon,
                                                        Predicate oldPred,
                                                        Predicate newPred)

### replacePredicate

    public void replacePredicate(SQLQueryObject stmt,
                                 QuerySearchCondition searchCon,
                                 Predicate oldPred,
                                 Predicate newPred)

  Replaces the given predicate with the new predicate

  Parameters:
    `stmt` - the current QueryStatement
    `searchCon` - the QuerySearchCondition which needs to be updated with new predicate
    `oldPred` - the Predicate which needs to be replaced
    `newPred` - the new Predicate

### replaceSearchCondition

    public void replaceSearchCondition(SQLQueryObject statement,
                                       QuerySearchCondition searchCon)

  Parameters:
    `statement` -
    `searchCon` -

### isHavingClause

    public boolean isHavingClause()

  Returns:
    Returns the havingClause.

### setHavingClause

    public void setHavingClause(boolean havingClause)

  Parameters:
    `havingClause` - The havingClause to set.