|
View:
New views
5 Messages
—
Rating Filter:
Alert me
|
|
|
Reusing criteria prev. buildedHello all,
I'm building a complex query using gorm criteria, and I'll have to use it 2 times, first one using the "list" method to retrieve its results and then I'll use it again with the 'get' method to count the results. I can't get the result list size to get number of returned rows cause I'm cutting it with max and offset params. So, I'm building the same criteria twice... First time this way: listaUnidades = criteria.list(max:formData.qtParam, offset:firstResult) { and { ... //all my conditionals } } and the second time this way: qtdeResultados = criteria.get() { and { ... //all the same conditionals } } I'd like to know if I can build the criteria closure outside it and just reuse the same reference instead of making this way I'm doing right now. Thanks! []s, Lucas Frare Teixeira .·. - lucastex@... - lucastex.com.br - blog.lucastex.com - twitter.com/lucastex |
|
|
Re: Reusing criteria prev. buildedOh sorry,
Actually, the second time, I'm using with projections { rowCount() } to count the rows. []s Lucas Frare Teixeira .·. - lucastex@... - lucastex.com.br - blog.lucastex.com - twitter.com/lucastex On Sun, Nov 8, 2009 at 1:53 PM, Lucas F. A. Teixeira <lucastex@...> wrote: Hello all, |
|
|
Re: Re: Reusing criteria prev. buildedLucas F. A. Teixeira wrote:
> Oh sorry, > > Actually, the second time, I'm using with > > projections { > rowCount() > } > > to count the rows. You could do something like: def conditionals = { and { // all my conditionals } } listaUnidades = criteria.list(max:formData.qtParam, offset:firstResult, conditionals) qtdeResultados = criteria.get() { conditionals.delegate = delegate conditionals() projections { rowCount() } } But for this particular use case you don't need to - when you invoke criteria.list with pagination parameters the object it returns has a totalResults property which is exactly what your get() call is calculating. qtdeResultadoc = listaUnidades.totalResults Ian -- Ian Roberts | Department of Computer Science i.roberts@... | University of Sheffield, UK --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: Re: Reusing criteria prev. buildedHello Ian!
Thanks a lot! But I couldn't find the 'totalResults' property you said. I've looked into the docs for the PagedResultList and the only thing similiar I found is the 'totalCount' property, witch returns me not the total count, but only the size of the returned list (im my case 5 - the size of my page). Is this the correct one? Thanks!! Lucas Frare Teixeira .·. - lucastex@... - lucastex.com.br - blog.lucastex.com - twitter.com/lucastex On Sun, Nov 8, 2009 at 5:13 PM, Ian Roberts <i.roberts@...> wrote:
|
|
|
Re: Re: Reusing criteria prev. buildeduh, my bad. :)
this is the correct one... 'totalCount' :) Thanks again Ian! []s, Lucas Frare Teixeira .·. - lucastex@... - lucastex.com.br - blog.lucastex.com - twitter.com/lucastex On Sun, Nov 8, 2009 at 11:38 PM, Lucas F. A. Teixeira <lucastex@...> wrote: Hello Ian! |
| Free embeddable forum powered by Nabble | Forum Help |