如何创建 Predicates 的(人类可读)字符串表示,它向我显示逻辑操作数AND / OR / NOT以及属性和参数占位符参与?
不需要进行SQL或平台特定的转换。
问候
答案 0 :(得分: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