R
- class type which contains members for columns of a row in a tableT
- class type of aggregate resultpublic class SelectAggregateOperation<R,T> extends ScalarSelectOperation<R>
SqlOperation.setWhere(String)
to limit
to a subset of rows. To get the result, use readAggregate()
.
If expression is a column, then T should be same type as column type in row class R. Column translator associated with column in row R will be used.
If expression is not a column, then T should match the expression type. Override readAggregate()
to provide a customized read for expression. By default where expression is not a column name, then
ResultSet.getObject(int)
is used.
Constructor and Description |
---|
SelectAggregateOperation(Table<R> table,
java.lang.String function,
java.lang.String expression)
Constructs for standard sql select statement as:
SELECT f(e), ... |
Modifier and Type | Method and Description |
---|---|
protected void |
initBaseSql()
Sets base sql with
SqlOperation.setBaseSql(String) . |
T |
readAggregate()
Reads the aggregate value from the current result set.
|
addFilter, close, execute, getFilterPredicateMap, getMaximumRowsRead, getOrderByName, getOrderByTranslator, getResultSet, getRowsReadCount, getSql, isExecuted, isLazySelectsCascades, isNotifyLazySelects, iterator, positionAbsolute, positionRelative, postRead, postReadCascade, prepareCascades, preRead, preReadCascade, readNext, removeFilter, resetRowsReadCount, select, select, setFilterPredicateMap, setMaximumRowsRead, setOrderBy, setOrderByTranslator, setParameters, setRowParameters, updateActiveFilterPredicate
cancel, cascade, closeCascades, closeStatement, createRowField, getBaseSql, getCascadeDepth, getConnection, getCustomSql, getNamedParameterMap, getNextParameter, getOperationTime, getParameter, getParameters, getPreparedSql, getPreparedStatement, getQueryTimeout, getRequiredCascades, getTable, getTargetTable, getTimingId, getWhereAnnotation, getWhereConditionName, getWhereTranslator, initOperationTime, isCached, isCascade, isCascading, isIncludeIdentityColumns, isPrimaryKey, isReadOnly, isRequiredCascade, isTimings, logTimings, prepare, prepareCascades, prepareCheck, prepareStatement, setBaseSql, setCached, setCascade, setCascadeDepth, setCustomSql, setIncludeIdentityColumns, setNamedParameterMap, setNextParameter, setParameter, setQueryTimeout, setReadOnly, setRequiredCascades, setTimingId, setTimings, setWhere, setWhereTranslator, writeColumns, writeParameter, writeParameters, writeWhere
public SelectAggregateOperation(Table<R> table, java.lang.String function, java.lang.String expression) throws OperationException
Example:
Database database = ... Table<Order> table = database.getTable(Order.class); // find largest order SelectAggregateOperation<Order> maxOrderOperation = new SelectAggregateOperation<Order, Double>(table, "MAX", "amount"); maxOrderOperation.execute(); double maxOrder = maxOrderOperation.readAggregate();
table
- select from this tablefunction
- aggregate function name like AVG, SUM, MIN, etc.expression
- expression to use as parameter to function; typically it is the
name of a column to that aggregate function operates upon (example: SUM(amount) SUM is function and
amount is expression)OperationException
- if errorprotected void initBaseSql()
SqlOperation.setBaseSql(String)
.initBaseSql
in class ScalarSelectOperation<R>
public T readAggregate() throws OperationException
OperationException
- if error