使用列作为 QueryDSL 的正则表达式模式

Use column as regex pattern with QueryDSL

我正在尝试使用列作为正则表达式来匹配用户提供的字符串,但不知道如何使用 QueryDSL 来实现。大多数情况下,我不知道如何将用户提供的字符串放在表达式的左侧。

基本上我想做类似于以下的事情,其中​​ ~ 是我用于正则表达式匹配的数据库符号…

SELECT * FROM thing WHERE 'user supplied string' ~ thing.match

我不知道这是最好的方法,但我能够开始工作的唯一解决方案是子类化 StringExpression

class ConstantExpression extends StringExpression {
  private Constant<String> constant;

  static public ConstantExpression create(String constant) {
     return new ConstantExpression(new ConstantImpl<String>(constant);
  }

  public ConstantExpression(Constant<String> mixin) {
     super(mixin);
     constant = mixin;
  }

  public <R,C> R accept(Visitor<R,C> v, C context) {
     return v.visit(constnat, context);
  }
}

然后我就可以用它作为等式的左边……

createJPAQueryFactory().from(qthing)
    .where(ConstantExpression.create("user supplied…").like(thing.match)

以下作品

Expressions.predicate(Ops.MATCHES, Expressions.constant(...), path)