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.headissue.pigeon.util.JPAUtils.java

/**
 * Returns a list of entities. Note: it returns always a list, never null.
 *//* w w  w . j a  v  a  2 s .co m*/
public static <T> List<T> getResultList(TypedQuery<T> q) {
    try {
        return q.getResultList();
    } catch (Exception e) {
        LogUtils.trace(log, e, "access to a list of entities is failed");
        return Collections.emptyList();
    }
}

From source file:fr.univrouen.poste.domain.LogMail.java

public static List<String> getAllMailTo() {
    EntityManager em = entityManager();/*from w w  w  . ja  va2  s  . c o  m*/
    TypedQuery<String> q = em.createQuery("select distinct(o.mailTo) FROM LogMail o ORDER BY o.mailTo",
            String.class);
    return q.getResultList();
}

From source file:org.mmonti.entitygraph.repository.CustomGenericJpaRepository.java

private static Long executeCountQuery(TypedQuery<Long> query) {

    Assert.notNull(query);//ww w.jav a2  s. c  om

    List<Long> totals = query.getResultList();
    Long total = 0L;

    for (Long element : totals) {
        total += element == null ? 0 : element;
    }

    return total;
}

From source file:au.org.ands.vocabs.toolkit.db.TaskUtils.java

/** Get all tasks.
 * @return A list of Tasks//from  w w  w.  ja  v  a2 s .c o m
 */
public static List<Task> getAllTasks() {
    EntityManager em = DBContext.getEntityManager();
    TypedQuery<Task> query = em.createNamedQuery(Task.GET_ALL_TASKS, Task.class);
    List<Task> tasks = query.getResultList();
    em.close();
    return tasks;
}

From source file:ar.edu.unlp.sedici.sedici2003.model.TesaurosTermino.java

/**
 * Genera el camino de terminos hasta llegar al antecesor del termino actual
 * @param separador//  w ww . j  a  va 2  s.  c om
 * @return
 */
public static String getCamino(TesaurosTermino entity, String separador) {
    String listaIDs = "'";
    String idTermino = entity.getId();

    // Armamos los IDs de los antecesores a partir del id del termino actual
    while (idTermino.contains(".")) {
        idTermino = idTermino.substring(0, idTermino.lastIndexOf("."));
        listaIDs += idTermino;
        if (idTermino.contains("."))
            listaIDs += "','";
    }
    listaIDs += "'";

    // Armamos la query
    String sqlAntecesores = "SELECT terminos FROM TesaurosTermino AS terminos " + "WHERE terminos.id IN ("
            + listaIDs + ") " + "ORDER BY terminos.id ASC";

    // Ejecutamos la query
    EntityManager em = TesaurosTermino.entityManager();
    TypedQuery<TesaurosTermino> q = em.createQuery(sqlAntecesores, TesaurosTermino.class);
    List<TesaurosTermino> antecesores = q.getResultList();

    // Procesamos los resultados y armamos el camino final
    String[] terminos = new String[antecesores.size()];
    for (int i = 0; i < antecesores.size(); i++) {
        terminos[i] = antecesores.get(i).getNombreEs();
    }
    return StringUtils.join(terminos, separador);
}

From source file:ar.edu.unlp.sedici.sedici2003.model.JerarquiasTermino.java

/**
 * Genera el camino de terminos hasta llegar al antecesor del termino actual
 * @param separador//w  ww  . j  a  va2s  .  c  om
 * @return
 */
public static String getCamino(JerarquiasTermino entity, String separador) {
    String listaIDs = "'";
    String idTermino = entity.getId();

    // Armamos los IDs de los antecesores a partir del id del termino actual
    while (idTermino.contains(".")) {
        idTermino = idTermino.substring(0, idTermino.lastIndexOf("."));
        listaIDs += idTermino;
        if (idTermino.contains("."))
            listaIDs += "','";
    }
    listaIDs += "'";

    // Armamos la query
    String sqlAntecesores = "SELECT terminos FROM JerarquiasTermino AS terminos " + "WHERE terminos.id IN ("
            + listaIDs + ") " + "ORDER BY terminos.id ASC";

    // Ejecutamos la query
    EntityManager em = JerarquiasTermino.entityManager();
    TypedQuery<JerarquiasTermino> q = em.createQuery(sqlAntecesores, JerarquiasTermino.class);
    List<JerarquiasTermino> antecesores = q.getResultList();

    // Procesamos los resultados y armamos el camino final
    String[] terminos = new String[antecesores.size()];
    for (int i = 0; i < antecesores.size(); i++) {
        terminos[i] = antecesores.get(i).getNombreEs();
    }
    return StringUtils.join(terminos, separador);
}

From source file:com.clustercontrol.platform.collect.QueryExecutor.java

public static <T> List<T> getListWithTimeout(String queryName, Class<T> resultClass,
        Map<String, Object> parameters) {
    setStatementTimeout();/*from  ww w . ja va 2s . c  o m*/
    HinemosEntityManager em = new JpaTransactionManager().getEntityManager();
    TypedQuery<T> query = em.createNamedQuery(queryName, resultClass);
    for (String key : parameters.keySet()) {
        query.setParameter(key, parameters.get(key));
    }
    List<T> list = query.getResultList();
    resetStatementTimeout();
    return list;
}

From source file:ar.edu.unlp.sedici.sedici2003.model.JerarquiasTermino.java

public static List<JerarquiasTermino> findAll(String text, String[] parents, boolean includeChilds,
        boolean includeSelf, int start, int count) {

    if (text == null || text.length() == 0)
        throw new IllegalArgumentException("The text argument is required");
    if (parents == null || parents.length == 0)
        throw new IllegalArgumentException("The parents argument is required");

    if (start < 0)
        start = 0;//from w  w  w. j  a va2s  .c o  m
    if (count <= 0)
        count = 10;

    // Armamos el filtro de descendencia
    String parentFilter = "(";
    if (includeChilds) {
        for (String parentID : parents) {
            if (!parentID.endsWith("."))
                parentID += ".";
            parentFilter += " terminos.id LIKE '" + parentID + "%' OR";
        }
    } else {
        for (String parentID : parents) {
            parentFilter += " relaciones.id.idTermino1 = '" + parentID + "' OR";
        }
    }

    if (includeSelf) {
        for (String parentID : parents) {
            if (parentID.endsWith("."))
                parentID = parentID.substring(0, parentID.length() - 1);

            parentFilter += " terminos.id LIKE '" + parentID + "' OR";
        }
    }

    //Sacamos el ultimo OR
    parentFilter = parentFilter.substring(0, parentFilter.length() - 2) + ")";

    String sql = "SELECT terminos " + "FROM JerarquiasTermino AS terminos, JerarquiasRelaciones AS relaciones "
            + "WHERE terminos.id = relaciones.id.idTermino2 AND relaciones.tipoRelacion = 1 "
            + "AND LOWER(terminos.nombreEs) LIKE LOWER(:filtro) AND " + parentFilter;

    //Agrego el orden
    sql = sql + " ORDER BY terminos.nombreEs ASC";

    //  System.out.println(sql);
    EntityManager em = JerarquiasTermino.entityManager();
    TypedQuery<JerarquiasTermino> q = em.createQuery(sql, JerarquiasTermino.class);
    q.setParameter("filtro", "%" + text + "%");
    q.setFirstResult(start);
    q.setMaxResults(count);

    return q.getResultList();
}

From source file:fr.univrouen.poste.domain.PosteAPourvoir.java

public static List<PosteAPourvoir> findPosteAPourvoirsByMembre(User membre) {
    if (membre == null)
        throw new IllegalArgumentException("The membre argument is required");
    TypedQuery<PosteAPourvoir> q = entityManager().createQuery(
            "SELECT o FROM PosteAPourvoir o WHERE :membre MEMBER OF o.membres ORDER BY o.numEmploi asc",
            PosteAPourvoir.class);
    q.setParameter("membre", membre);
    return q.getResultList();
}

From source file:fr.univrouen.poste.domain.PosteAPourvoir.java

public static List<PosteAPourvoir> findPosteAPourvoirsByNumEmplois(List<String> numEmplois) {
    if (numEmplois == null)
        throw new IllegalArgumentException("The numEmplois argument is required");
    TypedQuery<PosteAPourvoir> q = entityManager().createQuery(
            "SELECT o FROM PosteAPourvoir o WHERE o.numEmploi IN :numEmplois ORDER BY o.numEmploi asc",
            PosteAPourvoir.class);
    q.setParameter("numEmplois", numEmplois);
    return q.getResultList();
}