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:eu.planets_project.tb.impl.persistency.ServiceRecordPersistencyImpl.java

@SuppressWarnings("unchecked")
public List<ServiceRecordImpl> getAllServiceRecordsOfType(String type) {
    Query query = manager.createQuery("from ServiceRecordImpl where serviceType=:type");
    query.setParameter("type", type);
    return (List<ServiceRecordImpl>) query.getResultList();
}

From source file:es.ucm.fdi.dalgs.user.repository.UserRepository.java

public User findByEmail(String email) {
    Query query = em.createQuery("select s from User s where s.email=?1");
    query.setParameter(1, email);/*ww w .j av a  2s  .  c  o m*/

    if (query.getResultList().isEmpty()) {
        //         logger.error("User not found by email " + email);
        return null;
    }
    return (User) query.getSingleResult();
}

From source file:com.ny.apps.dao.BaseDaoImpl.java

@Override
public List<?> find(String queryStr, Object... params) {
    Query query = prepareParameterizedQuery(entityManager.createQuery(queryStr), params);
    List<?> list = query.getResultList();
    return list;//from w  w w  . ja v  a2s. c  o  m
}

From source file:com.fantasy.stataggregator.entities.dao.AbstractRepository.java

public List<T> findRange(int[] range) {
    javax.persistence.criteria.CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
    cq.select(cq.from(entityClass));//w w  w . j  a va2  s  .  com
    javax.persistence.Query q = em.createQuery(cq);
    q.setMaxResults(range[1] - range[0] + 1);
    q.setFirstResult(range[0]);
    return q.getResultList();
}

From source file:com.actionbazaar.email.EmailService.java

/**
 * Sends out an email//from w  ww  .  j  ava  2  s.c om
 * @param message - message to be sent
 */
public void onMessage(Message message) {

    try {
        EmailRequest emailRequest = (EmailRequest) ((ObjectMessage) message).getObject();

        Query query = entityManager.createQuery("select e from Email e where e.action = ?1");
        query.setParameter(1, emailRequest.getAction());
        List results = query.getResultList();
        if (results.size() != 1) {
            logger.severe("A total of " + results.size() + " email templates were returned for action "
                    + emailRequest.getAction());
            return;
        }
        System.out.println("--> Sending email.");
        Email emailInfo = (Email) results.get(0);
        logger.info("Speaker Directory: " + attachmentDirectory);
        HtmlEmail email = new HtmlEmail();
        email.setMailSession(mailSession);
        email.setTextMsg("Hello World!");
        //  email.setSubject(template.getSubject());
        email.addTo("rcuprak@mac.com");
        email.setFrom("java@ctjava.org");
        //  email.send();

        /*       emailTemplate.process(emailRecipient.getReplacementTokens());
                for (Map.Entry<String,File> entry : emailTemplate.getCidMappings().entrySet()) {
                    email.embed(entry.getValue(),entry.getKey());
                }
                email.setHtmlMsg(emailTemplate.getPatchedEmail());
          */
    } catch (Throwable t) {
        t.printStackTrace();
        //context.setRollbackOnly();
    }
}

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

@Override
public <T extends Task> List<T> findAll(final ExternalResource resource, final Class<T> reference) {

    StringBuilder queryString = buildfindAllQuery(reference);
    if (SchedTask.class.equals(reference)) {
        queryString.append("AND ");
    } else {/*from  ww w  .jav  a 2  s.c  o  m*/
        queryString.append("WHERE ");
    }
    queryString.append("e.resource=:resource");

    final Query query = entityManager.createQuery(queryString.toString());
    query.setParameter("resource", resource);

    return query.getResultList();
}

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

/**
 * @see vlove.dao.GenericDao#query(String, Map, int, int)
 *//* w  w w . ja va  2  s .c om*/
@Override
public <T> List<T> query(String query, Map<String, Object> parameters, int firstResult, int maxResults) {
    Query q = em.createQuery(query).setFirstResult(firstResult).setMaxResults(maxResults);
    applyParameters(q, parameters);
    return q.getResultList();
}

From source file:com.ny.apps.dao.BaseDaoImpl.java

public List<?> findByNativeSQL(String queryStr, Object... params) {
    Query query = prepareParameterizedQuery(entityManager.createNativeQuery(queryStr), params);
    List<?> list = query.getResultList();
    return list;//from   w  w  w  .j  a v  a 2  s  . c  om
}

From source file:com.ny.apps.dao.BaseDaoImpl.java

public List<?> findByNativeSQL(int start, int delta, String queryStr, Object... params) {
    Query query = prepareParameterizedQuery(entityManager.createNativeQuery(queryStr), params);
    List<?> list = query.getResultList();
    return list;//from w w w. ja  v a2 s  .c om
}

From source file:com.sct.descubriendoturuta.service.InsigniaServiceImpl.java

@Override
@Transactional/*ww w . j  a  va 2 s . c  om*/
public List<Usuario> obtenerUsuariosPopulares() {

    Query query = em.createQuery(
            "select p.usuario.id, SUM(p.puntuacion) from Puntuacion p GROUP BY p.usuario.id ORDER BY SUM(p.puntuacion) DESC");
    List<Puntuacion> puntos = query.getResultList();
    List<Usuario> usuarios = new ArrayList<Usuario>();

    Object[] v = puntos.toArray();
    for (Object o : v) {
        Object[] ro = (Object[]) o;
        Usuario u = em.find(Usuario.class, ro[0]);
        u.setPuntos((Double) ro[1]);

        usuarios.add(u);
    }

    return usuarios;
}