Klasse AggregateFunction

java.lang.Object
org.apache.torque.util.functions.AggregateFunction
Alle implementierten Schnittstellen:
Column, SQLFunction
Bekannte direkte Unterklassen:
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 1867515 2019-09-25 15:02:03Z gk $
Autor:
Greg Monroe
  • Konstruktordetails

    • AggregateFunction

      protected AggregateFunction(String function, Column column, boolean distinct)
      Constructor for aggregate functions.
      Parameter:
      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.
  • Methodendetails

    • getColumn

      public Column getColumn()
      Returns the column the function is applied to.
      Angegeben von:
      getColumn in Schnittstelle SQLFunction
      Gibt zurück:
      the column, not null.
    • setColumn

      public void setColumn(Column column)
      Sets the column the function is applied to.
      Parameter:
      column - the column, not null.
    • isDistinct

      public boolean isDistinct()
      Should the column have DISTINCT added in front of it?
      Gibt zurück:
      True if DISTINCT is needed.
    • getFunction

      protected String getFunction()
      Get the function name to use, e.g. AVG, MIN, LEAST.
      Gibt zurück:
      The function name.
    • setFunction

      public void setFunction(String function)
      Set the function name to use, e.g. AVG, MIN, LEAST.
      Parameter:
      function - The function name to use, not null or blank.
      Löst aus:
      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.
      Angegeben von:
      getSqlExpression in Schnittstelle Column
      Gibt zurück:
      the SQL expression for the column, not null.
      Löst aus:
      IllegalStateException - if the arguments are not set
    • getArgument

      public Object getArgument(int i)
      Beschreibung aus Schnittstelle kopiert: SQLFunction
      Returns the function parameters at index i. Should be null if parameter does not exist.
      Angegeben von:
      getArgument in Schnittstelle SQLFunction
      Parameter:
      i - The 0 based parameter to get.
      Gibt zurück:
      The parameter. Null if one does not exist.
    • getArguments

      public Object[] getArguments()
      Beschreibung aus Schnittstelle kopiert: 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.
      Angegeben von:
      getArguments in Schnittstelle SQLFunction
      Gibt zurück:
      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.
      Angegeben von:
      setArguments in Schnittstelle SQLFunction
      Parameter:
      args - The column to apply the function to.
      Löst aus:
      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.
      Angegeben von:
      getColumnName in Schnittstelle Column
      Gibt zurück:
      the column name, always null.
    • getTableName

      public String getTableName()
      Beschreibung aus Schnittstelle kopiert: Column
      Returns the name of the associated table (not prefixed by the schema name).
      Angegeben von:
      getTableName in Schnittstelle Column
      Gibt zurück:
      the name of the table, may be null but not blank.
    • getSchemaName

      public String getSchemaName()
      Beschreibung aus Schnittstelle kopiert: Column
      Returns the name of any fixed schema prefix for the column's table (if any).
      Angegeben von:
      getSchemaName in Schnittstelle Column
      Gibt zurück:
      the schema name, or null if the schema is not known.
    • getFullTableName

      public String getFullTableName()
      Beschreibung aus Schnittstelle kopiert: 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.
      Angegeben von:
      getFullTableName in Schnittstelle Column
      Gibt zurück:
      the fully qualified table name of the column, may be null but not blank.