Example usage for javax.persistence.criteria CriteriaQuery select

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

Introduction

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

Prototype

CriteriaQuery<T> select(Selection<? extends T> selection);

Source Link

Document

Specify the item that is to be returned in the query result.

Usage

From source file:org.openmeetings.app.data.user.Salutationmanagement.java

/**
 * get a list of all availible Salutations
 * //w  w w  .j  av  a  2 s  .  c o m
 * @param user_level
 * @return
 */
public List<Salutations> getUserSalutations(long language_id) {
    try {
        CriteriaBuilder cb = em.getCriteriaBuilder();
        CriteriaQuery<Salutations> cq = cb.createQuery(Salutations.class);
        Root<Salutations> from = cq.from(Salutations.class);
        CriteriaQuery<Salutations> select = cq.select(from);
        TypedQuery<Salutations> q = em.createQuery(select);
        List<Salutations> ll = q.getResultList();
        for (Salutations ti : ll) {
            ti.setLabel(fieldmanagment.getFieldByIdAndLanguage(ti.getFieldvalues_id(), language_id));
        }

        return ll;
    } catch (Exception ex2) {
        log.error("[addUserSalutation]", ex2);
    }
    return null;
}

From source file:org.sloth.persistence.impl.ReportDaoImpl.java

@Override
public Collection<Report> getByObservation(Observation o)
        throws NullPointerException, IllegalArgumentException {
    if (o == null) {
        throw new NullPointerException();
    }//w  w w . j a v a  2s. c o m
    if (o.isNew()) {
        throw new IllegalArgumentException();
    }
    CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
    CriteriaQuery<Report> cq = cb.createQuery(Report.class);
    Root<Report> r = cq.from(Report.class);
    cq.select(r).where(cb.equal(r.get(Report_.observation), o));
    Collection<Report> result = getEntityManager().createQuery(cq).getResultList();
    logger.info("{} Reports for Observation {}.", result.size(), o);
    return result;
}

From source file:se.kth.csc.persist.JPAStore.java

@Override
public List<Queue> fetchAllQueues() {
    CriteriaBuilder cb = entityManager.getCriteriaBuilder();
    CriteriaQuery<Queue> q = cb.createQuery(Queue.class);
    return entityManager.createQuery(q.select(q.from(Queue.class))).getResultList();
}

From source file:de.ks.idnadrev.information.view.InformationOverviewDS.java

protected List<Tag> getTags(List<String> tagNames, EntityManager em) {
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<Tag> query = builder.createQuery(Tag.class);
    Root<Tag> root = query.from(Tag.class);
    Path<String> namePath = root.get(KEY_NAME);
    query.select(root);
    query.where(namePath.in(tagNames));//  w  ww.  ja  va2 s .c o m

    return em.createQuery(query).getResultList();
}

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

@Override
public List<ApplicationBuilt> getApplications(User owner) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<ApplicationBuilt> cq = cb.createQuery(ApplicationBuilt.class);
    Root<ApplicationBuilt> from = cq.from(ApplicationBuilt.class);
    return em//from ww  w  .j a v a  2 s . c o m
            .createQuery(cq.select(from)
                    .where(cb.equal(from.get(ApplicationBuilt_.application).get(Application_.owner), owner)))
            .getResultList();
}

From source file:eu.uqasar.service.ProductService.java

public List<Product> sortAscendingDates() {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<Product> criteria = cb.createQuery(Product.class);
    Root<Product> from = criteria.from(Product.class);
    criteria.select(from);
    return em.createQuery(criteria.orderBy(cb.asc(from.get("releaseDate")))).getResultList();
}

From source file:eu.uqasar.service.ProductService.java

public List<Product> sortDescendingDates() {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<Product> criteria = cb.createQuery(Product.class);
    Root<Product> from = criteria.from(Product.class);
    criteria.select(from);
    return em.createQuery(criteria.orderBy(cb.desc(from.get("releaseDate")))).getResultList();
}

From source file:com.aimdek.ccm.dao.impl.test.BasicAbstractGenericDaoImplTest.java

/**
 * Find by id./*from  www . j av  a 2s . co m*/
 *
 * @param id
 *            the id
 * @param entityClass
 *            the entity class
 * @return the entity type
 */
public EntityType findById(IDType id, Class<EntityType> entityClass) {

    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<EntityType> query = builder.createQuery(entityClass);
    Root<EntityType> root = query.from(entityClass);
    query.select(root);
    query.where(builder.equal(root.get("id"), id));

    return entityManager.createQuery(query).getSingleResult();
}

From source file:com.june.app.board.repository.jpa.BoardRepositoryImpl.java

@Override
public long boardListCnt(Board vo) {

    CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder();

    int bbsId = vo.getBbsId();
    CriteriaQuery<Long> countQuery = criteriaBuilder.createQuery(Long.class);
    Root<Board> from = countQuery.from(Board.class);
    countQuery.select(criteriaBuilder.count(from));
    if (bbsId > 0) {
        countQuery.where(criteriaBuilder.equal(from.get("bbsId"), bbsId));
    }//from ww w.  ja  va2 s. c  o m
    Long count = em.createQuery(countQuery).getSingleResult();

    return count;

}

From source file:com.aimdek.ccm.dao.impl.UserRepositoryImpl.java

/**
 * {@inheritDoc}//from   w  ww  . ja  v a2s  .c o  m
 */
public List<User> getCustomers() {

    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<User> query = builder.createQuery(User.class);
    Root<User> root = query.from(User.class);
    query.select(root);
    query.where(builder.equal(root.<String>get(FIELDCONSTANT_USER_ROLE), ROLE_CUSTOMER));
    return entityManager.createQuery(query).getResultList();
}