简体   繁体   中英

How to combine Conditions in jOOQ

I have a list of conditions:

List<Condition> conditions = ...;

What is the easiest way to and-combine (or or-combine) these conditions into a new condition?

Condition condition = and(conditions);

Does JOOQ have a utility function for this? I agree it is easy to write, but I would rather not re-invent the wheel.

jOOQ 3.6+ solution.

You can simply write:

Condition condition = DSL.and(conditions);

Prior to jOOQ 3.6:

Before this was implemented in jOOQ 3.6 ( #3904 ) you had to resort to writing your own method:

static Condition and(Collection<? extends Condition> conditions) {
    Condition result = DSL.trueCondition();

    for (Condition condition : conditions)
        result = result.and(condition);

    return result;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM