Hi Lukas,

I'm not worried about saving the CPU cycles.
The reason I would like to recycle these objects as I would be able to use 
some generic utility methods like:

protected <T> Page<T> queryForPage(SelectJoinStep baseQuery, Pageable pageable,
        RowMapper<T> rowMapper) {


I would only need to provide a baseQuery in this case with a pageable 
object.
The utility method then simply executes 2 queries after tweaking the 
baseQuery and constructs the Page to be returned.

That way I could do something like in my repositories:

public Page<Season> findAll(Pageable pageable) {
    SelectJoinStep baseQuery = jooq
            .select(
                    SEASON.YEAR,
                    SEASON.WIKIPEDIA_URL)
            .from(SEASON);
    return queryForPage(baseQuery, pageable, seasonRowMapper);
}


 which is very powerful imo.

Currently by executing the selectCount().from(baseQuery) does not affect 
the baseQuery so I just have to make sure I run that first :-)


Marcel


On Tuesday, June 7, 2016 at 6:39:33 PM UTC+2, Lukas Eder wrote:
>
> Hi Marcel,
>
> 2016-06-07 10:16 GMT+02:00 Marcel Overdijk <[email protected] 
> <javascript:>>:
>
>> Regarding the mutability of the Query would it be possible to clone a 
>> (base) Query?
>>
>
> Right now, no. jOOQ query parts are not cloneable.
>  
>
>> I'm creating some utility methods like:
>>
>> protected <T> Page<T> queryForPage(SelectJoinStep baseQuery, Pageable 
>> pageable,
>>         RowMapper<T> rowMapper) {
>>
>>
>> From that baseQuery I want to create a count query and paged query (note 
>> windowing functions is not supported in my database).
>>
>> When I first construct the count query like:
>>
>> jooq
>>         .selectCount()
>>         .from(baseQuery);
>>
>>
>>
>>
>> and then paged query like:
>>
>> baseQuery
>>         .orderBy(toOrderBy(pageable))
>>         .limit(pageable.getPageSize())
>>         .offset(pageable.getOffset());
>>
>>
>> I think it should be ok as I believe the selectCount() will not alter the 
>> baseQuery.
>>
>
> That's correct, but you have to make sure you execute the first query 
> before you modify the base query for the latter case.
>  
>
>> But in case I create the paged query before the count query the baseQuery 
>> was already altered which might be error prone.
>>
>
> Yes.
>
> I don't think you're saving a lot of CPU cycles this way. Personally, I'd 
> just rather not recycle these objects.
> Lukas
>

-- 
You received this message because you are subscribed to the Google Groups "jOOQ 
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to