: Class Operator_Compare

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## ModSQL
Class Operator_Compare

    java.lang.Object
      |
      +--ModSQL.AbstractFunction
            |
            +--ModSQL.Operator
                  |
                  +--ModSQL.Operator_Compare

All Implemented Interfaces:
  Function

final class Operator_Compare
extends Operator

SQL comparison operators.

Author:
  chris.studholme@utoronto.ca

Field Summary
`static int` | `BETWEEN` Comparison operator (between).
`private int[]` | `compare_type` Per column comparison type.
`static int` | `EQU` Comparison operator (equal).
`static int` | `GT` Comparison operator (greater than).
`static int` | `GTE` Comparison operator (greater or equal).
`static int` | `LT` Comparison operator (less than).
`static int` | `LTE` Comparison operator (less or equal).
`private int` | `ncolumns` Number of columns in row-constructor.
`static int` | `NE` Comparison operator (not equal).
`private int` | `op` Which operator? One of the above constants.
`private Object[][]` | `row_value` Value of the parameters.
`private RowConstructor[]` | `rows` One row per parameter (only if we have row-constructors).

Fields inherited from class ModSQL.AbstractFunction
`all_constant, constant_non_null, evaluate_order, evaluate_order_array, out_of_order, parameter_constant, parameter_value, parameters, parameters_array`

Fields inherited from interface ModSQL.Function
`MATCH_BEGINS, MATCH_EQU, MATCH_GT, MATCH_GTE, MATCH_LT, MATCH_LTE, MATCH_NE`

Constructor Summary
`Operator_Compare(int op)` Constructor.

Method Summary
`static int` | `compare(Object v1, Object v2, int common_type)` Compare two objects by converting to a common type.
`static boolean` | `equal(Object v1, Object v2, int common_type)` Check if two objects are equal by converting to a common type.
`Object` | `evaluate(boolean aggregate)` Evaluate parameters and compare.
`Object` | `evaluate(int match_op, Object match_value)` Evaluate parameters and compare.
`String` | `functionName()` Returns the name of this function for use by toString() method.
`int` | `getMaxResultSize()` Returns -1 as this operator will never return String objects.
`int` | `getSQLType()` Returns Types.BIT.
`void` | `optimize()` Prepare the function for use.
`boolean` | `test(Object v1, Object v2)`
`static boolean` | `test(Object v1, Object v2, int op, int compare_type)` Compare two objects according to op.
`boolean` | `test(Object v1, Object v2, Object v3)`
`static boolean` | `test(Object v1, Object v2, Object v3, int compare_type)`
`static Boolean` | `testRow(Object[] r1, Object[] r2, int op, int[] compare_type)` Compare two rows according to op and using compare_type array.
`static Boolean` | `testRowInequality(Object[] r1, Object[] r2, int op, int[] compare_type)` Compare two rows according to op (inequalities only) and using compare_type array.

Methods inherited from class ModSQL.Operator
`addAllParameters, addAllParametersNegate, addAllParametersNot, removeDoubleNegation, removeDoubleNot`

Methods inherited from class ModSQL.AbstractFunction
`addParameter, convertToSQLType, evaluateConstantParameters, evaluateOrder, evaluateParameters, evaluateParameters, getCompatableType, getObjectSQLType, getParameter, getParameterCount, isAggregate, isConstant, postfixParameters, prefixParameters, registerWith, reset, toString`

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

Field Detail

### EQU

    public static final int EQU

  Comparison operator (equal).

### GT

    public static final int GT

  Comparison operator (greater than).

### GTE

    public static final int GTE

  Comparison operator (greater or equal).

### LT

    public static final int LT

  Comparison operator (less than).

### LTE

    public static final int LTE

  Comparison operator (less or equal).

### NE

    public static final int NE

  Comparison operator (not equal).

### BETWEEN

    public static final int BETWEEN

  Comparison operator (between).

### op

    private int op

  Which operator? One of the above constants.

### compare_type

    private int[] compare_type

  Per column comparison type.

### rows

    private RowConstructor[] rows

  One row per parameter (only if we have row-constructors).

### row_value

    private Object[][] row_value

  Value of the parameters.

### ncolumns

    private int ncolumns

  Number of columns in row-constructor.

Constructor Detail

### Operator_Compare

    public Operator_Compare(int op)

  Constructor.
  Parameters:
    `op` - operator type

Method Detail

### optimize

    public void optimize()
                  throws SQLException

  Prepare the function for use. This method checks the parameters and figures out how the comparison will take place (what type to use).

  Overrides:
    `optimize` in class `AbstractFunction`
  Throws:
    `SQLException` - if the parameters are invalid

### functionName

    public String functionName()

  Returns the name of this function for use by toString() method.
  Overrides:
    `functionName` in class `AbstractFunction`
  Returns:
    name of function

### getSQLType

    public int getSQLType()

  Returns Types.BIT.
  Returns:
    SQL type of data to be returned

### getMaxResultSize

    public int getMaxResultSize()

  Returns -1 as this operator will never return String objects.
  Returns:
    maximum size of String returned or -1 if unknown

### evaluate

    public Object evaluate(boolean aggregate)
                    throws SQLException,
                           EndOfTable

  Evaluate parameters and compare.
  Parameters:
    `aggregate` - passed to parameters
  Returns:
    result object
  Throws:
    `SQLException` - if a database-access error occurs
    `EndOfTable` - if thrown by a parameter

### evaluate

    public Object evaluate(int match_op,
                           Object match_value)
                    throws SQLException,
                           EndOfTable

  Evaluate parameters and compare.
  Overrides:
    `evaluate` in class `AbstractFunction`
  Parameters:
    `match_op` - how the value should be matched
    `match_value` - desired value
  Returns:
    result object
  Throws:
    `SQLException` - if a database-access error occurs
    `EndOfTable` - if thrown by a parameter

### testRow

    public static Boolean testRow(Object[] r1,
                                  Object[] r2,
                                  int op,
                                  int[] compare_type)
                           throws SQLException

  Compare two rows according to op and using compare_type array.
  Parameters:
    `r1` - left row
    `r2` - right row
    `op` - comparison operation
    `compare_type` - type to convert to for comparison
  Returns:
    result of comparison
  Throws:
    `SQLException` - if op is invalid or on type mismatch

### testRowInequality

    public static Boolean testRowInequality(Object[] r1,
                                            Object[] r2,
                                            int op,
                                            int[] compare_type)
                                     throws SQLException

  Compare two rows according to op (inequalities only) and using compare_type array.
  Parameters:
    `r1` - left row
    `r2` - right row
    `op` - comparison operation
    `compare_type` - type to convert to for comparison
  Returns:
    result of comparison
  Throws:
    `SQLException` - if op is invalid or on type mismatch

### test

    public static boolean test(Object v1,
                               Object v2,
                               int op,
                               int compare_type)
                        throws SQLException

  Compare two objects according to op.
  Parameters:
    `v1` - left value
    `v2` - right value
    `op` - comparison operation
    `compare_type` - type to convert to for comparison
  Returns:
    result of comparison
  Throws:
    `SQLException` - if op is invalid or on type mismatch

### test

    public boolean test(Object v1,
                        Object v2)
                 throws SQLException

### test

    public static boolean test(Object v1,
                               Object v2,
                               Object v3,
                               int compare_type)
                        throws SQLException

### test

    public boolean test(Object v1,
                        Object v2,
                        Object v3)
                 throws SQLException

### equal

    public static boolean equal(Object v1,
                                Object v2,
                                int common_type)

  Check if two objects are equal by converting to a common type.
  Parameters:
    `v1` - left value
    `v2` - right value
    `compare_type` - type to convert to for comparison
  Returns:
    true if the objects are equal

### compare

    public static int compare(Object v1,
                              Object v2,
                              int common_type)
                       throws SQLException

  Compare two objects by converting to a common type.
  Parameters:
    `v1` - left value
    `v2` - right value
    `compare_type` - type to convert to for comparison
  Returns:
    negative if v1<v2, positive if v1>v2, 0 if equal
  Throws:
    `SQLException` - if type mismatch

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD