user3278460
user3278460

Reputation:

JOOQ empty condition

Is there way to define empty condition which produces nothing in output sql query? Now, for default condition I use trueCondition()

private static Condition limitCondition(Integer offset, Integer count) {
    Condition limitCondition = trueCondition();
    if (count != null && offset != null) {
        limitCondition = rowNum.between(offset, count + offset);
    } else if (count == null && offset != null) {
        limitCondition = rowNum.greaterOrEqual(offset);
    } else if (count != null && offset == null) {
        limitCondition = rowNum.lessOrEqual(count);
    }
    return limitCondition;
}

Upvotes: 16

Views: 10432

Answers (2)

Lukas Eder
Lukas Eder

Reputation: 221350

There is DSL.noCondition() starting with jOOQ 3.11, which can act as an identity for both AND and OR operators, and doesn't produce any output unless strictly required (e.g. when projecting it in SELECT), in case of which it acts like DSL.trueCondition()

For more details, see:

Upvotes: 30

Muhammed Saed
Muhammed Saed

Reputation: 41

Maybe a bit too late for this but on 3.14 version, there is a static method you can use.

Condition result = trueCondition();

refer: jooq documentation

Upvotes: 4

Related Questions