Interface EntityCondition

All Superinterfaces:
IsEmpty, Serializable
All Known Implementing Classes:
EntityConditionList, EntityDateFilterCondition, EntityExpr, EntityFieldMap, EntityNotCondition, EntityWhereString

public interface EntityCondition extends IsEmpty, Serializable
Represents a condition expression that can be used in a SQL 'WHERE' clause which is used to constrain a SQL query.

An EntityCondition can represent various type of constraints, including:

  • EntityConditionList: a list of EntityConditions, combined with the operator specified
  • EntityExpr: for simple expressions or expressions that combine EntityConditions
  • EntityFieldMap: a map of fields where the field (key) equals the value, combined with the operator specified
These can be used in various combinations using the EntityConditionList and EntityExpr objects.
  • Field Details

  • Method Details

    • makeCondition

      static <L, R, LL, RR> EntityExpr makeCondition(L lhs, EntityComparisonOperator<LL,RR> operator, R rhs)
      Constructs a condition expression to represent a comparison between two elements.
      Parameters:
      lhs - the left hand side element
      operator - the binary infix operator
      rhs - the right hand side element
      Returns:
      a condition expression representing a comparison between two elements
    • makeCondition

      static <R> EntityExpr makeCondition(String fieldName, R value)
      Constructs a condition expression to represent a equality comparison between a field and a value.
      Parameters:
      fieldName - the name of the field to compare
      value - the value to find in field
      Returns:
      a condition expression representing a equality comparison
    • makeCondition

      static EntityExpr makeCondition(EntityCondition lhs, EntityJoinOperator operator, EntityCondition rhs)
      Constructs a condition expression to represent a combination of two condition expressions.
      Parameters:
      lhs - the left hand side condition
      operator - the binary infix operator used to combine lhs and rhs conditions
      rhs - the right hand side condition
      Returns:
      a condition expression representing a combination of condition expression
    • makeCondition

      @SafeVarargs static <R extends EntityCondition, T extends R> EntityConditionList<R> makeCondition(EntityJoinOperator operator, T... conditionList)
      Constructs a condition expression to represent a combination of condition expressions.
      Parameters:
      operator - the binary infix operator used to join every elements of conditionList
      conditionList - the list of condition expressions to join
      Returns:
      a condition expression representing a combination of condition expressions.
    • makeCondition

      @SafeVarargs static <R extends EntityCondition, T extends R> EntityConditionList<R> makeCondition(T... conditionList)
      Constructs a condition expression to represent a conjunction of condition expressions
      Parameters:
      conditionList - the condition expressions to join with EntityOperator.AND
      Returns:
      a condition expression representing a conjunction of condition expressions
    • makeCondition

      static <T extends EntityCondition> EntityConditionList<T> makeCondition(List<? extends T> conditionList, EntityJoinOperator operator)
      Constructs a condition expression to represent a combination of condition expressions.
      Parameters:
      conditionList - the list of condition expressions to join
      operator - the binary infix operator used to join every elements of conditionList
      Returns:
      a condition expression representing a combination of condition expressions.
    • makeCondition

      static <T extends EntityCondition> EntityConditionList<T> makeCondition(List<? extends T> conditionList)
      Constructs a condition expression to represent a conjunction of condition expressions
      Parameters:
      conditionList - the condition expressions to join with EntityOperator.AND
      Returns:
      a condition expression representing a conjunction of condition expressions
    • makeCondition

      static <L, R> EntityFieldMap makeCondition(Map<String,? extends Object> fieldMap, EntityComparisonOperator<L,R> compOp, EntityJoinOperator joinOp)
      Constructs a condition expression to represent a combination of field/value comparisons.
      Parameters:
      fieldMap - the map associating a field to the value to match
      compOp - the binary infix operator used to compare the field and the value
      joinOp - the binary infix operator used to join the field/value comparisons
      Returns:
      a condition expression representing a combination of field/value comparisons
    • makeCondition

      static EntityFieldMap makeCondition(Map<String,? extends Object> fieldMap, EntityJoinOperator joinOp)
      Constructs a condition expression to represent a combination of field/value equality comparisons.
      Parameters:
      fieldMap - the map associating a field to the value to match with EntityOperator.EQUALS
      joinOp - the binary infix operator used to join the field/value equality comparisons
      Returns:
      a condition expression representing a combination of field/value equality comparisons
    • makeCondition

      static EntityFieldMap makeCondition(Map<String,? extends Object> fieldMap)
      Constructs a condition expression to represent a conjunction of field/value equality comparisons.
      Parameters:
      fieldMap - the map associating a field to the value to match with EntityOperator.EQUALS
      Returns:
      a condition expression representing a conjunction of field/value equality comparisons
    • makeCondition

      static <L, R> EntityFieldMap makeCondition(EntityComparisonOperator<L,R> compOp, EntityJoinOperator joinOp, Object... keysValues)
      Constructs a condition expression to represent a combination of field/value comparisons.
      Parameters:
      compOp - the binary infix operator used to compare the field and the value
      joinOp - the binary infix operator used to join the field/value comparisons
      keysValues - the field/values pairs to match
      Returns:
      a condition expression representing a combination of field/value comparisons
    • makeCondition

      static EntityFieldMap makeCondition(EntityJoinOperator joinOp, Object... keysValues)
      Constructs a condition expression to represent a combination of field/value equality comparisons.
      Parameters:
      joinOp - the binary infix operator used to join the field/value equality comparisons
      keysValues - the field/values pairs to match with EntityOperator.EQUALS
      Returns:
      a condition expression representing a combination of field/value equality comparisons
    • makeConditionMap

      static EntityFieldMap makeConditionMap(Object... keysValues)
      Constructs a condition expression to represent a conjunction of field/value equality comparisons.
      Parameters:
      keysValues - the field/values pairs to match with EntityOperator.EQUALS
      Returns:
      a condition expression representing a conjunction of field/value equality comparisons
    • makeConditionDate

      static EntityDateFilterCondition makeConditionDate(String fromDateName, String thruDateName)
      Constructs a condition expression to filter rows that are currently valid. This means that we remove rows whose from/thru date range does not match the current date. The current date is the one computed when the SQL query is generated.
      Parameters:
      fromDateName - the name of the field corresponding to the from date
      thruDateName - the name of the field corresponding to the thru date
      Returns:
      a condition expression filtering rows that are currently valid
    • makeConditionWhere

      static EntityWhereString makeConditionWhere(String sqlString)
      Constructs a condition expression backed by a raw SQL string
      Parameters:
      sqlString - the SQL string
      Returns:
      a raw SQL string condition expression
    • accept

      void accept(EntityConditionVisitor visitor)
      Applies a visitor to this condition.
      Parameters:
      visitor - the visitor to be applied
    • makeWhereString

      String makeWhereString(ModelEntity modelEntity, List<EntityConditionParam> entityConditionParams, Datasource datasourceInfo)
      Dumps the corresponding SQL string.
      Parameters:
      modelEntity - the model of the entity
      entityConditionParams - the effective parameters used to substitute '?' parameters
      datasourceInfo - the model of the data source interpreting the SQL
      Returns:
      the corresponding SQL string
    • checkCondition

      void checkCondition(ModelEntity modelEntity) throws GenericModelException
      Verifies that this condition expression is valid.
      Parameters:
      modelEntity - the model of the entity
      Throws:
      GenericModelException - when this condition expression is not valid
    • entityMatches

      default boolean entityMatches(GenericEntity entity)
      Checks that this condition expression matches a particular entity.
      Parameters:
      entity - the entity to match
      Returns:
      true if this condition expression matches entity
    • mapMatches

      boolean mapMatches(Delegator delegator, Map<String,? extends Object> map)
      Checks that this condition expression matches a particular entity.
      Parameters:
      delegator - the delegator used to match
      map - the entity definition to match
      Returns:
      true if this condition expression matches map when using delegator
    • freeze

      EntityCondition freeze()
      Create a Frozen condition expression corresponding to this condition expression.
      Returns:
      the frozen condition expression
    • makeWhereString

      default String makeWhereString()
      Dumps the corresponding SQL string without substituting '?' parameters.
      Returns:
      the corresponding SQL string