ModSQL
Class Aggregate_Count
java.lang.Object
|
+--ModSQL.AbstractFunction
|
+--ModSQL.AbstractAggregate
|
+--ModSQL.Aggregate_Count
- All Implemented Interfaces:
- Aggregate, Function
- final class Aggregate_Count
- extends AbstractAggregate
Implementation of SQL aggregate function COUNT().
- Author:
- chris.studholme@utoronto.ca
|
Field Summary |
private long |
count
Current count. |
private boolean |
count_all
True if we are counting rows, false to count non-null values. |
| Methods inherited from class ModSQL.AbstractFunction |
convertToSQLType, evaluate, evaluateConstantParameters, evaluateOrder, evaluateParameters, evaluateParameters, getCompatableType, getObjectSQLType, getParameter, getParameterCount, postfixParameters, toString |
| Methods inherited from class java.lang.Object |
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait |
count_all
private boolean count_all
- True if we are counting rows, false to count non-null values.
count
private long count
- Current count.
Aggregate_Count
Aggregate_Count()
forName
public static Function forName(String name)
- Returns a new instance of this class if name is "count".
- Parameters:
name - name of function to find- Returns:
- instance of this class or null if name does not match
addParameter
public void addParameter(Function item)
throws SQLException
- Adds a value (function) to the list of parameters maintained by this
function.
- Overrides:
addParameter in class AbstractFunction
- Parameters:
item - function to add- Throws:
SQLException - if too many parameters have been added
optimize
public void optimize()
throws SQLException
Prepare the function for use. COUNT() requires exactly one
parameter, unless count_all, in which case no parameters are acceptable.
If we are doing COUNT(DISTINCT ...), we require a parameter.
- Overrides:
optimize in class AbstractFunction
- Throws:
SQLException - if the parameters are invalid
functionName
public String functionName()
- Returns "COUNT".
- Overrides:
functionName in class AbstractFunction
- Returns:
- name of function
getSQLType
public int getSQLType()
- COUNT always returns BIGINT integers.
- Returns:
- SQL type of data to be returned
getMaxResultSize
public int getMaxResultSize()
- Returns -1.
- Returns:
- maximum size of String returned or -1 if unknown
reset
public void reset()
throws SQLException
- Resets the current count to zero.
- Overrides:
reset in class AbstractAggregate
- Throws:
SQLException - if a database error occurs
evaluate
public Object evaluate(boolean aggregate)
throws SQLException,
EndOfTable
Evaluate the parameter and update the count. If aggregate is
true, the current count is returned and the parameter is not evaluated.
This method returns null if aggregate is false.
- Parameters:
aggregate - true to return current count- Returns:
- Long object if aggregate is true, null otherwise
- Throws:
SQLException - if a database-access error occursEndOfTable - if thrown by a parameter