Example usage for javax.persistence.criteria CriteriaQuery where

List of usage examples for javax.persistence.criteria CriteriaQuery where

Introduction

In this page you can find the example usage for javax.persistence.criteria CriteriaQuery where.

Prototype

CriteriaQuery<T> where(Predicate... restrictions);

Source Link

Document

Modify the query to restrict the query result according to the conjunction of the specified restriction predicates.

Usage

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

public Page<Deposit> findPage(Member member, Pageable pageable) {
    if (member == null) {
        return new Page<Deposit>(Collections.<Deposit>emptyList(), 0, pageable);
    }//from www.  j av  a  2s. c o  m
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<Deposit> criteriaQuery = criteriaBuilder.createQuery(Deposit.class);
    Root<Deposit> root = criteriaQuery.from(Deposit.class);
    criteriaQuery.select(root);
    criteriaQuery.where(criteriaBuilder.equal(root.get("member"), member));
    return super.findPage(criteriaQuery, pageable);
}

From source file:eu.uqasar.service.company.CompanyService.java

/**
 * /*from  ww  w.  j  a va 2  s. com*/
 * @param companyId
 * @return
 */
public boolean companyExists(Long companyId) {
    logger.info(String.format("checking if Company with ID %d exists ...", companyId));
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<Long> criteria = cb.createQuery(Long.class);
    Root<Company> from = criteria.from(Company.class);
    criteria.where(cb.equal(from.get(Company_.id), companyId));
    criteria.select(cb.countDistinct(from));
    return (em.createQuery(criteria).getSingleResult().longValue() == 1);
}

From source file:eu.uqasar.service.company.CompanyService.java

public long countAllFiltered(final CompanyFilterStructure filter) {
    logger.infof("counting all Companies matching the filter %s ...", filter);
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<Long> criteria = cb.createQuery(Long.class);
    Root<Company> from = criteria.from(Company.class);
    criteria.where(cb.or(cb.equal(from.get(Company_.name), filter.getName()),
            cb.equal(from.get(Company_.shortName), filter.getShortName()),
            cb.equal(from.get(Company_.country), filter.getCountry())));
    criteria.select(cb.countDistinct(from));
    return em.createQuery(criteria).getSingleResult();
}

From source file:core.commonapp.server.dao.security.UserLoginSecurityGroupDaoHibernateImpl.java

@Override
public List<UserLoginSecurityGroup> findBySecurityGroup(SecurityGroup securityGroup, boolean includeOld) {
    CriteriaBuilder builder = getEntityManager().getCriteriaBuilder();
    CriteriaQuery<UserLoginSecurityGroup> query = builder.createQuery(getPersistClass());
    Root<UserLoginSecurityGroup> root = query.from(getPersistClass());
    query.where(builder.equal(root.get("securityGroup"), securityGroup));

    if (!includeOld) {
        query.where(builder.isNull(root.get("thruDate")));
    }// w  w w.j  av  a  2s. c  o m

    return (List<UserLoginSecurityGroup>) getEntityManager().createQuery(query).getResultList();
}

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 www. j a  v  a2 s.  c om*/
    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();
}

From source file:eu.uqasar.service.company.CompanyService.java

/**
 * /*from w  ww .  ja  va2s . c o  m*/
 * @param innovationObjective
 * @return
 */
public List<Company> getAllByAscendingNameFiltered(CompanyFilterStructure filter, int first, int count) {
    logger.infof("loading all Companies ordered by ascending name matching the given filter %s...", filter);
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<Company> criteria = cb.createQuery(Company.class);
    Root<Company> root = criteria.from(Company.class);

    criteria.where(cb.or(cb.equal(root.get(Company_.name), filter.getName()),
            cb.equal(root.get(Company_.shortName), filter.getShortName()),
            cb.equal(root.get(Company_.country), filter.getCountry()))

    );
    return em.createQuery(criteria).setFirstResult(first).setMaxResults(count).getResultList();
}

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

/**
 * Looks for the user by email.// w ww  .j a v a  2 s . 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.ContactDaoImpl.java

public List<ContactEntity> findByName(String name) {

    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 . j av a2  s.  co m*/
    cq.where(cb.like(userInfo.<String>get("lastName"), "%" + name + "%"));
    List<ContactEntity> result = getEntityManager().createQuery(cq).getResultList();
    return result;
}

From source file:com.ttech.cordovabuild.domain.application.ApplicationRepositoryImpl.java

@Override
public ApplicationBuilt getLatestBuilt(Application application) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<ApplicationBuilt> cq = cb.createQuery(ApplicationBuilt.class);
    Root<ApplicationBuilt> from = cq.from(ApplicationBuilt.class);
    cq = cq.where(cb.equal(from.get(ApplicationBuilt_.application), application))
            .orderBy(cb.desc(from.get(ApplicationBuilt_.startDate)));
    try {/*from ww  w.  j  a v a 2  s  .  c o  m*/
        return em.createQuery(cq).setMaxResults(1).getSingleResult();
    } catch (NoResultException e) {
        throw new ApplicationBuiltNotFoundException(e);
    }
}

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);/*  w  ww .j  av  a  2 s . c  o  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;
}