Example usage for javax.persistence Query getResultList

List of usage examples for javax.persistence Query getResultList

Introduction

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

Prototype

List getResultList();

Source Link

Document

Execute a SELECT query and return the query results as an untyped List.

Usage

From source file:de.berlios.jhelpdesk.dao.jpa.AnnouncementDAOJpa.java

public List<Announcement> getLastAnnouncements(final int howMuch) {
    try {//from w  w w.  j a va 2  s  . c  om
        return (List<Announcement>) this.jpaTemplate.executeFind(new JpaCallback() {
            public Object doInJpa(EntityManager em) throws PersistenceException {
                Query q = em.createNamedQuery("Announcement.allOrderByCreateDateDesc");
                q.setMaxResults(howMuch);
                return q.getResultList();
            }
        });
    } catch (Exception ex) {
        log.error("wystapil problem..", ex);
    }
    return Collections.<Announcement>emptyList();
}

From source file:org.simbasecurity.core.domain.repository.LoginMappingDatabaseRepository.java

@SuppressWarnings("unchecked")
@Override// w w w.ja  v a  2s  .co  m
public LoginMapping findByToken(String token) {
    Query query = entityManager.createQuery("SELECT lm FROM LoginMappingEntity lm WHERE lm.token = :token")
            .setParameter("token", token);

    List<LoginMapping> resultList = query.getResultList();
    if (resultList.size() == 0) {
        return null; //can also be when token is expired/cleaned up
    } else if (resultList.size() == 1) {
        return resultList.get(0);
    }

    throw new IllegalStateException("Multiple mappings found for token: '" + token + "'");
}

From source file:org.mifos.user.repository.StandardOfficeLevelDao.java

@Override
@Transactional(readOnly = true)//from w ww .j a  v a  2 s  .c om
public OfficeLevel getBranchOfficeLevel() {
    Query query = entityManager.createQuery(
            "select officeLevel from OfficeLevel officeLevel where officeLevel.levelBelow IS NULL");
    List<OfficeLevel> result = query.getResultList();
    if (result.isEmpty()) {
        throw new MifosRuntimeException("Built in branch office level not found.");
    } else if (result.size() > 1) {
        throw new MifosRuntimeException("Multiple branch office levels found.");
    }
    return result.get(0);
}

From source file:org.mifos.user.repository.StandardOfficeLevelDao.java

@Override
@Transactional(readOnly = true)/*from w  w  w.j a  v a2s.co  m*/
public OfficeLevel getHeadOfficeLevel() {
    Query query = entityManager.createQuery(
            "select officeLevel from OfficeLevel officeLevel where officeLevel.levelAbove IS NULL");
    List<OfficeLevel> result = query.getResultList();
    if (result.isEmpty()) {
        throw new MifosRuntimeException("Built in head office level not found.");
    } else if (result.size() > 1) {
        throw new MifosRuntimeException("Multiple head office levels found.");
    }
    return result.get(0);
}

From source file:com.gerenciaProyecto.DaoImple.ProductoDaoImpl.java

@Override
public List<Producto> listar() {
    EntityManager em = getEntityManager();
    List<Producto> lista = new ArrayList<Producto>();
    Query q = em.createQuery("SELECT p FROM Producto p where p.estado= :estado ");
    q.setParameter("estado", Producto.ESTADOS.ACTIVO.getEstado());
    lista = q.getResultList();
    return lista;
}

From source file:vlove.dao.impl.GenericDaoImpl.java

/**
 * @see vlove.dao.GenericDao#namedQuery(String, Map)
 *///from www. j  a  v a2s.  co  m
@Override
public <T> List<T> namedQuery(String query, Map<String, Object> parameters) {
    Query q = em.createNamedQuery(query);
    applyParameters(q, parameters);
    return q.getResultList();
}

From source file:com.gerenciaProyecto.DaoImple.ProductoDaoImpl.java

@Override
public List<Producto> listarInactivos() {
    EntityManager em = getEntityManager();
    List<Producto> lista = new ArrayList<Producto>();
    Query q = em.createQuery("SELECT p FROM Producto p where p.estado= :estado ");
    q.setParameter("estado", Producto.ESTADOS.INACTIVO.getEstado());
    lista = q.getResultList();
    return lista;
}

From source file:dao.ExperienceDAOImpl.java

@Override
public List<ExperienceEntity> findExperiencesForProfil(Long profileId, int limit) {
    Query q;
    q = this.em.createQuery("SELECT e FROM ExperienceEntity e WHERE e.profile.id = ?");
    q.setParameter(1, profileId);/*from w  w  w.  java2 s  . co  m*/
    q.setMaxResults(limit);
    return q.getResultList();
}

From source file:nc.noumea.mairie.appock.dao.impl.PanierDaoImpl.java

@Override
public List<Panier> findAllWithArticleCatalogue(ArticleCatalogue articleCatalogue) {
    // @formatter:off
    String jpaQuery = "   SELECT panier FROM ArticlePanier articlePanier "
            + "         left join articlePanier.articleCatalogue articleCatalogue "
            + "         left join articlePanier.panier panier "
            + "       WHERE articleCatalogue = :articleCatalogue";
    // @formatter:on

    Query query = persistentManager.getEntityManager().createQuery(jpaQuery);

    AppockUtil.setParameter(query, "articleCatalogue", articleCatalogue);

    try {//  w  ww  .  j  a v a 2  s . co  m
        return query.getResultList();
    } catch (NoResultException e) {
        return null;
    }
}

From source file:org.simbasecurity.core.domain.repository.SSOTokenMappingDatabaseRepository.java

@SuppressWarnings("unchecked")
@Override//  w  ww . j  a  va2 s  .  co m
public SSOTokenMapping findByToken(String tokenKey) {
    Query query = entityManager.createQuery("SELECT tm FROM SSOTokenMappingEntity tm WHERE tm.token = :token")
            .setParameter("token", tokenKey);
    List<SSOTokenMapping> resultList = query.getResultList();

    if (resultList.size() == 0) {
        return null;
    } else if (resultList.size() == 1) {
        return resultList.get(0);
    }

    throw new IllegalStateException("Multiple mappings found for tokenKey: '" + tokenKey + "'");
}