: Class AbstractAggregate

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 AbstractAggregate

    java.lang.Object
      |
      +--ModSQL.AbstractFunction
            |
            +--ModSQL.AbstractAggregate

All Implemented Interfaces:
  Aggregate, Function

Direct Known Subclasses:
  Aggregate_Count, Aggregate_Math, Aggregate_MinMax

public abstract class AbstractAggregate
extends AbstractFunction
implements Aggregate

Abstract implementation of Aggregate to simplify the implementation of real aggregate functions.

Author:
  chris.studholme@utoronto.ca

Field Summary
`protected boolean` | `distinct` True if the aggregate should eliminate duplicate values before aggregating.
`protected HashSet` | `distinct_set` Hash table used to eliminate duplicate values.

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
`AbstractAggregate()`

Method Summary
`boolean` | `addDistinctValue(Object value)` Add a value to the set of distinct values.
`int` | `getDistinctSetSize()` Get the size of the set of distinct values.
`boolean` | `isAggregate()` Aggregate functions will always return true when isAggregate() is called, unless one of the parameters is an aggregate.
`boolean` | `isConstant()` Determine if this function returns a constant value.
`String` | `prefixParameters()` Returns "DISTINCT" if distinct was requested, or "*" if the parameter list is empty and optimize() has already been called.
`void` | `registerWith(Object o)` This implementation blocks the registerWith() call if the supplied object is of type GroupByList to prevent ColumnValue's that appear in the GROUP BY list from mistakenly being labled as aggregate.
`void` | `reset()` This implemenation calls reset() for all parameters and clears the distinct_set hash table.
`void` | `setDistinct()` Specify that this aggregate should eliminate duplicate values before aggregating rows.

Methods inherited from class ModSQL.AbstractFunction
`addParameter, convertToSQLType, evaluate, evaluateConstantParameters, evaluateOrder, evaluateParameters, evaluateParameters, functionName, getCompatableType, getObjectSQLType, getParameter, getParameterCount, optimize, postfixParameters, toString`

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

Methods inherited from interface ModSQL.Function
`addParameter, evaluate, evaluate, evaluateOrder, getMaxResultSize, getParameter, getParameterCount, getSQLType, optimize`

Field Detail

### distinct

    protected boolean distinct

  True if the aggregate should eliminate duplicate values before aggregating.

### distinct_set

    protected HashSet distinct_set

  Hash table used to eliminate duplicate values.

Constructor Detail

### AbstractAggregate

    public AbstractAggregate()

Method Detail

### setDistinct

    public void setDistinct()
                     throws SQLException

  Specify that this aggregate should eliminate duplicate values before aggregating rows.
  Specified by:
    `setDistinct` in interface `Aggregate`
  Throws:
    `SQLException` - if DISTINCT is not allowed

### prefixParameters

    public String prefixParameters()

  Returns "DISTINCT" if distinct was requested, or "*" if the parameter list is empty and optimize() has already been called.
  Overrides:
    `prefixParameters` in class `AbstractFunction`
  Returns:
    "DISTINCT ", "*", or "" as needed

### registerWith

    public void registerWith(Object o)
                      throws SQLException

  This implementation blocks the registerWith() call if the supplied object is of type GroupByList to prevent ColumnValue's that appear in the GROUP BY list from mistakenly being labled as aggregate. Otherwise, super.registerWith() is used.
  Specified by:
    `registerWith` in interface `Function`
  Overrides:
    `registerWith` in class `AbstractFunction`
  Parameters:
    `o` - object to register with
  Throws:
    `SQLException` - if an error occurs

### isConstant

    public boolean isConstant()
                       throws SQLException

  Determine if this function returns a constant value. Aggregate functions are rarely constant (even if all of their parameters are constant) so this method always returns false.
  Specified by:
    `isConstant` in interface `Function`
  Overrides:
    `isConstant` in class `AbstractFunction`
  Returns:
    false
  Throws:
    `SQLException` - if an error occurs

### isAggregate

    public boolean isAggregate()
                        throws SQLException

  Aggregate functions will always return true when isAggregate() is called, unless one of the parameters is an aggregate. In this latter case, an exception is thrown as aggregates within aggregates are not allowed in SQL.
  Specified by:
    `isAggregate` in interface `Function`
  Overrides:
    `isAggregate` in class `AbstractFunction`
  Returns:
    true unless exception
  Throws:
    `SQLException` - if any parameters are aggregates

### reset

    public void reset()
               throws SQLException

  This implemenation calls reset() for all parameters and clears the distinct_set hash table. Derived classes should override this method (but still call it) to reset its state.

  Specified by:
    `reset` in interface `Function`
  Overrides:
    `reset` in class `AbstractFunction`
  Throws:
    `SQLException` - if an error occurs

### addDistinctValue

    public boolean addDistinctValue(Object value)

  Add a value to the set of distinct values. This method initializes distinct_set if null.
  Returns:
    true if the value was not already in the distinct set

### getDistinctSetSize

    public int getDistinctSetSize()

  Get the size of the set of distinct values.
  Returns:
    number of distinct values in hash table

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