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

## org.apache.torque.util.functions
Class AggregateFunction

    java.lang.Object
      org.apache.torque.util.functions.AggregateFunction

All Implemented Interfaces:
  Column, SQLFunction

Direct Known Subclasses:
  Avg, Count, Max, Min, Sum

    public class AggregateFunction

extends Object
implements SQLFunction

A container for classes that will generate SQL for the SQL99 Standard Aggregate functions. These can be used via the Criteria.addSelectColumn method to produce SQL statements that can be called via the BasePeerImpl.doSelect methods.

Note database servers that use non-standard function names can be supported by setting the function name in the constructor accordingly.

E.g., older MySQL servers use LEAST instead of MIN. This can be supported by supplying "LEAST" as function name.

Version:
  $Id: AggregateFunction.java 1448414 2013-02-20 21:06:35Z tfischer $
Author:
  Greg Monroe

Constructor Summary
`protected` | `AggregateFunction(String function, Column column, boolean distinct)` Constructor for aggregate functions.

Method Summary
`Object` | `getArgument(int i)` Returns the function parameters at index i.
`Object[]` | `getArguments()` Return all the parameters as an object array.
`Column` | `getColumn()` Returns the column the function is applied to.
`String` | `getColumnName()` Returns the column name.
`String` | `getFullTableName()` Returns the table name prefixed with the schema name if it exists.
`protected String` | `getFunction()` Get the function name to use, e.g.
`String` | `getSchemaName()` Returns the name of any fixed schema prefix for the column's table (if any).
`String` | `getSqlExpression()` Generate the SQL for this function.
`String` | `getTableName()` Returns the name of the associated table (not prefixed by the schema name).
`boolean` | `isDistinct()` Should the column have DISTINCT added in front of it?
`void` | `setArguments(Object[] args)` Assumes that there are one or two arguments being specified.
`void` | `setColumn(Column column)` Sets the column the function is applied to.
`void` | `setFunction(String function)` Set the function name to use, e.g.

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

Constructor Detail

### AggregateFunction

    protected AggregateFunction(String function,
                                Column column,
                                boolean distinct)

  Constructor for aggregate functions.

  Parameters:
    `function` - the function name, not null or blank.
    `column` - the column to apply the function to, not null.
    `distinct` - whether to apply DISTINCT to the column.

Method Detail

### getColumn

    public Column getColumn()

  Returns the column the function is applied to.

  Specified by:
    `getColumn` in interface `SQLFunction`
  Returns:
    the column, not null.

### setColumn

    public void setColumn(Column column)

  Sets the column the function is applied to.

  Parameters:
    `column` - the column, not null.

### isDistinct

    public boolean isDistinct()

  Should the column have DISTINCT added in front of it?

  Returns:
    True if DISTINCT is needed.

### getFunction

    protected String getFunction()

  Get the function name to use, e.g. AVG, MIN, LEAST.

  Returns:
    The function name.

### setFunction

    public void setFunction(String function)

  Set the function name to use, e.g. AVG, MIN, LEAST.

  Parameters:
    `function` - The function name to use, not null or blank.
  Throws:
    `UnsupportedOperationException` - if a subclass does not support changing the function name; never thrown by this implementation.

### getSqlExpression

    public String getSqlExpression()

  Generate the SQL for this function.

  Specified by:
    `getSqlExpression` in interface `Column`
  Returns:
    the SQL expression for the column, not null.
  Throws:
    `IllegalStateException` - if the arguments are not set

### getArgument

    public Object getArgument(int i)

  Description copied from interface: `SQLFunction`
  Returns the function parameters at index i. Should be null if parameter does not exist.

  Specified by:
    `getArgument` in interface `SQLFunction`
  Parameters:
    `i` - The 0 based parameter to get.
  Returns:
    The parameter. Null if one does not exist.

### getArguments

    public Object[] getArguments()

  Description copied from interface: `SQLFunction`
  Return all the parameters as an object array. This allow for processing of the parameters in their original format rather than just in String format. E.g. a parameter might be specified as a Date object, or a Column object.

  Specified by:
    `getArguments` in interface `SQLFunction`
  Returns:
    Should return a valid Object array and not null. E.g. implementors should return new Object[0] if there are no parameters.

### setArguments

    public void setArguments(Object[] args)

  Assumes that there are one or two arguments being specified. The first being a column identifier, and the second being an optional boolean indicating if DISTINCT needs to be added.

  Specified by:
    `setArguments` in interface `SQLFunction`
  Parameters:
    `args` - The column to apply the function to.
  Throws:
    `IllegalArgumentException` - If at least one argument has not been supplied or the second argument object is not Boolean.

### getColumnName

    public String getColumnName()

  Returns the column name. This implementation always return null because we do not reference a real column.

  Specified by:
    `getColumnName` in interface `Column`
  Returns:
    the column name, always null.

### getTableName

    public String getTableName()

  Description copied from interface: `Column`
  Returns the name of the associated table (not prefixed by the schema name).

  Specified by:
    `getTableName` in interface `Column`
  Returns:
    the name of the table, may be null but not blank.

### getSchemaName

    public String getSchemaName()

  Description copied from interface: `Column`
  Returns the name of any fixed schema prefix for the column's table (if any).

  Specified by:
    `getSchemaName` in interface `Column`
  Returns:
    the schema name, or null if the schema is not known.

### getFullTableName

    public String getFullTableName()

  Description copied from interface: `Column`
  Returns the table name prefixed with the schema name if it exists. I.e. if a schema name exists, the result will be schemaName.tableName, and otherwise it will just be tableName.

  Specified by:
    `getFullTableName` in interface `Column`
  Returns:
    the fully qualified table name of the column, may be null but not blank.

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

Copyright © 2000-2013 The Apache Software Foundation. All Rights Reserved.