Record Class MatchCondition

java.lang.Object
java.lang.Record
de.calamanari.adl.sql.cnv.MatchCondition
Record Components:
operator - comparison operator, equals in case of an IN-clause
isNegation - if true this shall later be a NOT resp. NOT IN
argNameLeft - name of the argument on the left, mandatory
tableLeft - meta data of the table on the left, mandatory
columnLeft - meta data of the column on the left, mandatory
argNameRight - name of the argument on the right in case of a reference match, null by default
tableRight - meta data of the table on the right in case of a reference match, null by default
columnRight - meta data of the column on the right in case of a reference match, null by default
columnConditions - defines the parameters per column
All Implemented Interfaces:
Serializable

public record MatchCondition(de.calamanari.adl.irl.MatchOperator operator, boolean isNegation, String argNameLeft, TableMetaInfo tableLeft, DataColumn columnLeft, String argNameRight, TableMetaInfo tableRight, DataColumn columnRight, List<ColumnCondition> columnConditions) extends Record implements Serializable
A MatchCondition is an instruction to create an SQL term that either ...
  • compares a column against a value.
  • compares a column against multiple values.
  • compares a column against another column.
By intention the record temporarily introduces some redundancy to make it easier to work with the complex meta data.

Instances are deeply immutable.

Author:
Karl Eilebrecht
See Also:
  • Constructor Details

    • MatchCondition

      public MatchCondition(de.calamanari.adl.irl.MatchOperator operator, boolean isNegation, String argNameLeft, TableMetaInfo tableLeft, DataColumn columnLeft, String argNameRight, TableMetaInfo tableRight, DataColumn columnRight, List<ColumnCondition> columnConditions)
      Creates an instance of a MatchCondition record class.
      Parameters:
      operator - the value for the operator record component
      isNegation - the value for the isNegation record component
      argNameLeft - the value for the argNameLeft record component
      tableLeft - the value for the tableLeft record component
      columnLeft - the value for the columnLeft record component
      argNameRight - the value for the argNameRight record component
      tableRight - the value for the tableRight record component
      columnRight - the value for the columnRight record component
      columnConditions - the value for the columnConditions record component
  • Method Details

    • createSimpleCondition

      public static MatchCondition createSimpleCondition(de.calamanari.adl.irl.SimpleExpression expression, SqlConversionProcessContext ctx)
      Creates a simple (negated) match condition (against value, or IS NULL) from the given expression
      Parameters:
      expression -
      ctx -
      Returns:
      condition
    • shouldAlignDate

      public static boolean shouldAlignDate(de.calamanari.adl.cnv.tps.AdlType type, AdlSqlType columnType, de.calamanari.adl.ProcessContext ctx)
      Tells whether we should perform an alignment of the given data to a higher resolution stamp before creating the query, to for example turn an equals into a range query.
      Parameters:
      type - source type
      columnType - destination type
      ctx -
      Returns:
      true if the date needs alignment
    • createFilterColumnCondition

      public static ColumnCondition createFilterColumnCondition(ColumnConditionType filterType, FilterColumn filterColumn, SqlConversionProcessContext ctx)
      Creates a single filter column condition (column or table filter)
      Parameters:
      filterType -
      filterColumn -
      ctx -
      Returns:
      filter column condition
    • negate

      public static MatchCondition negate(MatchCondition condition)
      Parameters:
      condition -
      Returns:
      copy of the the given condition with isNegation==true
    • createInClauseCondition

      public static MatchCondition createInClauseCondition(List<de.calamanari.adl.irl.SimpleExpression> expressions, SqlConversionProcessContext ctx)
      Assumes a list of MatchExpressions or NegationExpressions all dealing with the same argName, EQUALS-operator and plain values, so the result will be an IN-clause in case of OR vs. a NOT IN clause in case of AND.
      Parameters:
      expressions - either the elements of an OR (IN, only MatchExpressions) or the elements of an AND (NOT IN, only NegationExpressions)
      ctx -
      Returns:
      condition
      Throws:
      IllegalArgumentException - if there are multiple argNames involved, multiple operands reference matches was detected.
      ClassCastException - if expressions are not all of the same type
    • dataColumnNameLeft

      public String dataColumnNameLeft(boolean qualified)
      Convenience method to obtain the effective data column name
      Parameters:
      qualified - if true, we prepend the table name separated by a dot
      Returns:
      sql identifier
    • dataColumnNameRight

      public String dataColumnNameRight(boolean qualified)
      Convenience method to obtain the effective data column name
      Parameters:
      qualified - if true, we prepend the table name separated by a dot
      Returns:
      sql identifier
    • idColumnNameLeft

      public String idColumnNameLeft(boolean qualified)
      Convenience method to obtain the effective ID column name
      Parameters:
      qualified - if true, we prepend the table name separated by a dot
      Returns:
      sql identifier
    • idColumnNameRight

      public String idColumnNameRight(boolean qualified)
      Convenience method to obtain the effective ID column name
      Parameters:
      qualified - if true, we prepend the table name separated by a dot
      Returns:
      sql identifier
    • isReferenceMatch

      public boolean isReferenceMatch()
      Returns:
      true if this condition matches two columns against each other
    • isSingleTableReferenceMatchInvolvingMultipleRows

      public boolean isSingleTableReferenceMatchInvolvingMultipleRows()
      Returns:
      true if this condition matches two columns of the same table against each other, and at least one of the columns is marked mult-row
    • isDualTableReferenceMatch

      public boolean isDualTableReferenceMatch()
      Returns:
      true if this condition matches two columns from different tables against each other
    • isNullMatch

      public boolean isNullMatch()
      Returns:
      true if this condition reflects an IS NULL (operator IS UNKNOWN)
    • getPrimaryColumnCondition

      public ColumnCondition getPrimaryColumnCondition()
      Returns:
      the primary value comparison (e.g., color=blue) or null if this is a reference match.
    • type

      public ColumnConditionType type()
      Returns:
      type of the main condition
    • hasAnyFilterColumnConditions

      public boolean hasAnyFilterColumnConditions()
      Returns:
      true if there are any additional filter conditions besides the primary match condition
    • getLeftFilterColumnConditions

      public List<ColumnCondition> getLeftFilterColumnConditions()
      Returns:
      list with optional filter column conditions related to the left column
    • getRightFilterColumnConditions

      public List<ColumnCondition> getRightFilterColumnConditions()
      Returns:
      list with optional filter column conditions related to the right column in case of a reference match
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • operator

      public de.calamanari.adl.irl.MatchOperator operator()
      Returns the value of the operator record component.
      Returns:
      the value of the operator record component
    • isNegation

      public boolean isNegation()
      Returns the value of the isNegation record component.
      Returns:
      the value of the isNegation record component
    • argNameLeft

      public String argNameLeft()
      Returns the value of the argNameLeft record component.
      Returns:
      the value of the argNameLeft record component
    • tableLeft

      public TableMetaInfo tableLeft()
      Returns the value of the tableLeft record component.
      Returns:
      the value of the tableLeft record component
    • columnLeft

      public DataColumn columnLeft()
      Returns the value of the columnLeft record component.
      Returns:
      the value of the columnLeft record component
    • argNameRight

      public String argNameRight()
      Returns the value of the argNameRight record component.
      Returns:
      the value of the argNameRight record component
    • tableRight

      public TableMetaInfo tableRight()
      Returns the value of the tableRight record component.
      Returns:
      the value of the tableRight record component
    • columnRight

      public DataColumn columnRight()
      Returns the value of the columnRight record component.
      Returns:
      the value of the columnRight record component
    • columnConditions

      public List<ColumnCondition> columnConditions()
      Returns the value of the columnConditions record component.
      Returns:
      the value of the columnConditions record component