本文整理匯總了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;
}