Example usage for javax.persistence TypedQuery setParameter

List of usage examples for javax.persistence TypedQuery setParameter

Introduction

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

Prototype

TypedQuery<X> setParameter(int position, Object value);

Source Link

Document

Bind an argument value to a positional parameter.

Usage

From source file:com.ewcms.content.particular.dao.FrontProjectArticleDAO.java

public List<ProjectArticle> findProjectArticleBySector(Long organId) {
    String hql = "From ProjectArticle As p where p.organ.id=:organId and p.release=true Order By p.published desc ";
    TypedQuery<ProjectArticle> query = this.getEntityManager().createQuery(hql, ProjectArticle.class);
    query.setParameter("organId", Integer.valueOf(organId.toString()));
    return query.getResultList();
}

From source file:com.ewcms.content.particular.dao.FrontProjectArticleDAO.java

public List<ProjectArticle> findProjectArticleByCode(String code) {
    String hql = "From ProjectArticle As p where p.projectBasic.code=:code and p.release=true Order By p.published desc ";
    TypedQuery<ProjectArticle> query = this.getEntityManager().createQuery(hql, ProjectArticle.class);
    query.setParameter("code", code);
    return query.getResultList();
}

From source file:csns.model.academics.dao.jpa.ProjectDaoImpl.java

@Override
public List<Project> searchProjects(String term, int maxResults) {
    TypedQuery<Project> query = entityManager.createNamedQuery("project.search", Project.class);
    if (maxResults > 0)
        query.setMaxResults(maxResults);
    return query.setParameter("term", term).getResultList();
}

From source file:org.mitre.oauth2.repository.impl.JpaOAuth2ClientRepository.java

@Override
public ClientDetailsEntity getClientByClientId(String clientId) {
    TypedQuery<ClientDetailsEntity> query = manager.createNamedQuery(ClientDetailsEntity.QUERY_BY_CLIENT_ID,
            ClientDetailsEntity.class);
    query.setParameter(ClientDetailsEntity.PARAM_CLIENT_ID, clientId);
    return JpaUtil.getSingleResult(query.getResultList());
}

From source file:com.ewcms.content.particular.dao.FrontProjectArticleDAO.java

public List<ProjectArticle> findProjectChannellArticleLimit(Integer channelId, Integer number) {
    String hql = "From ProjectArticle As p where p.channelId=:channelId and p.release=true Order By p.published desc limit "
            + number;//from   ww w. j  a v  a  2s  . com
    TypedQuery<ProjectArticle> query = this.getEntityManager().createQuery(hql, ProjectArticle.class);
    query.setParameter("channelId", channelId);
    return query.getResultList();
}

From source file:com.pingdu.dao.licenseDao.LicenseDao.java

public License getLicenseInfo(int entCode, int licenseCode) {
    String jpql = "select l from License l where l.licenseCode=:licenseCode ANDl.entCode=:entCode";
    TypedQuery<License> query = em().createQuery(jpql, License.class);
    query.setParameter("licenseCode", licenseCode);
    query.setParameter("entCode", entCode);
    List<License> licenses = query.getResultList();
    if (licenses.size() == 1) {
        return licenses.get(0);
    } else {/*ww  w  . j a va2  s .  c o m*/
        System.out.println("????");
        System.out.println("????");
        System.out.println("????");
        System.out.println("????");
        System.out.println("????");
        System.out.println("????");
        System.out.println("????");
    }
    License license = new License();
    return license;
}

From source file:br.eti.danielcamargo.backend.hsnpts.core.business.MicrocicloService.java

/**
 * Se o microciclo existir e for incompleto, ele  retornado.
 * <br />//from  www. ja  v  a  2 s . c  o m
 * Se o microciclo no existir ou estiver completo, cria um novo.
 *
 * @param alunoId
 * @return
 * @throws
 * br.eti.danielcamargo.backend.hsnpts.core.business.exceptions.ProgramaFinalizadoException
 */
@Transactional
public Microciclo resolverMicrociclo(Long alunoId) throws ProgramaFinalizadoException {

    StringBuilder hql = new StringBuilder();

    hql.append("SELECT ");
    hql.append(" p ");
    hql.append("FROM ");
    hql.append("  Programa p ");
    hql.append("WHERE ");
    hql.append("  p.aluno.id = :alunoId ");
    hql.append("  AND p.dataTermino IS NULL ");

    TypedQuery<Programa> queryPrograma = em.createQuery(hql.toString(), Programa.class);
    queryPrograma.setParameter("alunoId", alunoId);
    Programa programa = queryPrograma.getSingleResult();

    hql.append("SELECT ");
    hql.append(" m ");
    hql.append("FROM ");
    hql.append(" Microciclo m ");
    hql.append("WHERE ");
    hql.append(" m.programa = :programa ");
    hql.append("ORDER BY ");
    hql.append(" m.numero DESC ");

    TypedQuery<Microciclo> queryMicrociclo = em.createQuery(hql.toString(), Microciclo.class);
    queryMicrociclo.setParameter("programa", programa);
    queryMicrociclo.setMaxResults(1);

    List<Microciclo> result = queryMicrociclo.getResultList();

    HsnPersonal hsnPersonal = HsnPersonalUtils.getInstance();
    ObjetivoPrograma objetivoPrograma = programa.getObjetivoPrograma();
    FrequenciaSemanal frequenciaSemanal = programa.getFrequenciaSemanal();

    if (result.isEmpty()) {
        //criar primeiro microciclo
        Microciclo microciclo = hsnPersonal.buscarMicrociclo(objetivoPrograma, frequenciaSemanal, 1);
        microciclo.setPrograma(programa);
        save(microciclo);
        return microciclo;
    } else {
        //verificar se o programa esta finalizado
        Microciclo microciclo = result.get(0);
        if (microciclo.getDataTermino() != null) {
            if (microciclo.getNumero().equals(24)) {
                throw new ProgramaFinalizadoException();
            }
            microciclo = hsnPersonal.buscarMicrociclo(objetivoPrograma, frequenciaSemanal, 1);
            microciclo.setPrograma(programa);
            save(microciclo);
            return microciclo;
        }
        return microciclo;
    }
}

From source file:csns.model.forum.dao.jpa.ForumDaoImpl.java

@Override
public List<Forum> searchForums(String term, int maxResults) {
    TypedQuery<Forum> query = entityManager.createNamedQuery("forum.search", Forum.class);
    if (maxResults > 0)
        query.setMaxResults(maxResults);
    return query.setParameter("term", term).getResultList();
}

From source file:org.mitre.oauth2.repository.impl.JpaAuthorizationCodeRepository.java

@Override
@Transactional(value = "defaultTransactionManager")
public AuthorizationCodeEntity getByCode(String code) {
    TypedQuery<AuthorizationCodeEntity> query = manager.createNamedQuery(AuthorizationCodeEntity.QUERY_BY_VALUE,
            AuthorizationCodeEntity.class);
    query.setParameter("code", code);

    AuthorizationCodeEntity result = JpaUtil.getSingleResult(query.getResultList());
    return result;
}

From source file:org.openmeetings.app.data.user.dao.PrivateMessageFolderDaoImpl.java

public List<PrivateMessageFolder> getPrivateMessageFolderByUserId(Long userId) {
    try {//from w w  w.j  ava  2  s.  com
        String hql = "select c from PrivateMessageFolder c " + "where c.userId = :userId ";

        TypedQuery<PrivateMessageFolder> query = em.createQuery(hql, PrivateMessageFolder.class);
        query.setParameter("userId", userId);

        List<PrivateMessageFolder> privateMessageFolders = query.getResultList();

        return privateMessageFolders;
    } catch (Exception e) {
        log.error("[getPrivateMessageFolderByUserId]", e);
    }
    return null;
}