本文整理汇总了Java中org.springframework.data.jpa.domain.Specification.toPredicate方法的典型用法代码示例。如果您正苦于以下问题:Java Specification.toPredicate方法的具体用法?Java Specification.toPredicate怎么用?Java Specification.toPredicate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.data.jpa.domain.Specification
的用法示例。
在下文中一共展示了Specification.toPredicate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: applySpecificationToQueryCriteria
import org.springframework.data.jpa.domain.Specification; //导入方法依赖的package包/类
/**
* Spec op query doen.
* @param spec spec
* @param query query
* @param <S> query type
* @return root
*/
protected final <S> Root<T> applySpecificationToQueryCriteria(final Specification<T> spec, final CriteriaQuery<S> query) {
Assert.notNull(query, "Query mag niet null zijn.");
final Root<T> root = query.from(getDomainClass());
if (spec == null) {
return root;
}
final CriteriaBuilder builder = em.getCriteriaBuilder();
final Predicate predicate = spec.toPredicate(root, query, builder);
if (predicate != null) {
query.where(predicate);
}
return root;
}
示例2: aggregate
import org.springframework.data.jpa.domain.Specification; //导入方法依赖的package包/类
private <S> S aggregate(CriteriaBuilder builder, CriteriaQuery<S> query, Root<E> root, Specification<E> spec, List<Selection<?>> selectionList, LockModeType lockMode) {
if (selectionList != null) {
Predicate predicate = spec.toPredicate(root, query, builder);
if (predicate != null) {
query.where(predicate);
}
query.multiselect(selectionList);
return (S) em.createQuery(query).setLockMode(lockMode).getSingleResult();
}
return null;
}
示例3: toPredicate
import org.springframework.data.jpa.domain.Specification; //导入方法依赖的package包/类
@Override
public Predicate toPredicate(Root<Object> root, CriteriaQuery<?> cq, CriteriaBuilder cb) {
List<Predicate> predicates = new ArrayList<>();
for(Specification specification: specifications){
Predicate p = specification.toPredicate(root, cq, cb);
if(p!=null)
predicates.add(p);
}
return cb.and(predicates.toArray(new Predicate[predicates.size()]));
}
示例4: applySpecificationToCriteria
import org.springframework.data.jpa.domain.Specification; //导入方法依赖的package包/类
/**
* Applies the given {@link Specification} to the given {@link CriteriaQuery}.
*/
private <S, T> Root<T> applySpecificationToCriteria(final Root<T> root, final Specification<T> spec, final CriteriaQuery<S> query) {
Assert.notNull(query, "Query is requested");
if (spec != null) {
// There is at least one described filter
final CriteriaBuilder builder = em.getCriteriaBuilder();
final Predicate predicate = spec.toPredicate(root, query, builder);
// There is at least one validated filter
query.where(predicate);
}
return root;
}