[Building Sakai] generic DAO question

Aaron Zeckoski aaronz at vt.edu
Fri Feb 19 03:32:01 PST 2010


The genericdao stuff only handles the 80% use cases so it will not
return fields only. It returns the entire objects. If you are dealing
with smaller sets I would just get all the objects back and pull the
fields out into a set which will get you unique results. If you are
concerned about performance over very large sets (10000+ objects) then
it will be more efficient to write a method to pull the data via HQL
like you are doing and place this method in the DAO.

You will need the object to be capitalized correctly though:
EvalmonitorItem should be EvalMonitorItem. You need to use the
distinct keyword if you want to eliminate duplicate results.
Also I normally only write a single = in HQL. It may work with == but
that's not documented.
One last thing, dates are normally easiest to deal with in HQL by
using a date object and referring to it using an hql variable. I have
had a lot of trouble with trying to represent the date as a string in
the query.
http://docs.jboss.org/hibernate/core/3.3/reference/en/html/queryhql.html

-AZ


On Thu, Feb 18, 2010 at 8:55 PM, Jim Eng <jimeng at umich.edu> wrote:
> Hi Aaron,
>
> I have an object of type org.sakaiproject.genericdao.api.search.Search that
> expresses a set of Restrictions. I would like to do a query that gets the
> set of values for a particular property from the set of things selected by
> this Search.  It looks to me like I may need to implement a special method
> in my project's DAO that would turn the Search object into part of an HQL
> statement to select the unique values for the property where the
> Restrictions of the search are honored.  Does that sound right?  Or is there
> some way to use the search object directly?
>
> To give you an idea of what I'm looking at, I think the HQL might look
> something like this:
>
> select item.importOrderId from EvalmonitorItem item where item.createdDate <
> 'yyyy-mm-dd' and item.entityType == 'EvalTemplate' group by
> item.importOrderId
>
> where the Search object has two Restrictions (one for "createdDate" and one
> for "entityType").  But I don't know whether this is correct HQL and whether
> it eliminates duplicate values (as I'd like).
>
> Any suggestions?
>
> Thanks.
>
> Jim
>



-- 
Aaron Zeckoski (azeckoski (at) vt.edu)
Senior Research Engineer - CARET - University of Cambridge
https://twitter.com/azeckoski - http://www.linkedin.com/in/azeckoski
http://aaronz-sakai.blogspot.com/ - http://tinyurl.com/azprofile


More information about the sakai-dev mailing list