Example usage for javax.persistence Query setParameter

List of usage examples for javax.persistence Query setParameter

Introduction

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

Prototype

Query setParameter(int position, Object value);

Source Link

Document

Bind an argument value to a positional parameter.

Usage

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

private <T extends Task> TaskExec findLatest(final T task, final String field) {

    Query query = entityManager.createQuery("SELECT e " + "FROM " + TaskExec.class.getSimpleName() + " e "
            + "WHERE e.task=:task " + "ORDER BY e." + field + " DESC");
    query.setParameter("task", task);
    query.setMaxResults(1);/*  w ww.  j a v  a 2  s  .c om*/

    List<TaskExec> result = query.getResultList();
    return result == null || result.isEmpty() ? null : result.iterator().next();
}

From source file:com.solidmaps.webapp.dao.LicensePFDAO.java

/**
 * Obtem a Ultima licena cadastrada// w w w .  j av  a  2s .c om
 * 
 * @param idCompany
 * @return
 */
public LicensePFEntity findByLastProtocoled(Integer idCompany) {

    StringBuilder sb = new StringBuilder();
    sb.append("from LicensePFEntity e where e.company.idCompany =:idCompany ");
    sb.append("and e.isActive =:active ");
    sb.append("order by dateExpiration desc ");

    Query query = super.getEm().createQuery(sb.toString());

    query.setParameter("idCompany", idCompany);
    query.setParameter("active", Boolean.TRUE);

    @SuppressWarnings("unchecked")
    List<LicensePFEntity> list = query.getResultList();

    if (list != null && !list.isEmpty()) {
        return list.get(0);
    }

    return null;
}

From source file:com.solidmaps.webapp.dao.LicensePFDAO.java

/**
 * A licensa atual  a com Data de Expirao mais atual
 * //w  w w  . j  av  a2  s. c  om
 * @param idCompany
 * @return
 */
public LicensePFEntity findLastLicense(Integer idCompany) {

    StringBuilder sb = new StringBuilder();
    sb.append("from LicensePFEntity e where e.company.idCompany =:idCompany ");
    sb.append("and e.isActive =:active ");
    sb.append("order by dateExpiration desc ");

    Query query = super.getEm().createQuery(sb.toString());

    query.setParameter("idCompany", idCompany);
    query.setParameter("active", Boolean.TRUE);

    @SuppressWarnings("unchecked")
    List<LicensePFEntity> list = query.getResultList();

    if (list != null && !list.isEmpty()) {
        return list.get(0);
    }

    return null;
}

From source file:com.solidmaps.webapp.dao.LicensePFDAO.java

/**
 * Pesquisa se o Produto informado possui uma Licensa valida no Periodo
 * //ww  w  . j av a  2 s .co  m
 * @param idCompany
 * @param idProductOfficial
 * @return
 */
public ProductOfficialEntity findByProductOfficial(Integer idLicense, String codNcm) {

    StringBuilder sb = new StringBuilder();
    sb.append("select p ");
    sb.append("from LicensePFEntity e join e.listProducts p ");
    sb.append("where e.idLicense = :idLicense ");
    sb.append("and p.codNcm =:codNcm ");
    sb.append("order by e.dateExpiration "); // deve-se ordenar dessa forma

    Query query = super.getEm().createQuery(sb.toString());

    query.setParameter("codNcm", codNcm);
    query.setParameter("idLicense", idLicense);

    @SuppressWarnings("unchecked")
    List<ProductOfficialEntity> list = query.getResultList();

    if (list != null && !list.isEmpty()) {
        return list.get(0);
    }

    return null;
}

From source file:com.solidmaps.webapp.dao.LicensePFDAO.java

/**
 * Procura a licensa sem Considerar a Regra de Protocolo. 
 * Essa consulta eh usada na validao do cadsatro de Licenas.
 * /*from  w  w w  .ja v  a  2 s .c o m*/
 * @param idCompany
 * @param dateExpiration
 * @return
 */
public LicensePFEntity findByCompanyExpirationDateNoProtocol(Integer idCompany, Calendar dateExpiration) {

    StringBuilder sb = new StringBuilder();
    sb.append("from LicensePFEntity e where e.company.idCompany =:idCompany ");
    sb.append("and e.isActive =:active ");
    sb.append("and e.dateExpiration >= :dateExpiration ");
    sb.append("order by dateExpiration ");

    Query query = super.getEm().createQuery(sb.toString());

    query.setParameter("idCompany", idCompany);
    query.setParameter("dateExpiration", dateExpiration);
    query.setParameter("active", Boolean.TRUE);

    @SuppressWarnings("unchecked")
    List<LicensePFEntity> list = query.getResultList();

    if (list != null && !list.isEmpty()) {
        return list.get(0);
    }

    return null;
}