Reusing criteria prev. builded

View: New views
5 Messages — Rating Filter:   Alert me  

Reusing criteria prev. builded

by Lucas Teixeira :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello 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. builded

by Lucas Teixeira :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Oh 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,

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: Re: Reusing criteria prev. builded

by ianroberts :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Lucas 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. builded

by Lucas Teixeira :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello 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:
Lucas 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. builded

by Lucas Teixeira :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

uh, 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!

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!!
On Sun, Nov 8, 2009 at 5:13 PM, Ian Roberts <i.roberts@...> wrote:
Lucas 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