Example usage for javax.persistence.criteria CriteriaBuilder equal

List of usage examples for javax.persistence.criteria CriteriaBuilder equal

Introduction

In this page you can find the example usage for javax.persistence.criteria CriteriaBuilder equal.

Prototype

Predicate equal(Expression<?> x, Object y);

Source Link

Document

Create a predicate for testing the arguments for equality.

Usage

From source file:cz.vse.webmail.EmailDAOBean.java

@Override
public List<Email> getFilteredEmails(User user, EmailListFilter filter) {
    CriteriaBuilder cb = entityManager.getCriteriaBuilder();
    CriteriaQuery<Email> criteria = cb.createQuery(Email.class);
    Root<Email> root = criteria.from(Email.class);
    List<Predicate> predicates = new ArrayList<Predicate>();
    predicates.add(cb.equal(root.<User>get("owner"), user));
    if (StringUtils.isNoneBlank(filter.getTo())) {
        predicates.add(cb.like(root.<String>get("to"), "%" + filter.getTo() + "%"));
    }//  ww  w  . j  av  a2  s .c  om
    criteria.select(root).where(predicates.toArray(new Predicate[] {}));
    return entityManager.createQuery(criteria).getResultList();
}

From source file:aka.pirana.jdoc.JChart.java

private XYDataset SampleGenerator() {
    manager.getTransaction().begin();//from   w ww .j a  v a2  s.  c  o m
    CriteriaBuilder cb = manager.getCriteriaBuilder();
    CriteriaQuery<Consultation> query = cb.createQuery(Consultation.class);
    Root<Consultation> sm = query.from(Consultation.class);
    query.where(cb.equal(sm.get("patient.id"), id.toString()));
    TypedQuery<Consultation> q = manager.createQuery(query);
    List<Consultation> results = q.getResultList();
    XYSeries xyWeightSeries = new XYSeries("Weight");
    XYSeries xyFatSeries = new XYSeries("Fat");
    XYSeries xyMuscleSeries = new XYSeries("Muscle");
    XYSeries xyWaterSeries = new XYSeries("Water");
    int i = 2;
    results.stream().map((result) -> {
        xyWeightSeries.add(i, result.getC_weight());
        return result;
    }).map((result) -> {
        xyFatSeries.add(i, result.getC_gm());
        return result;
    }).map((result) -> {
        xyMuscleSeries.add(i, result.getC_mm());
        return result;
    }).forEach((result) -> {
        xyWaterSeries.add(i, result.getC_hm());
    });
    XYSeriesCollection xyseriescollection = new XYSeriesCollection(xyWeightSeries);
    xyseriescollection.addSeries(xyFatSeries);
    xyseriescollection.addSeries(xyMuscleSeries);
    xyseriescollection.addSeries(xyWaterSeries);
    return xyseriescollection;
}

From source file:net.osgiliath.jpa.repository.impl.HelloJpaRepository.java

@Override
public Collection<? extends HelloEntity> findByHelloObjectMessage(String message_p) {
    CriteriaBuilder cb = entityManager.getCriteriaBuilder();
    CriteriaQuery<HelloEntity> cq = cb.createQuery(HelloEntity.class);
    Root<HelloEntity> helloObject = cq.from(HelloEntity.class);
    cq.select(helloObject);/*from w w w  .  j a  v  a2 s.c o  m*/
    Predicate where = cb.equal(helloObject.get("helloMessage"), message_p);
    cq.where(where);
    TypedQuery<HelloEntity> q = entityManager.createQuery(cq);
    List<HelloEntity> result = q.getResultList();
    return result;
}

From source file:de.logicline.splash.dao.ContactDaoImpl.java

public ContactEntity getContactByUserId(String userId) {

    CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
    CriteriaQuery<ContactEntity> cq = cb.createQuery(ContactEntity.class);
    Root<ContactEntity> userInfo = cq.from(ContactEntity.class);
    cq.select(userInfo);//from w w  w .ja  v  a2 s .co  m
    cq.where(cb.equal(userInfo.get("userIdFk"), userId));
    List<ContactEntity> resultList = em.createQuery(cq).getResultList();

    ContactEntity result = null;
    if (resultList != null && resultList.size() > 0) {
        result = resultList.get(0);
    }

    return result;
}

From source file:de.logicline.splash.dao.UserDaoImpl.java

public UserEntity getUser(String token) {
    CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
    CriteriaQuery<UserEntity> cq = cb.createQuery(UserEntity.class);
    Root<UserEntity> user = cq.from(UserEntity.class);
    cq.select(user);//w  w  w .j a  va  2s  .com
    cq.where(cb.equal(user.get("token"), token));
    List<UserEntity> resultList = getEntityManager().createQuery(cq).getResultList();

    UserEntity result = null;
    if (resultList != null && resultList.size() > 0) {
        result = resultList.get(0);
        return result;
    }

    return null;
}

From source file:com.datapine.dao.impl.UserDAOImpl.java

/**
 * Looks for the user by email./*from   ww w . j a v  a2s. c  o m*/
 * @param email The specified email.
 * @return Found user.
 */
@Override
public final User findByEmail(final String email) {
    final CriteriaBuilder builder = this.manager.getCriteriaBuilder();
    final CriteriaQuery<User> query = builder.createQuery(User.class);
    final Root<User> root = query.from(User.class);
    query.where(builder.equal(root.get("email"), email));
    return this.manager.createQuery(query).getResultList().get(0);
}

From source file:de.logicline.splash.dao.UserDaoImpl.java

public UserEntity getUserByName(String username) {
    CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
    CriteriaQuery<UserEntity> cq = cb.createQuery(UserEntity.class);
    Root<UserEntity> user = cq.from(UserEntity.class);
    cq.select(user);/*w  w  w.  ja  v  a2  s .c  o  m*/
    cq.where(cb.equal(user.get("username"), username));
    List<UserEntity> resultList = getEntityManager().createQuery(cq).getResultList();

    if (resultList == null || resultList.size() == 0) {
        log.debug("UserEntity not found");
        return null;
    } else if (resultList.size() > 1) {
        log.warn("Multiple Users found for User with Username: " + username);
        return null;
    }

    return resultList.get(0);
}

From source file:net.kaczmarzyk.spring.data.jpa.domain.EqualEnum.java

@Override
public Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
    List<Enum<?>> matchingEnumConstants = findMatchingEnumConstants(getEnumClass(root));
    Iterator<Enum<?>> iterator = matchingEnumConstants.iterator();
    Predicate combinedPredicates = builder.equal(this.<Enum<?>>path(root), iterator.next());
    while (iterator.hasNext()) {
        combinedPredicates = builder.or(builder.equal(this.<Enum<?>>path(root), iterator.next()),
                combinedPredicates);/* w  w  w.  jav a 2s . c  om*/
    }
    return combinedPredicates;
}

From source file:com.sixsq.slipstream.persistence.Run.java

private static Predicate viewListCommonQueryOptions(CriteriaBuilder builder, Root<Run> rootQuery, User user,
        String moduleResourceUri, String cloudServiceName) {
    Predicate where = null;/*from   w  w w. j  a  v  a  2s .  c  o m*/
    if (!user.isSuper()) {
        where = andPredicate(builder, where, builder.equal(rootQuery.get("user_"), user.getName()));
    }
    if (moduleResourceUri != null && !"".equals(moduleResourceUri)) {
        where = andPredicate(builder, where,
                builder.equal(rootQuery.get("moduleResourceUri"), moduleResourceUri));
    }
    if (cloudServiceName != null && !"".equals(cloudServiceName)) {
        // TODO: Replace the 'like' by an 'equals'
        where = andPredicate(builder, where,
                builder.like(rootQuery.<String>get("cloudServiceNames"), "%" + cloudServiceName + "%"));
    }
    return where;
}

From source file:net.groupbuy.dao.impl.TagDaoImpl.java

public List<Tag> findList(Type type) {
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<Tag> criteriaQuery = criteriaBuilder.createQuery(Tag.class);
    Root<Tag> root = criteriaQuery.from(Tag.class);
    criteriaQuery.select(root);/*from  w ww  . jav a  2  s .  com*/
    if (type != null) {
        criteriaQuery.where(criteriaBuilder.equal(root.get("type"), type));
    }
    criteriaQuery.orderBy(criteriaBuilder.asc(root.get("order")));
    return entityManager.createQuery(criteriaQuery).setFlushMode(FlushModeType.COMMIT).getResultList();
}