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:ar.edu.unlp.sedici.sedici2003.model.TesaurosTermino.java

public static List<TesaurosTermino> findAll(String text, String[] parents, boolean includeChilds, 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;/* w  ww. j  a v a  2 s.c o  m*/
    if (count <= 0)
        count = 60;

    // 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";
        }
    }

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

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

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

    EntityManager em = TesaurosTermino.entityManager();
    TypedQuery<TesaurosTermino> q = em.createQuery(sql, TesaurosTermino.class);
    if (text != null || text.length() != 0) {
        q.setParameter("filtro", "%" + text.trim() + "%");

    }
    q.setFirstResult(start);
    q.setMaxResults(count);

    return q.getResultList();
}

From source file:com.clustercontrol.infra.util.QueryUtil.java

public static List<InfraCheckResult> getInfraCheckResultFindByManagementId(String managementId) {
    HinemosEntityManager em = new JpaTransactionManager().getEntityManager();
    TypedQuery<InfraCheckResult> query = em.createNamedQuery("InfraCheckResultEntity.findByManagementId",
            InfraCheckResult.class);
    query.setParameter("managementId", managementId);
    List<InfraCheckResult> list = query.getResultList();
    return list;//  www .  j a  v a2  s  .c o  m
}

From source file:com.clustercontrol.infra.util.QueryUtil.java

public static boolean isInfraFileReferredByFileTransferModuleInfoEntity(String fileId) {
    HinemosEntityManager em = new JpaTransactionManager().getEntityManager();
    TypedQuery<FileTransferModuleInfo> query = em.createNamedQuery("FileTransferModuleInfoEntity.findByFileId",
            FileTransferModuleInfo.class);
    query.setParameter("fileId", fileId);
    query.setMaxResults(1);/*w ww  .  ja  v  a 2 s . c  o m*/
    return !query.getResultList().isEmpty();
}

From source file:net.triptech.metahive.model.SubmittedField.java

/**
 * Find the submitted fields for the supplied parameters.
 *
 * @param def the def/*from   w w  w. ja va  2s.  c o  m*/
 * @param primaryId the primary id
 * @param secondaryId the secondary id
 * @param tertiaryId the tertiary id
 * @return the list
 */
public static List<SubmittedField> findSubmittedFields(final Definition def, final String primaryId,
        final String secondaryId, final String tertiaryId) {

    if (def == null) {
        throw new IllegalArgumentException("A valid defintion is required");
    }
    if (StringUtils.isBlank(primaryId)) {
        throw new IllegalArgumentException("The primaryId argument is required");
    }

    Map<String, Object> variables = new HashMap<String, Object>();

    StringBuilder sql = new StringBuilder();
    sql.append("SELECT s FROM SubmittedField AS s JOIN s.definition d");
    sql.append(" JOIN s.submission sub WHERE d.id = :definitionId");
    variables.put("definitionId", def.getId());

    sql.append(" AND LOWER(s.primaryRecordId) = LOWER(:primaryRecordId)");
    variables.put("primaryRecordId", primaryId);

    if (def.getApplicability() == Applicability.RECORD_SECONDARY) {
        if (StringUtils.isNotBlank(secondaryId)) {
            sql.append(" AND LOWER(s.secondaryRecordId) = LOWER(:secondaryRecordId)");
            variables.put("secondaryRecordId", secondaryId);
        } else {
            sql.append(" AND (s.secondaryRecordId IS NULL");
            sql.append(" OR s.secondaryRecordId = '')");
        }
    }
    if (def.getApplicability() == Applicability.RECORD_TERTIARY) {
        if (StringUtils.isNotBlank(tertiaryId)) {
            sql.append(" AND LOWER(s.tertiaryRecordId) = LOWER(:tertiaryRecordId)");
            variables.put("tertiaryRecordId", tertiaryId);
        } else {
            sql.append(" AND (s.tertiaryRecordId IS NULL");
            sql.append(" OR s.tertiaryRecordId = '')");
        }
    }
    sql.append(" ORDER BY sub.created");

    TypedQuery<SubmittedField> q = entityManager().createQuery(sql.toString(), SubmittedField.class);
    for (String key : variables.keySet()) {
        q.setParameter(key, variables.get(key));
    }
    return q.getResultList();
}

From source file:com.clustercontrol.infra.util.QueryUtil.java

public static List<InfraCheckResult> getInfraCheckResultFindByModuleId(String managementId, String moduleId) {
    HinemosEntityManager em = new JpaTransactionManager().getEntityManager();
    TypedQuery<InfraCheckResult> query = em.createNamedQuery("InfraCheckResultEntity.findByModuleId",
            InfraCheckResult.class);
    query.setParameter("managementId", managementId);
    query.setParameter("moduleId", moduleId);
    List<InfraCheckResult> list = query.getResultList();
    return list;//  w  w  w  . j ava 2  s  .  c  om
}

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

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

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

public static List<Personas> findPersonasesByApellidoYNombre(String apellido, String nombre, int start,
        int count) {
    if (apellido == null || apellido.length() == 0)
        apellido = "";
    if (nombre == null)
        nombre = "";
    if (start < 0)
        start = 0;/*from  w  w w . j a  v  a 2  s  .c o m*/
    if (count <= 0)
        count = 20;

    apellido = Personas.convertirParaQuery(apellido);
    nombre = Personas.convertirParaQuery(nombre);

    String where = Personas.generateCondition(apellido, nombre);

    EntityManager em = Personas.entityManager();
    TypedQuery<Personas> q = em.createQuery(
            "SELECT o FROM Personas AS o " + where + " ORDER BY o.apellido, o.nombre ASC", Personas.class);
    if (apellido.length() != 0)
        q.setParameter("apellido", apellido);
    if (nombre.length() != 0)
        q.setParameter("nombre", nombre);
    q.setFirstResult(start);
    q.setMaxResults(count);
    return q.getResultList();

}

From source file:org.kew.rmf.matchconf.Configuration.java

public static List<Configuration> findAllDedupConfigs() {
    EntityManager em = Configuration.entityManager();
    TypedQuery<Configuration> q = em.createQuery(
            "SELECT o FROM Configuration AS o WHERE o.authorityFileName = :authorityFileName",
            Configuration.class);
    q.setParameter("authorityFileName", "");
    return q.getResultList();
}

From source file:org.kew.rmf.matchconf.Configuration.java

public static List<Configuration> findAllMatchConfigs() {
    EntityManager em = Configuration.entityManager();
    TypedQuery<Configuration> q = em.createQuery(
            "SELECT o FROM Configuration AS o WHERE o.authorityFileName != :authorityFileName",
            Configuration.class);
    q.setParameter("authorityFileName", "");
    return q.getResultList();
}

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

/** Get all access points.
 * @return A list of AccessPoints//from   w ww  .j  a  va2 s  .c o  m
 */
public static List<AccessPoint> getAllAccessPoints() {
    EntityManager em = DBContext.getEntityManager();
    TypedQuery<AccessPoint> query = em.createNamedQuery(AccessPoint.GET_ALL_ACCESSPOINTS, AccessPoint.class);
    List<AccessPoint> aps = query.getResultList();
    em.close();
    return aps;
}