Example usage for javax.persistence TypedQuery getResultList

List of usage examples for javax.persistence TypedQuery getResultList

Introduction

In this page you can find the example usage for javax.persistence TypedQuery getResultList.

Prototype

List<X> getResultList();

Source Link

Document

Execute a SELECT query and return the query results as a typed List.

Usage

From source file:edu.sabanciuniv.sentilab.sare.models.base.documentStore.PersistentDocumentStore.java

/**
 * Gets identifiers of documents in this store.
 * @param em the {@link EntityManager} to get the documents from.
 * @return an {@link Iterable} of document identifiers.
 *//*from  ww  w.j  a va  2  s  .  c  o  m*/
public Iterable<byte[]> getDocumentIds(EntityManager em) {
    Validate.notNull(em, CannedMessages.NULL_ARGUMENT, "em");

    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<byte[]> cq = cb.createQuery(byte[].class);
    Root<PersistentDocument> doc = cq.from(PersistentDocument.class);
    cq.multiselect(doc.get("id"))
            .where(cb.equal(doc.get("store"), cb.parameter(PersistentDocumentStore.class, "store")));
    TypedQuery<byte[]> tq = em.createQuery(cq);
    tq.setParameter("store", this);
    return tq.getResultList();
}

From source file:com.pingdu.dao.licenseDao.LicenseDao.java

public List<License> searchLicenses(String searchType, Object keyWord, int page, int rows) {
    String jpql = new String();
    int head = (page - 1) * rows;
    if (searchType.equals("1")) {
        jpql = "select lic from License lic where lic.entCode =:keyWord order by lic.licenseCode";
    }//w  ww  .  jav  a 2 s  . c  om
    if (searchType.equals("???")) {
        jpql = "select lic from License lic where lic.licTypeCode =:keyWord order by lic.licenseCode";
    }
    if (searchType.equals("")) {
        jpql = "select lic from License lic where lic.uploadDate =:keyWord order by lic.licenseCode";
    }
    if (searchType.equals("")) {
        jpql = "select lic from License lic where lic.expireDate =:keyWord order by lic.licenseCode";
    }
    if (searchType.equals("?")) {
        jpql = "select lic from License lic where lic.isExpire =:keyWord order by lic.licenseCode";
    }
    TypedQuery<License> query = em().createQuery(jpql, License.class);
    //query.setHint(QueryHints.RESULT_TYPE, ResultType.Map);
    query.setParameter("keyWord", keyWord);
    query.setFirstResult(head);
    query.setMaxResults(rows);
    List<License> list = query.getResultList();
    return list;
}

From source file:io.hops.hopsworks.common.dao.certificates.CertsFacade.java

public List<UserCerts> findUserCertsByProjectId(String projectname) {
    TypedQuery<UserCerts> query = em.createNamedQuery("UserCerts.findByProjectname", UserCerts.class);
    query.setParameter("projectname", projectname);
    try {/*www. j  av a  2 s  .c o m*/
        List<UserCerts> res = query.getResultList();
        return res;
    } catch (EntityNotFoundException e) {
        Logger.getLogger(CertsFacade.class.getName()).log(Level.SEVERE, null, e);
    }
    return new ArrayList<>();
}

From source file:com.daphne.es.common.repository.support.SimpleBaseRepository.java

public Page<M> findAll(Specification<M> spec, Pageable pageable) {

    TypedQuery<M> query = getQuery(spec, pageable);
    return pageable == null ? new PageImpl<M>(query.getResultList()) : readPage(query, pageable, spec);
}

From source file:com.qpark.eip.core.spring.statistics.dao.StatisticsLoggingDao.java

/**
 * Get all {@link SystemUserLogType}s of the day of the application.
 *
 * @param date/*from  www  . jav a  2s.  c o m*/
 *            the date the calls are recorded.
 * @return the list of {@link SystemUserLogType}s.
 */
@Transactional(value = EipPersistenceConfig.TRANSACTION_MANAGER_NAME, propagation = Propagation.REQUIRED)
public List<SystemUserLogType> getSystemUserLogType(final Date date) {
    final CriteriaBuilder cb = this.em.getCriteriaBuilder();
    Date d = date;
    if (d == null) {
        d = new Date();
    }
    final CriteriaQuery<SystemUserLogType> q = cb.createQuery(SystemUserLogType.class);
    final Root<SystemUserLogType> c = q.from(SystemUserLogType.class);
    q.where(cb.equal(c.<String>get(SystemUserLogType_.context), this.contextNameProvider.getContextName()),
            cb.between(c.<Date>get(SystemUserLogType_.logDateItem), getDayStart(d), getDayEnd(d)));

    final TypedQuery<SystemUserLogType> typedQuery = this.em.createQuery(q);
    return typedQuery.getResultList();
}

From source file:name.marcelomorales.siqisiqi.openjpa.impl.OrmFinderImpl.java

@Override
@TransactionAttribute/*from   w  ww  .j  a v  a  2 s .c  o m*/
public List<T> findByFullTexts(final String terms, final OrderBy<T> orders, final long first, final long count,
        final String... fg) {

    LOGGER.debug("searching by text {} terms {}, fg {}", new Object[] { persistentClass, terms, fg });

    if (settings.returnsNullIfTermsAreNull() && Strings.isNullOrEmpty(terms)) {
        return Collections.emptyList();
    }

    if (fg != null) {
        entityManager.pushFetchPlan();
        entityManager.getFetchPlan().addFetchGroups(fg);
    }

    CriteriaBuilder cb = entityManager.getCriteriaBuilder();
    CriteriaQuery<T> q = cb.createQuery(persistentClass);
    Root<T> p = q.from(persistentClass);
    q.where(newFullTextPredicate(cb, p, terms));

    if (orders != null) {
        List<Order> orderList = orders.orders(cb, p);
        if (orderList != null && !orderList.isEmpty()) {
            q.orderBy(orderList);
        }
    }

    TypedQuery<T> query = entityManager.createQuery(q);

    OrmUtils.firstCount(query, first, count);
    List<T> resultList = query.getResultList();

    if (fg != null) {
        entityManager.popFetchPlan();
    }

    return resultList;
}

From source file:com.music.dao.PieceDao.java

public List<Piece> getPiecesInRange(DateTime start, DateTime end) {
    TypedQuery<Piece> query = getEntityManager().createQuery(
            "SELECT p FROM Piece p WHERE p.generationTime > :start AND p.generationTime < :end", Piece.class);
    query.setParameter("start", start);
    query.setParameter("end", end);

    return query.getResultList();
}

From source file:com.pingdu.dao.licenseDao.LicenseTypeDao.java

public LicenseType findByName(String licName) {
    String jpql = "select t from LicenseType t where t.licName =:licName ";
    TypedQuery<LicenseType> query = em().createQuery(jpql, LicenseType.class);
    //      query.setHint(QueryHints.RESULT_TYPE, ResultType.Map);
    query.setParameter("licName", licName);
    List<LicenseType> list = query.getResultList();
    return list.get(0);
}

From source file:com.qpark.eip.core.spring.statistics.dao.StatisticsLoggingDao.java

/**
 * Get all {@link ApplicationUserLogType}s of the day of the application.
 *
 * @param date/*from   w  ww. j a va 2 s.  co m*/
 *            the date the calls are recorded.
 * @return the list of {@link SystemUserLogType}s.
 */
@Transactional(value = EipPersistenceConfig.TRANSACTION_MANAGER_NAME, propagation = Propagation.REQUIRED)
public List<ApplicationUserLogType> getApplicationUserLogType(final Date date) {
    final CriteriaBuilder cb = this.em.getCriteriaBuilder();
    Date d = date;
    if (d == null) {
        d = new Date();
    }
    final CriteriaQuery<ApplicationUserLogType> q = cb.createQuery(ApplicationUserLogType.class);
    final Root<ApplicationUserLogType> c = q.from(ApplicationUserLogType.class);
    q.where(cb.equal(c.<String>get(ApplicationUserLogType_.context), this.contextNameProvider.getContextName()),
            cb.between(c.<Date>get(ApplicationUserLogType_.startItem), getDayStart(d), getDayEnd(d)));

    final TypedQuery<ApplicationUserLogType> typedQuery = this.em.createQuery(q);
    return typedQuery.getResultList();
}

From source file:org.mitre.oauth2.repository.impl.JpaOAuth2TokenRepository.java

@Override
public Set<OAuth2AccessTokenEntity> getAllAccessTokens() {
    TypedQuery<OAuth2AccessTokenEntity> query = manager.createNamedQuery(OAuth2AccessTokenEntity.QUERY_ALL,
            OAuth2AccessTokenEntity.class);
    return new LinkedHashSet<>(query.getResultList());
}