Java Code Examples for javax.persistence.criteria.CriteriaBuilder.or()

The following are Jave code examples for showing how to use or() of the javax.persistence.criteria.CriteriaBuilder class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: datatable-java   File: DatatableSpecification.java   Source Code and License Vote up 6 votes
private Predicate getPredicateGlobalSearch(final Root<T> root, final CriteriaQuery<?> query, final CriteriaBuilder cb,
    Predicate predicate) {
    // check whether a global filter value exists
    final String globalFilterValue = input.getSearch().getValue();
    if (globalFilterValue != null && globalFilterValue.trim().length() > 0) {
        LOGGER.fine("filtre global: {"+ globalFilterValue+"}");

        Predicate matchOneColumnPredicate = cb.disjunction();
        // add a 'WHERE .. LIKE' clause on each searchable column
        for (final DatatableColumn column : input.getColumns()) {
            if (column.getSearchable()) {
                LOGGER.log(Level.FINE, "filtre global pour colonne: {}", column);
                final Expression<String> expression = DatatableHelper.getExpression(root, column.getData(), String.class);

                matchOneColumnPredicate = cb.or(matchOneColumnPredicate,
                    cb.like(cb.lower(expression), getLikeFilterValue(globalFilterValue), ESCAPE_CHAR));
            }
        }
        predicate = cb.and(predicate, matchOneColumnPredicate);
    }
    return predicate;
}
 
Example 2
Project: plumdo-stock   File: LogicalExpression.java   Source Code and License Vote up 5 votes
public Predicate toPredicate(Root<?> root, CriteriaQuery<?> query,  
        CriteriaBuilder builder) {  
    List<Predicate> predicates = new ArrayList<Predicate>();  
    for(int i=0;i<this.criterion.length;i++){  
        predicates.add(this.criterion[i].toPredicate(root, query, builder));  
    }  
    switch (operator) {  
    case OR:  
        return builder.or(predicates.toArray(new Predicate[predicates.size()]));  
    default:  
        return null;  
    }  
}
 
Example 3
Project: CriteriaBuilder   File: CriteriaServiceImpl.java   Source Code and License Vote up 5 votes
protected Predicate buildPredicateWithOperator(Path<T> tt, Conjunctions conjunctions, List<Predicate> predicateList) {
	CriteriaBuilder criteriaBuilder = this.entitymanager.getCriteriaBuilder();
	Predicate predicate = null;
	if(conjunctions.equals(Conjunctions.AND)) {
		predicate = criteriaBuilder.and(predicateList.toArray(new Predicate[predicateList.size()]));
	} else if(conjunctions.equals(Conjunctions.OR)) {
		predicate = criteriaBuilder.or(predicateList.toArray(new Predicate[predicateList.size()]));
	}
	return predicate;
}
 
Example 4
Project: OperatieBRP   File: OrPredicateBuilder.java   Source Code and License Vote up 5 votes
@Override
public Predicate toPredicate(final Root<?> root, final CriteriaQuery<?> query, final CriteriaBuilder cb) {
    final List<Predicate> predicates = new ArrayList<>();

    for (final PredicateBuilder predicateBuilder : predicateBuilders) {
        final Predicate predicate = predicateBuilder.toPredicate(root, query, cb);
        if (predicate != null) {
            predicates.add(predicate);
        }
    }

    return cb.or(predicates.toArray(new Predicate[] {}));
}
 
Example 5
Project: OperatieBRP   File: PersoonFilterFactory.java   Source Code and License Vote up 5 votes
@Override
public Predicate toPredicate(final Root<?> persoonRoot, final CriteriaQuery<?> query, final CriteriaBuilder cb) {
    final Root<PersoonAdres> persoonAdressenRoot = query.from(PersoonAdres.class);
    final Predicate joinPredicateAdressen = persoonRoot.get(ID).in(persoonAdressenRoot.get(PERSOON).get(ID));

    final Expression<String> attributeExpression1 =
            cb.lower(cb.function(UNACCENT, String.class, persoonAdressenRoot.get("buitenlandsAdresRegel1")));
    final Expression<String> attributeExpression2 =
            cb.lower(cb.function(UNACCENT, String.class, persoonAdressenRoot.get("buitenlandsAdresRegel2")));
    final Expression<String> attributeExpression3 =
            cb.lower(cb.function(UNACCENT, String.class, persoonAdressenRoot.get("buitenlandsAdresRegel3")));
    final Expression<String> attributeExpression4 =
            cb.lower(cb.function(UNACCENT, String.class, persoonAdressenRoot.get("buitenlandsAdresRegel4")));
    final Expression<String> attributeExpression5 =
            cb.lower(cb.function(UNACCENT, String.class, persoonAdressenRoot.get("buitenlandsAdresRegel5")));
    final Expression<String> attributeExpression6 =
            cb.lower(cb.function(UNACCENT, String.class, persoonAdressenRoot.get("buitenlandsAdresRegel6")));
    final Expression<String> valueExpression =
            cb.lower(
                    cb.function(
                            UNACCENT,
                            String.class,
                            cb.concat(cb.concat(cb.literal(WILDCARD), cb.literal(value.toString())), cb.literal(WILDCARD))));
    final Predicate adresPredicate1 = cb.like(attributeExpression1, valueExpression);
    final Predicate adresPredicate2 = cb.like(attributeExpression2, valueExpression);
    final Predicate adresPredicate3 = cb.like(attributeExpression3, valueExpression);
    final Predicate adresPredicate4 = cb.like(attributeExpression4, valueExpression);
    final Predicate adresPredicate5 = cb.like(attributeExpression5, valueExpression);
    final Predicate adresPredicate6 = cb.like(attributeExpression6, valueExpression);

    final Predicate buitenlandsAdres = cb.or(adresPredicate1, adresPredicate2, adresPredicate3, adresPredicate4, adresPredicate5, adresPredicate6);
    return cb.and(joinPredicateAdressen, buitenlandsAdres);
}
 
Example 6
Project: plumdo-work   File: LogicalExpression.java   Source Code and License Vote up 5 votes
public Predicate toPredicate(Root<?> root, CriteriaQuery<?> query,  
        CriteriaBuilder builder) {  
    List<Predicate> predicates = new ArrayList<Predicate>();  
    for(int i=0;i<this.criterion.length;i++){  
        predicates.add(this.criterion[i].toPredicate(root, query, builder));  
    }  
    switch (operator) {  
    case OR:  
        return builder.or(predicates.toArray(new Predicate[predicates.size()]));  
    default:  
        return null;  
    }  
}
 
Example 7
Project: bootstrap   File: DynamicSpecification.java   Source Code and License Vote up 5 votes
/**
 * Create a predicate group.
 */
private Predicate getGroupPredicate(final UiFilter group, final Root<U> root, final CriteriaQuery<?> query, final CriteriaBuilder cb) {
	// Build the predicates
	final java.util.List<Predicate> predicates = getPredicates(group, root, query, cb);

	// Build the specification
	if (predicates.isEmpty()) {
		return cb.conjunction();
	}
	final Predicate[] filteredPredicates = predicates.toArray(new Predicate[predicates.size()]);
	if (group.getGroupOp() == FilterOperator.AND) {
		return cb.and(filteredPredicates);
	}
	return cb.or(filteredPredicates);
}
 
Example 8
Project: datatable-java   File: DatatableOrSpecification.java   Source Code and License Vote up 5 votes
/**
 * {@inheritDoc}
 */
@Override
public Predicate toPredicate(final Root<T> root, final CriteriaQuery<?> query, final CriteriaBuilder cb) {

	LOGGER.log(Level.FINE, "Creating OR search predicate: '{}':'{}'", new Object[]{search, colonnes});

    // liste de predicats pour aprés faire le "or"
    final List<Predicate> predicates = new ArrayList<Predicate>();

    // valeur a chercher
    final String valeurRecherche = search.getValue().trim().toLowerCase();

    for (final DatatableColumn colonne : colonnes) {
        final Path<?> expression = DatatableHelper.getExpression(root, colonne.getData(), null);
        if (expression.getJavaType() == String.class) {
            String valuerFinale = valeurRecherche;
            if (colonne.isSearchWithoutSpaces()) {
                // le siret par exemple no contient pas des espaces
                valuerFinale = valeurRecherche.replace(" ", "");
            }
            predicates.add(cb.like(cb.lower(expression.as(String.class)),
                DatatableSpecification.getLikeFilterValue(valuerFinale),
                DatatableSpecification.ESCAPE_CHAR));
        } else if (expression.getJavaType() == Integer.class) {
            predicates.add(cb.like(expression.as(String.class),
                DatatableSpecification.getLikeFilterValue(valeurRecherche),
                DatatableSpecification.ESCAPE_CHAR));
        } else {
            throw new IllegalArgumentException("La colonne n'a pas le type supporté [String.class|Integer.class] ("
                + expression.getJavaType() + ")");
        }
    }

    return cb.or(predicates.toArray(new Predicate[predicates.size()]));
}
 
Example 9
Project: sctalk   File: LogicalExpression.java   Source Code and License Vote up 5 votes
@Override
public Predicate toPredicate(Root<?> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
    List<Predicate> predicates = new ArrayList<Predicate>();
    for (int i = 0; i < this.criterion.length; i++) {
        predicates.add(this.criterion[i].toPredicate(root, query, builder));
    }
    switch (operator) {
    case OR:
        return builder.or(predicates.toArray(new Predicate[predicates.size()]));
    default:
        return null;
    }
}
 
Example 10
Project: sucok-framework   File: IsNullOr.java   Source Code and License Vote up 4 votes
@Override
public Predicate buildJpaPredicate(CriteriaBuilder cb, Root<?> root) {
	Expression<?> path = QueryFormHelper.getPath(root, field);
	AbstractExpression expr = (AbstractExpression) value;
	return cb.or(cb.isNull(path), expr.buildJpaPredicate(cb, root));
}
 
Example 11
Project: datatable-java   File: Specifications.java   Source Code and License Vote up 4 votes
@Override
public Predicate combine(CriteriaBuilder builder, Predicate lhs, Predicate rhs) {
	return builder.or(lhs, rhs);
}