예제 #1
2
  @Override
  public Predicate toPredicate(Root<Role> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
    Predicate predicate = cb.conjunction();
    List<Expression<Boolean>> expressions = predicate.getExpressions();

    if (isNotBlank(criteria.getFilter())) {
      expressions.add(
          cb.or(
              cb.like(
                  cb.lower(root.<String>get(Role_.roleName)),
                  wildcardsAndLower(criteria.getFilter())),
              cb.like(
                  cb.lower(root.<String>get(Role_.roleDesc)),
                  wildcardsAndLower(criteria.getFilter()))));
    }

    if (isNotBlank(criteria.getRoleName())) {
      expressions.add(
          cb.like(
              cb.lower(root.<String>get(Role_.roleName)),
              wildcardsAndLower(criteria.getRoleName())));
    }
    if (isNotBlank(criteria.getRoleDesc())) {
      expressions.add(
          cb.like(
              cb.lower(root.<String>get(Role_.roleDesc)),
              wildcardsAndLower(criteria.getRoleDesc())));
    }
    if (null != criteria.getIsSys()) {
      expressions.add(cb.equal(root.<Boolean>get(Role_.isSys), criteria.getIsSys()));
    }
    return predicate;
  }
  /*
   * (non-Javadoc)
   * @see com.github.dactiv.orm.core.spring.data.jpa.restriction.PredicateSingleValueSupport#build(com.github.dactiv.orm.core.PropertyFilter, com.github.dactiv.orm.core.spring.data.jpa.JpaBuilderModel)
   */
  public Predicate build(PropertyFilter filter, SpecificationEntity entity) {
    Object value = convertMatchValue(filter.getMatchValue(), filter.getFieldType());
    Predicate predicate = null;

    if (filter.hasMultiplePropertyNames()) {
      Predicate orDisjunction = entity.getBuilder().disjunction();
      for (String propertyName : filter.getPropertyNames()) {
        orDisjunction.getExpressions().add(build(propertyName, value, entity));
      }
      predicate = orDisjunction;
    } else {
      predicate = build(filter.getSinglePropertyName(), value, entity);
    }

    return predicate;
  }
예제 #3
0
 @Override
 public Predicate isFalse(Expression<Boolean> expression) {
   if (CompoundPredicate.class.isInstance(expression)) {
     final CompoundPredicate predicate = (CompoundPredicate) expression;
     if (predicate.getExpressions().size() == 0) {
       return new BooleanStaticAssertionPredicate(
           this, predicate.getOperator() == Predicate.BooleanOperator.OR);
     }
     predicate.not();
     return predicate;
   } else if (Predicate.class.isInstance(expression)) {
     final Predicate predicate = (Predicate) expression;
     predicate.not();
     return predicate;
   }
   return new BooleanAssertionPredicate(this, expression, Boolean.FALSE);
 }
  private Predicate buildCriteria(
      CriteriaBuilder criteriaBuilder, Root<Product> enityRoot, Map<String, Object> params) {
    String categoryName = (String) params.get("category_name");

    Predicate criteria = criteriaBuilder.conjunction();

    if (categoryName != null && !categoryName.isEmpty()) {
      criteria
          .getExpressions()
          .add(
              criteriaBuilder.like(
                  criteriaBuilder.lower(
                      enityRoot.join("category", JoinType.LEFT).<String>get("name")),
                  "%" + categoryName.toLowerCase() + "%"));
    }
    return criteria;
  }
예제 #5
0
 /**
  * Create negation of compound predicate by using logic rules: 1. not (x || y) is (not x && not y)
  * 2. not (x && y) is (not x || not y)
  */
 @Override
 public Predicate not() {
   toggleOperator();
   for (Expression expr : this.getExpressions()) {
     if (Predicate.class.isInstance(expr)) {
       ((Predicate) expr).not();
     }
   }
   return this;
 }