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:com.siriusit.spezg.multilib.storage.jpa.JpaLoanRepository.java

@Override
public List<? extends Loan> findLoansByUnit(Unit unit) {
    TypedQuery<LoanDomainObject> query = entityManager.createNamedQuery("findLoanByUnit",
            LoanDomainObject.class);
    query.setParameter("unit", unit);
    return query.getResultList();
}

From source file:com.ewcms.content.particular.dao.FrontEmployeArticleDAO.java

public List<EmployeArticle> findEmployeChannelArticleLimit(Integer channelId, Integer number) {
    String hql = "From EmployeArticle As p where p.channelId=:channelId and p.release=true Order By p.published desc limit "
            + number;/* w w w.  j  a  v a 2 s  .  com*/
    TypedQuery<EmployeArticle> query = this.getEntityManager().createQuery(hql, EmployeArticle.class);
    query.setParameter("channelId", channelId);
    return query.getResultList();
}

From source file:org.mitre.uma.repository.impl.JpaResourceSetRepository.java

@Override
public Collection<ResourceSet> getAllForClient(String clientId) {
    TypedQuery<ResourceSet> query = em.createNamedQuery(ResourceSet.QUERY_BY_CLIENT, ResourceSet.class);
    query.setParameter(ResourceSet.PARAM_CLIENTID, clientId);
    return query.getResultList();
}

From source file:com.deltastar.task7.core.repository.api.impl.EmployeeRepositoryImpl.java

/**
 * {@inheritDoc}// ww w .j a  v a 2  s.  co m
 */
public Employee getEmployeeByUserName(final String userName) {
    TypedQuery<Employee> query = entityManager.createNamedQuery("findEmployeeByUserName", Employee.class);
    query.setParameter("p_userName", userName);
    List<Employee> employees = query.getResultList();
    return (employees != null && !employees.isEmpty()) ? employees.get(0) : null;
}

From source file:com.siriusit.spezg.multilib.storage.jpa.JpaLoanRepository.java

@Override
public List<? extends Loan> findLoanByOwner(Person owner) {
    TypedQuery<LoanDomainObject> query = entityManager.createNamedQuery("findLoanByOwner",
            LoanDomainObject.class);
    query.setParameter("owner", owner);
    return query.getResultList();
}

From source file:org.jasig.portlet.blackboardvcportlet.dao.impl.UserSessionUrlDaoImpl.java

@Override
public Set<UserSessionUrl> getAllUserSessionUrls() {
    final TypedQuery<UserSessionUrlImpl> query = this.createQuery(this.findAllUserSessionUrl);
    return new LinkedHashSet<UserSessionUrl>(query.getResultList());
}

From source file:ispok.dao.TournamentHibernateJpaDao.java

@Override
public List<Tournament> getPage(int first, int rows, String sortBy, boolean ascending,
        Map<String, Object> filters) {

    //        Session session = getEntityManager().unwrap(Session.class);
    //        Criteria criteria = session.createCriteria(Tournament.class);
    //        CriteriaBuilder cb = entityManagerfactory.getCriteriaBuilder();
    //        CriteriaQuery<Tournament> cq = cb.createQuery(Tournament.class);
    //        Root<Tournament> tou = cq.from(Tournament.class);
    //        cb.para
    //        criteria.add(cb.equal(tou, tou))
    //        String queryString = "SELECT e FROM " + Tournament.class.getSimpleName();
    //        if (!filters.isEmpty()) {
    //            queryString += " WHERE ";
    //            for (Map.Entry<String, Object> entry : filters.entrySet()) {
    //                if ("id".equals(entry.getKey())) {
    //                    queryString += "e." + entry.getKey() + " = " + entry.getValue();
    //                } else {
    //                    queryString += "e." + entry.getKey() + " LIKE '" + entry.getValue() + "'";
    //                }
    //            }
    //        }//from w  w w  . j ava2 s.  c om
    //                " e WHERE e." + property + " = :value";
    //        return getEntityManager().createQuery(queryString).setParameter("value", value).getResultList();
    //        return null;
    //        Session session = getEntityManager().unwrap(Session.class);
    //        Criteria criteria = session.createCriteria(Tournament.class);
    //
    //        for (Map.Entry<String, Object> filter : filters.entrySet()) {
    //            if ("id".equals(filter.getKey())) {
    //                criteria.add(Restrictions.eq("id", Long.parseLong(filter.getValue().toString())));
    //            } else {
    //                criteria.add(Restrictions.ilike(filter.getKey(), (String) filter.getValue(), MatchMode.START));
    //            }
    //        }
    //
    //        if (ascending) {
    //            criteria.addOrder(Order.asc(sortBy));
    //        } else {
    //            criteria.addOrder(Order.desc(sortBy));
    //        }
    //
    //        criteria.setFirstResult(first);
    //        criteria.setMaxResults(rows);
    //
    //        criteria.setResultTransformer(Transformers.aliasToBean(clazz));
    //        List<ENTITY> list = criteria.list();
    //
    //        return list;
    EntityManager em = getEntityManager();

    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<Tournament> cq = cb.createQuery(Tournament.class);
    Root<Tournament> t = cq.from(Tournament.class);

    cq.select(t);

    TypedQuery<Tournament> tq = em.createQuery(cq);

    List<Tournament> tournaments = tq.getResultList();
    return tournaments;

}

From source file:org.openmeetings.app.data.basic.dao.SOAPLoginDaoImpl.java

public SOAPLogin getSOAPLoginByHash(String hash) {
    try {// ww  w .  j a  v a  2 s  . c  om
        String hql = "select sl from SOAPLogin as sl " + "WHERE sl.hash LIKE :hash";
        TypedQuery<SOAPLogin> query = em.createQuery(hql, SOAPLogin.class);
        query.setParameter("hash", hash);
        List<SOAPLogin> sList = query.getResultList();

        if (sList.size() > 1) {
            throw new Exception("there are more then one SOAPLogin with identical hash! " + hash);
        }

        if (sList.size() == 1) {
            return sList.get(0);
        }

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

From source file:kirchnerei.note.model.DataService.java

private <T> List<T> getResultList(TypedQuery<T> q) {
    try {//  w w w .  ja  v  a  2 s  . c  o  m
        return q.getResultList();
    } catch (Exception e) {
        return Collections.emptyList();
    }
}

From source file:com.ewcms.content.particular.dao.FrontEnterpriseArticleDAO.java

public List<EnterpriseArticle> findEnterpriseChannelArticleLimit(Integer channelId, Integer number) {
    String hql = "From EnterpriseArticle As p where p.channelId=:channelId and p.release=true Order By p.published desc limit "
            + number;/*from w w w  .  j  a va 2s . c om*/
    TypedQuery<EnterpriseArticle> query = this.getEntityManager().createQuery(hql, EnterpriseArticle.class);
    query.setParameter("channelId", channelId);
    return query.getResultList();
}