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:ext.msg.model.Message.java

public static Page<Message> queryMessageByRead(int page, int pageSize, String consumeOnly,
        Collection<?> msgTypes, boolean unReadFirst) {
    String countQL = " select count(m) from Message m where m.consumeOnly = :consumeOnly ";
    String contentQL = " from Message m where m.consumeOnly = :consumeOnly ";

    if (CollectionUtils.isNotEmpty(msgTypes)) {
        countQL += "  and m.msgType in (:msgTypes) ";
        contentQL += "  and m.msgType in (:msgTypes)  ";
    }/*ww w  . j av  a2 s . c  om*/

    if (unReadFirst) {
        contentQL += " order by isRead asc, m.id desc ";
    } else {
        contentQL += " order by m.id desc ";
    }

    TypedQuery<Long> countQuery = JPA.em().createQuery(countQL, Long.class).setParameter("consumeOnly",
            consumeOnly);
    TypedQuery<Message> contentQuery = JPA.em().createQuery(contentQL, Message.class)
            .setParameter("consumeOnly", consumeOnly);

    if (CollectionUtils.isNotEmpty(msgTypes)) {
        countQuery.setParameter("msgTypes", msgTypes);
        contentQuery.setParameter("msgTypes", msgTypes);
    }

    contentQuery.setFirstResult(page * pageSize).setMaxResults(pageSize);

    Long total = countQuery.getSingleResult();
    List<Message> data = contentQuery.getResultList();
    Page<Message> pageMsg = new Page<Message>(Constants.SUCESS, total, data);
    return pageMsg;
}

From source file:com.smhdemo.common.report.dao.ParameterDao.java

public Boolean findSessionIsEntityByParameterIdAndUserName(final Long parameterId, final String userName) {
    String hql = "Select p From Parameter As p Where p.id=:parameterId And p.defaultValue=:userName";

    TypedQuery<Parameter> query = this.getEntityManager().createQuery(hql, Parameter.class);
    query.setParameter("parameterId", parameterId);
    query.setParameter("userName", userName);

    List<Parameter> list = query.getResultList();
    return list.isEmpty() ? false : true;
}

From source file:com.smhdemo.common.report.dao.ChartDao.java

public List<Category> findCategoryReportByChartReportId(final Long chartReportId) {
    String hql = "Select c From Category As c Left Join c.chartReports As t Where t.id=:chartReportId";

    TypedQuery<Category> query = this.getEntityManager().createQuery(hql, Category.class);
    query.setParameter("chartReportId", chartReportId);

    return query.getResultList();
}

From source file:com.smhdemo.common.report.dao.TextDao.java

public List<Category> findCategoryReportByTextReportId(final Long textReportId) {
    String hql = "Select c From Category As c Left Join c.textReports As t Where t.id=:textReportId";

    TypedQuery<Category> query = this.getEntityManager().createQuery(hql, Category.class);
    query.setParameter("textReportId", textReportId);

    return query.getResultList();
}

From source file:com.sshdemo.common.schedule.manage.dao.JobClassDAO.java

public JobClass findByJobClassByClassEntity(final String classEntity) {
    String hql = "From JobClass o Where o.classEntity=:classEntity";

    TypedQuery<JobClass> query = this.getEntityManager().createQuery(hql, JobClass.class);
    query.setParameter("classEntity", classEntity);

    JobClass jobClass = null;/*from  w ww .java  2s . c  o  m*/
    try {
        jobClass = (JobClass) query.getSingleResult();
    } catch (NoResultException e) {
    }

    return jobClass;
}

From source file:com.smhdemo.common.report.dao.CategoryDao.java

public Boolean findTextIsEntityByTextAndCategory(final Long textReportId, final Long categoryReportId) {
    String hql = "Select c From Category As c Left Join c.texts As t Where t.id=:textReportId And c.id=:categoryReportId";

    TypedQuery<Category> query = this.getEntityManager().createQuery(hql, Category.class);
    query.setParameter("textReportId", textReportId);
    query.setParameter("categoryReportId", categoryReportId);

    List<Category> list = query.getResultList();
    return list.isEmpty() ? false : true;
}

From source file:com.smhdemo.common.report.dao.CategoryDao.java

public Boolean findChartIsEntityByChartAndCategory(final Long chartReportId, final Long categoryReportId) {
    String hql = "Select c From Category As c Left Join c.charts As t Where t.id=:chartReportId And c.id=:categoryReportId";

    TypedQuery<Category> query = this.getEntityManager().createQuery(hql, Category.class);
    query.setParameter("chartReportId", chartReportId);
    query.setParameter("categoryReportId", categoryReportId);

    List<Category> list = query.getResultList();
    return list.isEmpty() ? false : true;
}

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

public List<Programa> findByAlunoId(Long alunoId) throws BusinessException {
    StringBuilder hql = new StringBuilder();

    hql.append("SELECT ");
    hql.append(" p ");
    hql.append("FROM ");
    hql.append("  Programa p ");
    hql.append("  JOIN p.aluno a ");
    hql.append("WHERE ");
    hql.append("  a.id = :alunoId ");
    hql.append("ORDER BY ");
    hql.append("  p.dataInicio DESC");

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

    List<Programa> result = query.getResultList();

    return result;
}

From source file:com.sshdemo.common.report.manage.dao.ChartReportDAO.java

public List<CategoryReport> findCategoryReportByChartReportId(final Long chartReportId) {
    String hql = "Select c From CategoryReport As c Left Join c.charts As t Where t.id=:chartReportId";

    TypedQuery<CategoryReport> query = this.getEntityManager().createQuery(hql, CategoryReport.class);
    query.setParameter("chartReportId", chartReportId);

    return query.getResultList();
}

From source file:com.sshdemo.common.report.manage.dao.ChartReportDAO.java

public List<EwcmsJobReport> findEwcmsJobReportByChartReportId(final Long chartReportId) {
    String hql = "Select e From EwcmsJobReport As e Where e.chartReport.id=:chartReportId";

    TypedQuery<EwcmsJobReport> query = this.getEntityManager().createQuery(hql, EwcmsJobReport.class);
    query.setParameter("chartReportId", chartReportId);

    return query.getResultList();
}