jOOQ select with map type values

Viewed 108

There is a table that has map type column, and the map column type would be like below

Map<String, CustomClass.class>

and CustomClass is like below

Class CustomClass {
   String name;
   String attr;
}

I would like to select record that match 'keyword' contain in map column's values (no matter what key is). I need something like below. Is there any way that I can use?

JooqQuery jooqQuery = (SelectJoinStep<?> step) -> {
  
    step.where(MANAGERS.NAME_DESC_I18N_MAP.contains(
          Map<"ANY KEY", keyword in CustomClass.name> // need help here
      ));
1 Answers

You can use LIKE as a quantified comparison predicate in jOOQ. If it's not supported natively by your RDBMS, jOOQ will emulate it for you. Try this:

MANAGERS.NAME_DESC_I18N_MAP.like(any(
    map.values().stream().map(cc -> "%" + cc.name + "%").toArray(String[]::new)
))

You can't use contains() in this way yet, but I guess that's OK.

See also this blog post about using LIKE as a quantified comparison predicate.

Related