Package javax.persistence.criteria

Examples of javax.persistence.criteria.CriteriaBuilder.like()


        Expression<String> literal = cb.literal((String) "%"
            + searchstring + "%");
        // crit.add(Restrictions.ilike(searchcriteria, "%" +
        // searchstring + "%"));
        Path<String> path = c.get(searchcriteria);
        Predicate predicate = cb.like(path, literal);
        Predicate condition = cb.notEqual(c.get("deleted"), "true");
        cq.where(condition, predicate);
        cq.distinct(asc);
        if (asc) {
          cq.orderBy(cb.asc(c.get(orderby)));
View Full Code Here


        List<Predicate> predicates = new ArrayList<Predicate>();
        predicates.add(builder.equal(root.get(identityToProperty.getName()),
                lookupIdentity(identity, em)));

        Path<String> rolesOnly = root.get(relationshipNameProperty.getName());
        predicates.add(builder.like(rolesOnly, "%"));

        criteria.where(predicates.toArray(new Predicate[predicates.size()]));

        List<?> results = em.createQuery(criteria).getResultList();
        for (Object result : results) {
View Full Code Here

            Path<?> path = from.get(attribute);
            Class<?> javaType = attribute.getType().getJavaType();

            Predicate currentClause;
            if (javaType.equals(String.class)) {
                currentClause = cb.like((Expression<String>) path, (String) args[i++]);
            } else if (Number.class.isAssignableFrom(javaType) || javaType.isPrimitive()) {
                currentClause = cb.equal(path, args[i++]);
            } else {
                LOGGER.warning("field " + condition + " not found, ignoring");
                continue;
View Full Code Here

        Root<Conference> root = cq.from(Conference.class);

        Path<String> name = root.get("name");

        if(criteria.getName() != null) {
            cq.where(cb.like(name, "*" + criteria.getName() + "*"));
        }
        return getManager().createQuery(cq)
            .setFirstResult(criteria.getFirstResult())
            .setMaxResults(criteria.getMaxResult()).getResultList();
    }
View Full Code Here

      criteriaQuery.from(c);   

    criteriaQuery
      .select(root)
      .where(
        criteriaBuilder.like(
          root.get("nome").as(String.class),
          nome + "%" 
        )
      );
       
View Full Code Here

        CriteriaQuery<Movie> query = builder.createQuery(Movie.class);
        Root<Movie> root = query.from(Movie.class);
        EntityType<Movie> type = entityManager.getMetamodel().entity(Movie.class);

        Path<String> path = root.get(type.getDeclaredSingularAttribute(fieldname, String.class));
        Predicate condition = builder.like(path, "%" + param + "%");

        query.where(condition);

        return entityManager.createQuery(query).getResultList();
    }
View Full Code Here

            Path<?> path = from.get(attribute);
            Class<?> javaType = attribute.getType().getJavaType();

            Predicate currentClause;
            if (javaType.equals(String.class)) {
                currentClause = cb.like((Expression<String>) path, (String) args[i++]);
            } else if (Number.class.isAssignableFrom(javaType) || javaType.isPrimitive()) {
                currentClause = cb.equal(path, args[i++]);
            } else {
                LOGGER.warning("field " + condition + " not found, ignoring");
                continue;
View Full Code Here

        q.select(book);
       
        // Builds the predicates conditionally for the filled-in input fields
        List<Predicate> predicates = new ArrayList<Predicate>();
        if (!isEmpty(title)) {
            Predicate matchTitle = cb.like(book.get(Book_.title), title);
            predicates.add(matchTitle);
        }
        if (!isEmpty(author)) {
            Predicate matchAuthor = cb.like(book.join(Book_.authors).get(Author_.name), "%"+author+"%");
            predicates.add(matchAuthor);
View Full Code Here

        if (!isEmpty(title)) {
            Predicate matchTitle = cb.like(book.get(Book_.title), title);
            predicates.add(matchTitle);
        }
        if (!isEmpty(author)) {
            Predicate matchAuthor = cb.like(book.join(Book_.authors).get(Author_.name), "%"+author+"%");
            predicates.add(matchAuthor);
        }
        // for price fields, also the comparison operation changes based on whether
        // minimum or maximum price or both have been filled.
        if (minPrice != null && maxPrice != null) {
View Full Code Here

    criteria.select( orderRoot );
    // create correlated subquery
    Subquery<Customer> customerSubquery = criteria.subquery( Customer.class );
    Root<Order> orderRootCorrelation = customerSubquery.correlate( orderRoot );
    Join<Order, Customer> orderCustomerJoin = orderRootCorrelation.join( Order_.customer );
    customerSubquery.where( builder.like( orderCustomerJoin.get( Customer_.name ), "%Caruso" ) )
        .select( orderCustomerJoin );
    criteria.where( builder.exists( customerSubquery ) );
    em.createQuery( criteria ).getResultList();

    em.getTransaction().commit();
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.