SelectJoinStep baseQuery = jooq
.select(SEASON.YEAR, SEASON.WIKIPEDIA_URL)
.from(SEASON);
Query countQuery = jooq
.selectCount()
.from(baseQuery);
Query pagedQuery = baseQuery
.orderBy(toOrderBy(pageable))
.limit(pageable.getPageSize())
.offset(pageable.getOffset());
System.out.println("countQuery => " + countQuery.getSQL());
System.out.println("pagedQuery => " + pagedQuery.getSQL());
Maybe even taking it a little bit further.Would it be possible if I have a org.jooq.Query that I can construct a new Query object from it with an added orderBy, offset and limit?
On Monday, June 6, 2016 at 3:01:50 PM UTC+2, Marcel Overdijk wrote:PS: would it be a good idea to start a jooq gitter room for discussions?
protected <T> Page<T> queryForPage(SelectJoinStep baseQuery, Pageable pageable,
RowMapper<T> rowMapper) {
jooq
.selectCount()
.from(baseQuery);
baseQuery
.orderBy(toOrderBy(pageable))
.limit(pageable.getPageSize())
.offset(pageable.getOffset());
Regarding the mutability of the Query would it be possible to clone a (base) Query?
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.
But in case I create the paged query before the count query the baseQuery was already altered which might be error prone.
protected <T> Page<T> queryForPage(SelectJoinStep baseQuery, Pageable pageable,
RowMapper<T> rowMapper) {
public Page<Season> findAll(Pageable pageable) {
SelectJoinStep baseQuery = jooq
.select(
SEASON.YEAR,
SEASON.WIKIPEDIA_URL)
.from(SEASON);
return queryForPage(baseQuery, pageable, seasonRowMapper);
}
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(Supplier<SelectJoinStep> baseQuery, Pageable pageable,
RowMapper<T> rowMapper) {
queryForPage( () -> select(TABLE.A, TABLE.B).from(TABLE), pageable, mapper );