: Class IndirectFunction

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 IndirectFunction

    java.lang.Object
      |
      +--ModSQL.IndirectFunction

All Implemented Interfaces:
  Function

final class IndirectFunction
extends Object
implements Function

Wrapper for some other function. This class is typically used to hold column names before the names can be looked up. It may also be used to make a function appear in two seperate locations (such as SELECT expressions appearing in the ORDER BY clause).

Author:
  chris.studholme@utoronto.ca

Field Summary
`private String` | `description` Text description of function (usually a column name).
`private boolean` | `force_aggregate` Make the function appear as an aggregate regardless of whether it is or not (used for GROUP BY columns).
`private Object` | `last_value` Last value returned by function (used for forced aggregates).
`private Function` | `value` Function being wrapped.

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

Constructor Summary
`IndirectFunction(String description)` Constructor.

Method Summary
`void` | `addParameter(Function item)` Adds a parameter to the list of parameters.
`Object` | `evaluate(boolean aggregate)` Evaluate the function and return the result.
`Object` | `evaluate(int match_op, Object match_value)` Calls the equivalent evaluate() method for the underlying function.
`void` | `evaluateOrder(int index, int order)` Specify the order in which the parameters should be evaluated.
`String` | `getDescription()` Get text description of function.
`Function` | `getFunction()` Get function being wrapped.
`int` | `getMaxResultSize()` Return the maximum number of characters that this function expects to return in a String object.
`Function` | `getParameter(int index)` Get a particular parameter.
`int` | `getParameterCount()` Get the number of parameters.
`int` | `getSQLType()` Return the SQL type of the value that this function expects to return.
`boolean` | `isAggregate()` Determine if this function will return a value that is an aggregate of many database rows.
`boolean` | `isConstant()` Determine if this function returns a constant value.
`void` | `optimize()` If the function has been set, it is optimized.
`void` | `registerWith(Object o)` This method responds to two objects: `FunctionProvider` to lookup the description if the function has not been set yet, and `Select.GroupByList` to check for GROUP BY columns that need to be forced to aggregate.
`void` | `reset()` Calls reset() for the underlying function and set the last value returned by evaluate() to null.
`String` | `toString()` Returns string version of function or description if function is not set yet.

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

Field Detail

### description

    private String description

  Text description of function (usually a column name).

### value

    private Function value

  Function being wrapped.

### force_aggregate

    private boolean force_aggregate

  Make the function appear as an aggregate regardless of whether it is or not (used for GROUP BY columns).

### last_value

    private Object last_value

  Last value returned by function (used for forced aggregates).

Constructor Detail

### IndirectFunction

    public IndirectFunction(String description)

  Constructor.
  Parameters:
    `description` - text description of function (column name)

Method Detail

### toString

    public String toString()

  Returns string version of function or description if function is not set yet.
  Overrides:
    `toString` in class `Object`
  Returns:
    human readable description of function

### getDescription

    public String getDescription()

  Get text description of function.
  Returns:
    text description of function

### getFunction

    public Function getFunction()

  Get function being wrapped.
  Returns:
    function being wrapped (null if not set)

### getParameterCount

    public int getParameterCount()

  Get the number of parameters. Returns 0 as parameters cannot be indirectly accessed.
  Specified by:
    `getParameterCount` in interface `Function`
  Returns:
    number of parameters

### getParameter

    public Function getParameter(int index)

  Get a particular parameter. Throws an exception as parameters cannot be indirectly accessed.
  Specified by:
    `getParameter` in interface `Function`
  Parameters:
    `index` - index of parameter to get
  Returns:
    parameter (function)
  Throws:
    `IndexOutOfBoundsException` - always

### addParameter

    public void addParameter(Function item)
                      throws SQLException

  Adds a parameter to the list of parameters. Throws an exception as parameters cannot be indirectly accessed.
  Specified by:
    `addParameter` in interface `Function`
  Parameters:
    `item` - function to add
  Throws:
    `SQLException` - always

### evaluateOrder

    public void evaluateOrder(int index,
                              int order)

  Specify the order in which the parameters should be evaluated. Throws an exception as parameters cannot be indirectly accessed.
  Specified by:
    `evaluateOrder` in interface `Function`
  Parameters:
    `index` - index of parameter
    `order` - number indicating order in which parameter is evaluated
  Throws:
    `IndexOutOfBoundsException` - always

### registerWith

    public void registerWith(Object o)
                      throws SQLException

  This method responds to two objects:

  - `FunctionProvider` to lookup the description if the function has not been set yet, and
  - `Select.GroupByList` to check for GROUP BY columns that need to be forced to aggregate.

  Otherwise, if the function has been set, the object is passed on to that function.

  Specified by:
    `registerWith` in interface `Function`
  Parameters:
    `o` - object to register with
  Throws:
    `SQLException` - if an error occurs

### optimize

    public void optimize()
                  throws SQLException

  If the function has been set, it is optimized. Otherwise, an exception is thrown.

  Specified by:
    `optimize` in interface `Function`
  Throws:
    `SQLException` - if an error occurs

### isConstant

    public boolean isConstant()
                       throws SQLException

  Determine if this function returns a constant value.
  Specified by:
    `isConstant` in interface `Function`
  Returns:
    true if the value returned is constant
  Throws:
    `SQLException` - if an error occurs

### isAggregate

    public boolean isAggregate()
                        throws SQLException

  Determine if this function will return a value that is an aggregate of many database rows. This method may return true in cases where the function is actually not an aggregate (in this case, aggregate has been forced).
  Specified by:
    `isAggregate` in interface `Function`
  Returns:
    true if the function aggregates several rows of data
  Throws:
    `SQLException` - if an error occurs

### getSQLType

    public int getSQLType()
                   throws SQLException

  Return the SQL type of the value that this function expects to return.
  Specified by:
    `getSQLType` in interface `Function`
  Returns:
    SQL type of data to be returned
  Throws:
    `SQLException` - if an error occurs

### getMaxResultSize

    public int getMaxResultSize()
                         throws SQLException

  Return the maximum number of characters that this function expects to return in a String object.
  Specified by:
    `getMaxResultSize` in interface `Function`
  Returns:
    maximum size of String returned or -1 if unknown
  Throws:
    `SQLException` - if an error occurs

### evaluate

    public Object evaluate(boolean aggregate)
                    throws SQLException,
                           EndOfTable

  Evaluate the function and return the result. If aggregate is true, but the function is not an aggregate and aggregate is being forced, the last value returned by evaluate is returned again. In this case, if evaluate() has never been called, null is returned.
  Specified by:
    `evaluate` in interface `Function`
  Parameters:
    `aggregate` - true to get final aggregate value
  Returns:
    result object
  Throws:
    `SQLException` - if an error occurs
    `EndOfTable` - if thrown by the function

### evaluate

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

  Calls the equivalent evaluate() method for the underlying function.
  Specified by:
    `evaluate` in interface `Function`
  Parameters:
    `match_op` - how the value should be matched
    `match_value` - desired value
  Returns:
    result object
  Throws:
    `SQLException` - if an error occurs
    `EndOfTable` - if thrown by the function

### reset

    public void reset()
               throws SQLException

  Calls reset() for the underlying function and set the last value returned by evaluate() to null.
  Specified by:
    `reset` in interface `Function`
  Throws:
    `SQLException` - if an error occurs

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