Hi,
The QueryByCriteria returns a collection of populated objects; in your
QueryByCriteria example, it would returns list of Person objects.
The ReportQuery allows you to specify what columns to return, relative to
the specified class; instead of returning an object for each result of the
query (as above), it returns an array containing the values of the specified
columns. It also allows you to request aggregate columns...
I think the example should go a little further :
Criteria crit = new Criteria();
ReportQueryByCriteria q = QueryFactory.newReportQuery(
ProductGroup.class, crit);
// define the 'columns' of the report
q.setColumns(new String[] { "groupName",
"sum(allArticlesInGroup.stock)",
"sum(allArticlesInGroup.price)" });
q.addGroupBy("groupName");
// Process results using an iterator
Iterator iter = broker.getReportQueryIteratorByQuery(q);
while(iter.hasNext()){
Object[] data = (Object[]) iter.next();
String groupName = data[0];
Integer totalStock = data[1];
Integer totalPrice = data[2];
}
// Process results using a collection
Collection results = broker.getCollectionByQuery(q);
for (Iterator it = results.iterator(); it.hasNext();) {
Object[] data = (Object[]) iter.next();
String groupName = data[0];
Integer totalStock = data[1];
Integer totalPrice = data[2];
}
And finally, the QueryFactory.newReportQuery method is defined as returning
a ReportQueryByCriteria and not a ReportQuery interface, so the example is
correct - even though it may be cleaner to use the interface. I guess this
would be unlikely to change in the near future, as it would involve changing
an established interface close to a final release 1.0.
HTH
Charles.
> -----Original Message-----
> From: Anthony Carlos [mailto:[EMAIL PROTECTED]
> Sent: 29 January 2004 03:46
> To: [EMAIL PROTECTED]
> Subject: Easy question
>
>
> I read the page on queries: http://db.apache.org/ojb/query.html#report
>
> I noticed two kinds of queries. First, a QueryByCriteria:
> Query q = QueryFactory.newQuery(Person.class, crit);
>
> And second, a ReportQueryByCriteria:
> ReportQueryByCriteria q =
> QueryFactory.newReportQuery(ProductGroup.class, crit);
>
> What's the difference between the two? After looking at 60+
> messages in
> the mail archive, I'm guessing that it's the fact that the
> ReportQueryByCriteria allows the creation of
> summary/aggregate columns
> such as max(), min(), avg(), ...
>
> Am I right?
>
> Also, shouldn't the example for ReportQueryByCriteria declare q as:
>
> ReportQuery q =
> QueryFactory.newReportQuery(ProductGroup.class, crit);
> // Use the ReportQuery interface instead of the ReportQueryByCriteria
> class
>
> Thanks for the help!
>
> -Anthony
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
___________________________________________________________
HPD Software Ltd. - Helping Business Finance Business
Email terms and conditions: www.hpdsoftware.com/disclaimer
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]