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:com.linksinnovation.elearning.repository.VideoAmountRepository.java

public List<VideoAmount> findByCondition(BasicConditionDTO amountDTO) {
    if (null == amountDTO.getCategory() && null == amountDTO.getStart()) {
        Query query = em.createNativeQuery(queryString + " ORDER BY update_date ASC");
        List<Object[]> resultList = query.getResultList();
        return mapObject(resultList);
    } else if (null != amountDTO.getCategory() && null == amountDTO.getStart()) {
        String queryAppend = queryString + " WHERE category_id=:cat";
        if (null != amountDTO.getSubCategory()) {
            queryAppend = queryAppend + " AND sub_category_id=:subcat";
        }/*from w  w w .j av  a2 s.  c o  m*/
        Query query = em.createNativeQuery(queryAppend + " ORDER BY update_date ASC");
        query.setParameter("cat", amountDTO.getCategory());
        if (null != amountDTO.getSubCategory()) {
            query.setParameter("subcat", amountDTO.getSubCategory());
        }
        List<Object[]> resultList = query.getResultList();
        return mapObject(resultList);
    } else if (null != amountDTO.getCategory() && null != amountDTO.getStart() && null != amountDTO.getEnd()) {
        String queryAppend = queryString + " WHERE update_date BETWEEN :start AND :end AND category_id=:cat";
        if (null != amountDTO.getSubCategory()) {
            queryAppend = queryAppend + " AND sub_category_id=:subcat";
        }
        Query query = em.createNativeQuery(queryAppend + " ORDER BY update_date ASC");
        query.setParameter("start", amountDTO.getStart());
        query.setParameter("end", amountDTO.getEnd());
        query.setParameter("cat", amountDTO.getCategory());

        if (null != amountDTO.getSubCategory()) {
            query.setParameter("subcat", amountDTO.getSubCategory());
        }
        List<Object[]> resultList = query.getResultList();
        return mapObject(resultList);
    } else if (null == amountDTO.getCategory() && null != amountDTO.getStart() && null != amountDTO.getEnd()) {
        String queryAppend = queryString + " WHERE update_date BETWEEN :start AND :end";
        Query query = em.createNativeQuery(queryAppend + " ORDER BY update_date ASC");
        query.setParameter("start", amountDTO.getStart());
        query.setParameter("end", amountDTO.getEnd());
        List<Object[]> resultList = query.getResultList();
        return mapObject(resultList);
    } else {
        Query query = em.createNativeQuery(queryString + " ORDER BY update_date ASC");
        List<Object[]> resultList = query.getResultList();
        return mapObject(resultList);
    }
}

From source file:com.plan.proyecto.repositorios.DaoCuentaImpl.java

@Override
public List<Cuenta> findAmigosByCuenta(Cuenta cuenta) {
    Query query = em.createNamedQuery("Cuenta.findAmigosByCuenta");
    query.setParameter("idorigen", cuenta.getId());
    return query.getResultList();
}

From source file:org.opentides.dao.impl.SystemCodesDaoJpaImpl.java

/** 
  * Selects all available categories except for the
  * specified ones /*from  w w w  . j a  va  2  s .co  m*/
  */
@SuppressWarnings("unchecked")
public List<String> getAllCategoriesExcept(String... categories) {
    String queryString = getJpqlQuery("jpql.systemcodes.findAllCategoriesExcept");
    Query queryObject = getEntityManager().createQuery(queryString);
    queryObject.setParameter("categories", categories);

    return queryObject.getResultList();
}

From source file:net.chrissearle.flickrvote.dao.JpaPhotographyDao.java

@SuppressWarnings("unchecked")
public List<Photographer> getAdmins() {
    Query query = entityManager.createQuery("SELECT p FROM Photographer p WHERE p.administrator = TRUE");

    return (List<Photographer>) query.getResultList();
}

From source file:org.syncope.core.persistence.dao.impl.TaskDAOImpl.java

@Override
public <T extends Task> List<T> findWithoutExecs(final Class<T> reference) {
    StringBuilder queryString = buildfindAllQuery(reference);
    queryString.append("WHERE e.executions IS EMPTY");
    final Query query = entityManager.createQuery(queryString.toString());
    return query.getResultList();
}

From source file:modelo.dao.GestionUsuariosImpl.java

@Override
public List<Usuario> obtenerUsuario(String nombre, String contrasena) {
    Query q = em.createNamedQuery("Usuario.findByNombreContrasena");
    q.setParameter(1, nombre);//  w  w  w  . j a va  2s  .  c om
    q.setParameter(2, contrasena);
    return q.getResultList();
}

From source file:gov.utah.dts.det.ccl.documents.reporting.reports.AbstractDimensionReport.java

@SuppressWarnings("unchecked")
protected Input getLicenseTypeInput(boolean required) {
    Query query = reportRunner
            .getNativeQuery("select distinct license_type from rpt_dim_license_type order by license_type");
    List<String> results = (List<String>) query.getResultList();

    Map<String, String> types = new LinkedHashMap<String, String>();
    if (!required) {
        types.put("All", "All");
    }/*from  w  w  w .  jav  a2s .  co  m*/
    for (String res : results) {
        types.put(res, res);
    }

    return new Input(LICENSE_TYPE_KEY, "License Type", required ? results.get(0) : "All", String.class,
            required, types, InputDisplayType.SELECT);
}

From source file:com.expressui.core.dao.security.PermissionDao.java

/**
 * Finds all permissions ordered by targetType and field.
 *
 * @return all permissions/*from w  w  w  .  j  a  v  a 2s.c  o m*/
 */
@Override
public List<Permission> findAll() {
    Query query = getEntityManager().createQuery("SELECT p FROM Permission p ORDER BY p.targetType, p.field");
    setReadOnly(query);

    return query.getResultList();
}

From source file:org.mifos.loan.repository.StandardLoanDao.java

@Override
@Transactional(readOnly = true)//from ww  w  .j  av a2 s.  com
public List<Loan> findLoansForClient(Integer clientId) {
    Query query = entityManager.createQuery("select loan from Loan loan where loan.clientId = :clientId");
    query.setParameter("clientId", clientId);
    return query.getResultList();
}

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

@Override
@SuppressWarnings("unchecked")
public User findByName(String userName) {
    Query query = entityManager.createQuery("SELECT u FROM UserEntity u WHERE u.userName = :userName")
            .setParameter("userName", userName);
    List<User> resultList = query.getResultList();

    if (resultList.size() == 0) {
        return null;
    } else if (resultList.size() == 1) {
        return resultList.get(0);
    }/*  w w  w . j  a  v  a  2  s.  c  om*/

    throw new IllegalStateException("Multiple users found for username: '" + userName + "'");
}