List of usage examples for javax.persistence.criteria CriteriaBuilder lower
Expression<String> lower(Expression<String> x);
From source file:net.awired.generic.jpa.dao.impl.GenericDaoImpl.java
private Predicate[] BuildFilterPredicates(Root<ENTITY> root, String search, List<String> searchProperties) { if (Strings.isNullOrEmpty(search)) { return new Predicate[] {}; }// w w w . ja v a 2s . co m CriteriaBuilder builder = entityManager.getCriteriaBuilder(); EntityType<ENTITY> type = entityManager.getMetamodel().entity(entityClass); String[] split = search.split(","); Set<SingularAttribute<? super ENTITY, ?>> attributes = type.getSingularAttributes(); List<Predicate> predicates = new ArrayList<Predicate>(split.length * attributes.size()); for (String searchElem : split) { String searchProperty = null; if (searchElem.contains(":")) { String[] propSearchs = searchElem.trim().split(":", 2); searchElem = propSearchs[1]; searchProperty = propSearchs[0]; } boolean numeric; try { Double.parseDouble(searchElem); numeric = true; } catch (Exception e) { numeric = false; } for (SingularAttribute<? super ENTITY, ?> attribute : attributes) { if (searchProperties != null && !searchProperties.isEmpty() && !searchProperties.contains(attribute.getName())) { continue; // skip this property as its not listed in searchable properties } if (searchProperty != null && !searchProperty.equals(attribute.getName())) { continue; // skip this property as we are searching for specific property } Class<?> javaType = attribute.getJavaType(); if (javaType == String.class) { @SuppressWarnings("unchecked") Predicate like = builder.like( builder.lower(root.get((SingularAttribute<ENTITY, String>) attribute)), "%" + searchElem.toLowerCase().trim() + "%"); predicates.add(like); } else if (numeric && (Number.class.isAssignableFrom(javaType) || javaType == int.class || javaType == short.class || javaType == long.class || javaType == float.class || javaType == double.class || javaType == byte.class)) { Predicate like = builder.equal(root.get(attribute), searchElem.toLowerCase().trim()); predicates.add(like); } //TODO fancy types // enums // char // boolean } } return predicates.toArray(new Predicate[] {}); }
From source file:com.sammyun.dao.impl.BaseDaoImpl.java
private void addRestrictions(CriteriaQuery<T> criteriaQuery, List<Filter> filters) { if (criteriaQuery == null || filters == null || filters.isEmpty()) { return;//w w w . jav a 2s . co m } Root<T> root = getRoot(criteriaQuery); if (root == null) { return; } CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); Predicate restrictions = criteriaQuery.getRestriction() != null ? criteriaQuery.getRestriction() : criteriaBuilder.conjunction(); for (Filter filter : filters) { if (filter == null || StringUtils.isEmpty(filter.getProperty())) { continue; } /** */ if (filter.getMold() == Mold.dl || filter.getMold() == Mold.dg) { if (filter.getOperator() == Operator.lt && filter.getValue() != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.lessThan(root.<Date>get(filter.getProperty()), DateUtil.parseDate(filter.getValue().toString()))); } else if (filter.getOperator() == Operator.gt && filter.getValue() != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.greaterThan(root.<Date>get(filter.getProperty()), DateUtil.parseDate(filter.getValue().toString()))); } else if (filter.getOperator() == Operator.le && filter.getValue() != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.lessThanOrEqualTo(root.<Date>get(filter.getProperty()), DateUtil.parseDate(filter.getValue().toString()))); } else if (filter.getOperator() == Operator.ge && filter.getValue() != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.greaterThanOrEqualTo(root.<Date>get(filter.getProperty()), DateUtil.parseDate(filter.getValue().toString()))); } } else { if (filter.getOperator() == Operator.eq && filter.getValue() != null) { if (filter.getIgnoreCase() != null && filter.getIgnoreCase() && filter.getValue() instanceof String) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(criteriaBuilder.lower(root.<String>get(filter.getProperty())), ((String) filter.getValue()).toLowerCase())); } else { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get(filter.getProperty()), filter.getValue())); } } else if (filter.getOperator() == Operator.ne && filter.getValue() != null) { if (filter.getIgnoreCase() != null && filter.getIgnoreCase() && filter.getValue() instanceof String) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.notEqual( criteriaBuilder.lower(root.<String>get(filter.getProperty())), ((String) filter.getValue()).toLowerCase())); } else { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.notEqual(root.get(filter.getProperty()), filter.getValue())); } } else if (filter.getOperator() == Operator.gt && filter.getValue() != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.gt(root.<Number>get(filter.getProperty()), (Number) filter.getValue())); } else if (filter.getOperator() == Operator.lt && filter.getValue() != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.lt(root.<Number>get(filter.getProperty()), (Number) filter.getValue())); } else if (filter.getOperator() == Operator.ge && filter.getValue() != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.ge(root.<Number>get(filter.getProperty()), (Number) filter.getValue())); } else if (filter.getOperator() == Operator.le && filter.getValue() != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.le(root.<Number>get(filter.getProperty()), (Number) filter.getValue())); } else if (filter.getOperator() == Operator.like && filter.getValue() != null && filter.getValue() instanceof String) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder .like(root.<String>get(filter.getProperty()), (String) filter.getValue())); } else if (filter.getOperator() == Operator.in && filter.getValue() != null) { restrictions = criteriaBuilder.and(restrictions, root.get(filter.getProperty()).in(filter.getValue())); } else if (filter.getOperator() == Operator.isNull) { restrictions = criteriaBuilder.and(restrictions, root.get(filter.getProperty()).isNull()); } else if (filter.getOperator() == Operator.isNotNull) { restrictions = criteriaBuilder.and(restrictions, root.get(filter.getProperty()).isNotNull()); } } } criteriaQuery.where(restrictions); }
From source file:com.sammyun.dao.impl.BaseDaoImpl.java
private void addRestrictions(CriteriaQuery<T> criteriaQuery, Pageable pageable) { if (criteriaQuery == null || pageable == null) { return;//from w w w . java 2 s .com } Root<T> root = getRoot(criteriaQuery); if (root == null) { return; } CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); Predicate restrictions = criteriaQuery.getRestriction() != null ? criteriaQuery.getRestriction() : criteriaBuilder.conjunction(); if (StringUtils.isNotEmpty(pageable.getSearchProperty()) && StringUtils.isNotEmpty(pageable.getSearchValue())) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder .like(root.<String>get(pageable.getSearchProperty()), "%" + pageable.getSearchValue() + "%")); } if (pageable.getFilters() != null) { for (Filter filter : pageable.getFilters()) { if (filter == null || StringUtils.isEmpty(filter.getProperty())) { continue; } /** */ if (filter.getMold() == Mold.dl || filter.getMold() == Mold.dg) { if (filter.getOperator() == Operator.lt && filter.getValue() != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.lessThan(root.<Date>get(filter.getProperty()), DateUtil.parseDate(filter.getValue().toString()))); } else if (filter.getOperator() == Operator.gt && filter.getValue() != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.greaterThan(root.<Date>get(filter.getProperty()), DateUtil.parseDate(filter.getValue().toString()))); } else if (filter.getOperator() == Operator.le && filter.getValue() != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.lessThanOrEqualTo(root.<Date>get(filter.getProperty()), DateUtil.parseDate(filter.getValue().toString()))); } else if (filter.getOperator() == Operator.ge && filter.getValue() != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.greaterThanOrEqualTo(root.<Date>get(filter.getProperty()), DateUtil.parseDate(filter.getValue().toString()))); } } else { if (filter.getOperator() == Operator.eq && filter.getValue() != null) { if (filter.getIgnoreCase() != null && filter.getIgnoreCase() && filter.getValue() instanceof String) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal( criteriaBuilder.lower(root.<String>get(filter.getProperty())), ((String) filter.getValue()).toLowerCase())); } else { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get(filter.getProperty()), filter.getValue())); } } else if (filter.getOperator() == Operator.ne && filter.getValue() != null) { if (filter.getIgnoreCase() != null && filter.getIgnoreCase() && filter.getValue() instanceof String) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.notEqual( criteriaBuilder.lower(root.<String>get(filter.getProperty())), ((String) filter.getValue()).toLowerCase())); } else { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.notEqual(root.get(filter.getProperty()), filter.getValue())); } } else if (filter.getOperator() == Operator.gt && filter.getValue() != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder .gt(root.<Number>get(filter.getProperty()), (Number) filter.getValue())); } else if (filter.getOperator() == Operator.lt && filter.getValue() != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder .lt(root.<Number>get(filter.getProperty()), (Number) filter.getValue())); } else if (filter.getOperator() == Operator.ge && filter.getValue() != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder .ge(root.<Number>get(filter.getProperty()), (Number) filter.getValue())); } else if (filter.getOperator() == Operator.le && filter.getValue() != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder .le(root.<Number>get(filter.getProperty()), (Number) filter.getValue())); } else if (filter.getOperator() == Operator.like && filter.getValue() != null && filter.getValue() instanceof String) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder .like(root.<String>get(filter.getProperty()), (String) filter.getValue())); } else if (filter.getOperator() == Operator.in && filter.getValue() != null) { restrictions = criteriaBuilder.and(restrictions, root.get(filter.getProperty()).in(filter.getValue())); } else if (filter.getOperator() == Operator.isNull) { restrictions = criteriaBuilder.and(restrictions, root.get(filter.getProperty()).isNull()); } else if (filter.getOperator() == Operator.isNotNull) { restrictions = criteriaBuilder.and(restrictions, root.get(filter.getProperty()).isNotNull()); } } } } criteriaQuery.where(restrictions); }
From source file:org.apache.rave.portal.repository.impl.JpaWidgetRepository.java
private Predicate[] getStatusAndTypeAndFreeTextPredicates(CriteriaBuilder cb, Root<JpaWidget> widgetType, WidgetStatus widgetStatus, String type, String searchTerm) { List<Predicate> predicates = new ArrayList<Predicate>(); if (StringUtils.isNotBlank(searchTerm)) { predicates.add(/* ww w.j ava 2 s . com*/ cb.or(cb.like(cb.lower(getTitleField(widgetType)), getLowercaseWildcardSearchTerm(searchTerm)), cb.like(cb.lower(getDescriptionField(widgetType)), getLowercaseWildcardSearchTerm(searchTerm)))); } if (StringUtils.isNotBlank(type)) { predicates.add(cb.and(cb.equal(getTypeField(widgetType), type))); } if (widgetStatus != null) { predicates.add(cb.and(cb.equal(getWidgetStatusField(widgetType), widgetStatus))); } return predicates.toArray(new Predicate[predicates.size()]); }
From source file:org.apereo.portal.persondir.dao.jpa.JpaLocalAccountDaoImpl.java
@Override public List<ILocalAccountPerson> getPeople(LocalAccountQuery query) { final EntityManager entityManager = this.getEntityManager(); final CriteriaBuilder cb = entityManager.getCriteriaBuilder(); final CriteriaQuery<LocalAccountPersonImpl> criteriaQuery = cb.createQuery(LocalAccountPersonImpl.class); final Root<LocalAccountPersonImpl> accountRoot = criteriaQuery.from(LocalAccountPersonImpl.class); final CollectionJoin<LocalAccountPersonImpl, LocalAccountPersonAttributeImpl> attributes = accountRoot .join(LocalAccountPersonImpl_.attributes); final ListJoin<LocalAccountPersonAttributeImpl, String> attributeValues = attributes .join(LocalAccountPersonAttributeImpl_.values); //Due to the joins multiple rows are returned for each result criteriaQuery.distinct(true);//from ww w .j a va 2 s.c om criteriaQuery.select(accountRoot); final List<Predicate> whereParts = new LinkedList<Predicate>(); final Map<Parameter<String>, String> params = new LinkedHashMap<Parameter<String>, String>(); // if a username has been specified, append it to the query if (query.getName() != null) { whereParts.add(cb.equal(accountRoot.get(LocalAccountPersonImpl_.name), this.nameParameter)); params.put(this.nameParameter, query.getName()); } //Build Predicate for each attribute being queried int paramCount = 0; for (Map.Entry<String, List<String>> entry : query.getAttributes().entrySet()) { final List<String> values = entry.getValue(); if (values == null) { continue; } //For each value create a Predicate checking the attribute name and value together for (final String value : values) { if (StringUtils.isBlank(value)) { continue; } //Create Parameter objects for the name and value, stick them in the params map for later use final ParameterExpression<String> nameParam = this.createParameterExpression(String.class, "attrName" + paramCount); final ParameterExpression<String> valueParam = this.createParameterExpression(String.class, "attrValue" + paramCount); params.put(nameParam, entry.getKey()); params.put(valueParam, "%" + value.toLowerCase() + "%"); //Build the and(eq, like) predicate and add it to the list of predicates for the where clause whereParts.add(cb.and(cb.equal(attributes.get(LocalAccountPersonAttributeImpl_.name), nameParam), cb.like(cb.lower(attributeValues.as(String.class)), valueParam))); paramCount++; } } //Add the Predicates to the where clause criteriaQuery.where(cb.or(whereParts.toArray(new Predicate[whereParts.size()]))); //Create the query final TypedQuery<LocalAccountPersonImpl> jpaQuery = this.createCachedQuery(criteriaQuery); //Add all of the stored up parameters to the query for (Map.Entry<Parameter<String>, String> entry : params.entrySet()) { final Parameter<String> parameter = entry.getKey(); final String value = entry.getValue(); jpaQuery.setParameter(parameter, value); } final List<LocalAccountPersonImpl> accounts = jpaQuery.getResultList(); return new ArrayList<ILocalAccountPerson>(accounts); }
From source file:org.broadleafcommerce.admin.server.service.handler.SkuRestrictionFactoryImpl.java
@Override public Restriction getRestriction(final String type, String propertyId) { final Restriction delegateRestriction = delegate.getRestriction(type, propertyId); return new Restriction().withFilterValueConverter(delegateRestriction.getFilterValueConverter()) .withPredicateProvider(new PredicateProvider() { @Override/*w w w .ja v a 2 s.com*/ public Predicate buildPredicate(CriteriaBuilder builder, FieldPathBuilder fieldPathBuilder, From root, String ceilingEntity, String fullPropertyName, Path explicitPath, List directValues) { FieldPath fieldPath = fieldPathBuilder.getFieldPath(root, fullPropertyName); if ((StringUtils.isNotEmpty(skuPropertyPrefix) && fullPropertyName.startsWith(skuPropertyPrefix)) || CollectionUtils.isEmpty(fieldPath.getAssociationPath())) { Path targetPropertyPath = fieldPathBuilder.getPath(root, fieldPath, builder); Path defaultSkuPropertyPath = fieldPathBuilder.getPath(root, DEFAULT_SKU_PATH_PREFIX + fullPropertyName, builder); Path productPath = fieldPathBuilder.getPath(root, "product", builder); Predicate propertyExpression; Predicate defaultSkuExpression; if (delegateRestriction.getPredicateProvider() instanceof LikePredicateProvider) { propertyExpression = builder.like(builder.lower(targetPropertyPath), ((String) directValues.get(0)).toLowerCase()); defaultSkuExpression = builder.like(builder.lower(defaultSkuPropertyPath), ((String) directValues.get(0)).toLowerCase()); } else if (delegateRestriction .getPredicateProvider() instanceof IsNullPredicateProvider) { propertyExpression = builder.isNull(targetPropertyPath); defaultSkuExpression = builder.isNull(defaultSkuPropertyPath); } else if (delegateRestriction .getPredicateProvider() instanceof BetweenDatePredicateProvider) { if (directValues.size() == 2) { if (directValues.get(0) == null) { propertyExpression = builder.lessThan(targetPropertyPath, (Comparable) directValues.get(1)); defaultSkuExpression = builder.lessThan(defaultSkuPropertyPath, (Comparable) directValues.get(1)); } else if (directValues.get(1) == null) { propertyExpression = builder.greaterThanOrEqualTo(targetPropertyPath, (Comparable) directValues.get(0)); defaultSkuExpression = builder.greaterThanOrEqualTo(defaultSkuPropertyPath, (Comparable) directValues.get(0)); } else { propertyExpression = builder.between(targetPropertyPath, (Comparable) directValues.get(0), (Comparable) directValues.get(1)); defaultSkuExpression = builder.between(defaultSkuPropertyPath, (Comparable) directValues.get(0), (Comparable) directValues.get(1)); } } else { propertyExpression = builder.equal(targetPropertyPath, directValues.get(0)); defaultSkuExpression = builder.equal(defaultSkuPropertyPath, directValues.get(0)); } } else if (delegateRestriction .getPredicateProvider() instanceof BetweenPredicateProvider) { if (directValues.size() > 1) { propertyExpression = builder.between(targetPropertyPath, (Comparable) directValues.get(0), (Comparable) directValues.get(1)); defaultSkuExpression = builder.between(defaultSkuPropertyPath, (Comparable) directValues.get(0), (Comparable) directValues.get(1)); } else { propertyExpression = builder.equal(targetPropertyPath, directValues.get(0)); defaultSkuExpression = builder.equal(defaultSkuPropertyPath, directValues.get(0)); } } else if (delegateRestriction .getPredicateProvider() instanceof CollectionSizeEqualPredicateProvider) { propertyExpression = builder.equal(builder.size(targetPropertyPath), directValues.get(0)); defaultSkuExpression = builder.equal(builder.size(defaultSkuPropertyPath), directValues.get(0)); } else if (delegateRestriction.getPredicateProvider() instanceof EqPredicateProvider) { propertyExpression = builder.equal(targetPropertyPath, directValues.get(0)); defaultSkuExpression = builder.equal(defaultSkuPropertyPath, directValues.get(0)); } else { throw new IllegalArgumentException("Unknown PredicateProvider instance: " + delegateRestriction.getPredicateProvider().getClass().getName()); } return buildCompositePredicate(builder, targetPropertyPath, productPath, propertyExpression, defaultSkuExpression); } return delegateRestriction.getPredicateProvider().buildPredicate(builder, fieldPathBuilder, root, ceilingEntity, fullPropertyName, explicitPath, directValues); } }); }
From source file:org.broadleafcommerce.core.catalog.dao.ProductDaoImpl.java
protected List<Product> readFilteredActiveProductsByQueryInternal(String query, Date currentDate, SearchCriteria searchCriteria) { // Set up the criteria query that specifies we want to return Products CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery<Product> criteria = builder.createQuery(Product.class); // The root of our search is Product since we are searching Root<ProductImpl> product = criteria.from(ProductImpl.class); // We also want to filter on attributes from sku and productAttributes Join<Product, Sku> sku = product.join("defaultSku"); // Product objects are what we want back criteria.select(product);// w w w . ja va 2s. c o m // We only want results that match the search query List<Predicate> restrictions = new ArrayList<Predicate>(); String lq = query.toLowerCase(); restrictions.add(builder.or(builder.like(builder.lower(sku.get("name").as(String.class)), '%' + lq + '%'), builder.like(builder.lower(sku.get("longDescription").as(String.class)), '%' + lq + '%'))); attachSearchCriteria(searchCriteria, product, sku, restrictions); attachActiveRestriction(currentDate, product, sku, restrictions); attachOrderBy(searchCriteria, product, sku, criteria); // Execute the query with the restrictions criteria.where(restrictions.toArray(new Predicate[restrictions.size()])); TypedQuery<Product> typedQuery = em.createQuery(criteria); //don't cache - not really practical for open ended search return typedQuery.getResultList(); }
From source file:org.jboss.pnc.datastore.predicates.rsql.RSQLNodeTravellerPredicate.java
public RSQLNodeTravellerPredicate(Class<Entity> entityClass, String rsql) throws RSQLParserException { operations.put(RSQLOperators.EQUAL, new AbstractTransformer<Entity>() { @Override/* www .j av a2 s.c om*/ Predicate transform(Root<Entity> r, Path<?> selectedPath, CriteriaBuilder cb, String operand, List<Object> convertedArguments) { return cb.equal(selectedPath, convertedArguments.get(0)); } }); operations.put(RSQLOperators.NOT_EQUAL, new AbstractTransformer<Entity>() { @Override Predicate transform(Root<Entity> r, Path<?> selectedPath, CriteriaBuilder cb, String operand, List<Object> convertedArguments) { return cb.notEqual(selectedPath, convertedArguments.get(0)); } }); operations.put(RSQLOperators.GREATER_THAN, (r, cb, clazz, operand, arguments) -> cb .greaterThan((Path) selectWithOperand(r, operand, clazz), arguments.get(0))); operations.put(RSQLOperators.GREATER_THAN_OR_EQUAL, (r, cb, clazz, operand, arguments) -> cb .greaterThanOrEqualTo((Path) selectWithOperand(r, operand, clazz), arguments.get(0))); operations.put(RSQLOperators.LESS_THAN, (r, cb, clazz, operand, arguments) -> cb .lessThan((Path) selectWithOperand(r, operand, clazz), arguments.get(0))); operations.put(RSQLOperators.LESS_THAN_OR_EQUAL, (r, cb, clazz, operand, arguments) -> cb .lessThanOrEqualTo((Path) selectWithOperand(r, operand, clazz), arguments.get(0))); operations.put(RSQLOperators.IN, (r, cb, clazz, operand, arguments) -> ((Path) selectWithOperand(r, operand, clazz)).in(arguments)); operations.put(RSQLOperators.NOT_IN, (r, cb, clazz, operand, arguments) -> cb .not(((Path) selectWithOperand(r, operand, clazz)).in(arguments))); operations.put(LIKE, (r, cb, clazz, operand, arguments) -> cb.like(cb.lower((Path) selectWithOperand(r, operand, clazz)), preprocessLikeOperatorArgument(arguments.get(0).toLowerCase()))); operations.put(IS_NULL, (r, cb, clazz, operand, arguments) -> { if (Boolean.parseBoolean(arguments.get(0))) { return cb.isNull((Path) selectWithOperand(r, operand, clazz)); } else { return cb.isNotNull((Path) selectWithOperand(r, operand, clazz)); } }); Set<ComparisonOperator> operators = RSQLOperators.defaultOperators(); operators.add(LIKE); operators.add(IS_NULL); rootNode = new RSQLParser(operators).parse(preprocessRSQL(rsql)); selectingClass = entityClass; }
From source file:org.kisoonlineapp.uc.teilnehmer.SearchPredicatesForTeilnehmerFilterForm.java
List<Predicate> createSearchPredicates(TeilnehmerFilterForm teilnehmerFilterForm, Root<Teilnehmer> root) { final Teilnehmer example = teilnehmerFilterForm.getExample(); final CriteriaBuilder builder = this.entityManager.getCriteriaBuilder(); final List<Predicate> predicatesList = new ArrayList<>(); {/*from www . j av a 2 s .com*/ final String vorname = example.getVorname(); if (isNotEmpty(vorname)) { predicatesList .add(builder.like(builder.lower(root.<String>get("vorname")), lowerWildcards(vorname))); } } { final String nachname = example.getNachname(); if (isNotEmpty(nachname)) { predicatesList .add(builder.like(builder.lower(root.<String>get("nachname")), lowerWildcards(nachname))); } } { final String email = example.getEmail(); if (isNotEmpty(email)) { predicatesList.add(builder.like(builder.lower(root.<String>get("email")), lowerWildcards(email))); } } { final String telefon = example.getTelefon(); if (isNotEmpty(telefon)) { predicatesList .add(builder.like(builder.lower(root.<String>get("telefon")), lowerWildcards(telefon))); } } return Collections.unmodifiableList(predicatesList); }
From source file:org.kisoonlineapp.uc.veranstalter.SearchPredicatesForVeranstalterFilterForm.java
List<Predicate> createSearchPredicates(VeranstalterFilterForm veranstalterFilterForm, Root<Veranstalter> root) { Veranstalter example = veranstalterFilterForm.getExample(); CriteriaBuilder builder = this.entityManager.getCriteriaBuilder(); List<Predicate> predicatesList = new ArrayList<Predicate>(); {/*from w w w. j a v a2s . c o m*/ final String code = example.getCode(); if (isNotEmpty(code)) { predicatesList.add(builder.like(builder.lower(root.<String>get("code")), lowerWildcards(code))); } } { final String vorname = example.getVorname(); if (isNotEmpty(vorname)) { predicatesList .add(builder.like(builder.lower(root.<String>get("vorname")), lowerWildcards(vorname))); } } { final String nachname = example.getNachname(); if (isNotEmpty(nachname)) { predicatesList .add(builder.like(builder.lower(root.<String>get("nachname")), lowerWildcards(nachname))); } } { final String organisation = example.getOrganisation(); if (isNotEmpty(organisation)) { predicatesList.add(builder.like(builder.lower(root.<String>get("organisation")), lowerWildcards(organisation))); } } { final String beschreibung = example.getBeschreibung(); if (isNotEmpty(beschreibung)) { predicatesList.add(builder.like(builder.lower(root.<String>get("beschreibung")), lowerWildcards(beschreibung))); } } return Collections.unmodifiableList(predicatesList); }