user manual
180 BES Developer’s Guide
Aggregate Functions in EJB-QL
l.lineItemId=?1</ejb-ql>
</query>
The return types of the EJB-QL query method are:
■
If the Java type of the cmp-field is an object type, and the query method is a
single-object query method, the return type is an instance of that object
type.
■
If the Java type of the cmp-field is an object type and the query method
returns multiple objects, a collection of instances of the object type is
returned.
■
If the Java type of the cmp-field is a primitive Java type, and the SELECT
method is a single-object method, the return type is that primitive type.
■
If the Java type of the cmp-field is a primitive Java type, and the SELECT
method is for multiple objects, a collection of the wrappered Java type is
returned.
Selecting a ResultSet
When more than one cmp-field is to be returned by a single query method, the
return type must be of type ResultSet. This allows you to select multiple cmp-
fields from the same or multiple EJBs in the same query method. You then
write code to extract the desired data from the ResultSet. This feature is a
Borland extension of the CMP 2.x specification.
Aggregate Functions in EJB-QL
Aggregate functions are MIN, MAX, SUM, AVG, and COUNT. For the
aggregate functions MIN, MAX, SUM, and AVG, the path expression that
forms the argument for the function must terminate in a cmp-field. Also,
database queries for MAX, MIN, SUM, and AVG will return a null value if there
are no rows correspoding to the argument to the aggregate function. If the
return type is an object-type, then null is returned. If the return type is a
primitive type, then the container will throw a ObjectNotFoundException (a sub-
class of FinderException) if there is no value in the query result.
The path expression to the COUNT functions may terminate in either a cmp-
field or cmr-field, or may be an identification variable.
For example, the following EJB-QL aggregate function terminates in a CMP
field:
<query>
<query-method>
<method-name>ejbSelectMaxLineItemId</method-name>
<method-params>
<method-param>java.lang.String</method-param>
</method-params>
</query-method>










