简体   繁体   English

JPA 实体表达式求值器

[英]JPA entity expression evaluator

Is there any possibility to evaluate if the JPA entity fulfils JPQL/RSQL expression using any libs or Hibernate without an active Entity Manager?是否有可能评估 JPA 实体是否使用任何库或 Hibernate 在没有活动实体管理器的情况下满足 JPQL/RSQL 表达式?

For example:例如:

SampleEntity entity = ...;
boolean evaluationResult = new Criteria("id=gt=1").test(entity);

You may just use this library: https://github.com/turkraft/spring-filter你可以只使用这个库: https://github.com/turkraft/spring-filter

It will let you run search queries such as:它可以让您运行搜索查询,例如:

/search?filter= average (ratings) > 4.5 and brand.name in ('audi', 'land rover') and (year > 2018 or km < 50000) and color : 'white' and accidents is empty /search?filter= average (ratings) > 4.5 and brand.name in ('audi', 'land Rover') and (year > 2018 or km < 50000) and color : 'white' and事故为空

You can also run search queries even if you don't have an API, the library basically compiles a search input to JPA predicates.即使您没有 API,您也可以运行搜索查询,该库基本上将搜索输入编译为 JPA 谓词。

Blaze-Expression is a library that implements a syntax similar to JPQL and supports expression evaluation/interpretation, as well as serialization to a Blaze-Persistence query builder. Blaze-Expression是一个实现类似于 JPQL 的语法并支持表达式评估/解释以及序列化到 Blaze-Persistence 查询构建器的库。

See here for an example: https://github.com/Blazebit/blaze-expression/blob/master/declarative/persistence/src/test/java/com/blazebit/expression/declarative/persistence/ModelTest.java有关示例,请参见此处: https://github.com/Blazebit/blaze-expression/blob/master/declarative/persistence/src/test/java/com/blazebit/expression/declarative/persistence/ModelTest.java

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM