2

如何创建Predicates的(人类可读的)字符串表示,它向我显示逻辑操作数 AND/OR/NOT 以及所涉及的属性和参数占位符?

不需要 SQL 或特定于平台的转换。

问候

4

1 回答 1

1

这对我来说适用于 EclipseLink 2.3/2.4:

import org.eclipse.persistence.internal.jpa.querydef.SelectionImpl;

public static String getPredicateAsString(final Predicate predicate) {
    if (predicate == null) {
        return null;
    }
    if (!(predicate instanceof SelectionImpl<?>)) { // type guard
        return "not supported";
    }

    return ((SelectionImpl<?>) predicate).getCurrentNode().toString();
}

getPredicateAsString的示例输出:

Logical operator [ AND ]
    Relation operator [ <> ]
       Query Key age
          Base model.Person
       Constant 42
    Function operator [(,  IS NOT NULL)]
       Query Key currentJob
          Base model.Employer
于 2013-09-11T12:24:07.867 回答