String someName = ".."
String sql = jooq
.select(
field("first_name"),
field("last_name"))
.from(
table("driver"))
.where(
field("last_name").equal(someName))
.orderBy(
field("first_name").asc())
.getSQL(ParamType.INLINED);
I want to basically reuse this base query to actually:1) select the count for the given base from/where.2) extend the query to limit the result set to given page size/offset.Would it be possible to create some base part query and then change the select cause (count vs. actual columns) and the where (add pagesize/offset) and perform the 2 queries?
Select<?> select = jooq.select(...) // Your existing SELECTint count = jooq.fetchCount(select);Result<?> page = jooq.selectFrom(table(select)).limit(...).offset(...).fetch();
public Select<?> drivers(Integer limit, Integer offset, Field<?>... selectColumns) {return jooq.select(selectColumns)
.from(table("driver")).where(field("last_name").equal(someName)).orderBy(field("first_name").asc())
.limit(limit == null ? Integer.MAX_VALUE : limit).offset(offset == null ? 0 : offset);}
--
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 jooq-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Table<?> table = table("driver")
.join(table("country"))
.on(field("driver.country_id").equal(field("country.id")))
.join(table("continent"))
.on(field("country.continent_id").equal(field("continent.id")));
Condition where = field("driver.last_name").equal("Verstappen")
.and(field("country.id").equal("NL"));
SortField<?> orderBy[] = new SortField<?>[]{
field("driver.last_name").asc(),
field("driver.first_name").asc()
};
Select<?> count = jooq.selectCount()
.from(table)
.where(where);
Select<?> paged = jooq.select(
field("driver.first_name"),
field("driver.last_name"),
field("driver.full_name"),
field("country.id"),
field("country.name"),
field("continent.id"),
field("continent.name"))
.from(table)
.where(where)
.orderBy(orderBy)
.limit(10)
.offset(0);
1. I'm using the static table(..) and field(..) methods. Is this ok as it does not go through my DSLContext instance?
2. Is there an easier way to construct the order by? Instead of creating a SortField<?>[] something like field(..).asc().and().field(..).asc() would be useful. Just like building the condition. Maybe this can be done already with current api?
--
Condition where = some empty condition;
if (StringUtils.isNotBlank(country)) {
where = where.and(field("country.id").equal(country));
}
if (StringUtils.isNotBlank(name)) {
where = where.and(field("driver.full_name").likeIgnoreCase(name));
}
Condition where = field("1").equal(1);
One quick question though.Is it possible to create an empty condition or something similar?