0

I have some params to generate different sql condition,

Condition con = DSL.trueCondition();
if (StringUtils.isNotEmpty(book.getName)) {
  con = con.and(BOOK.NAME.eq(book.getName))
}
if (book.getId > 0) {
  con = con.and(BOOK.ID.eq(book.getId))
}
if ...

I want to know if there is common function, so I can dynamic generate condition. for example:

public Condition generateCondition(Field<?> field, Object obj, Class<?> type) {
  if () { 
    return DSL.trueCondition();
  }
  return field.eq(obj, type);
}

I have see this question Is there a way to query by example in Jooq?, it's useful for search single table, but when I need search from multiple table, I don't know how to do...

einherjar
  • 45
  • 1
  • 6
  • Well, you already wrote the "common function". What's still missing? – Lukas Eder May 31 '21 at 20:01
  • actually, I don't konw how to write the function, I just show the pseudocode – einherjar Jun 01 '21 at 01:30
  • Well, what *exactly* does your function have to do? Auto-join? Auto-semi-join? Auto-project? Auto-filter? Auto-group-by? And which part of these possible specifications did you struggle with? – Lukas Eder Jun 01 '21 at 05:58

0 Answers0