Example usage for org.hibernate Query setString

List of usage examples for org.hibernate Query setString

Introduction

In this page you can find the example usage for org.hibernate Query setString.

Prototype

@Deprecated
@SuppressWarnings("unchecked")
default Query<R> setString(String name, String val) 

Source Link

Document

Bind a named String-valued parameter.

Usage

From source file:br.ufg.reqweb.dao.ReportDao.java

@Transactional(readOnly = true)
public List<Map<String, ?>> listDocumentoDeEstagioMap(Curso curso) {
    Query query = this.sessionFactory.getCurrentSession().createSQLQuery(
            "select dis.nome as discente, dis.matricula, doc.email, doc.nome as docente, i.tipodedocumento, c.nome as curso\n"
                    + "from requerimento r\n" + "join itemrequerimento i on i.requerimento_id=r.id\n"
                    + "join usuario dis on r.usuario_id=dis.id\n"
                    + "join perfil p_dis on p_dis.usuario_id=dis.id\n" + "join curso c on p_dis.curso_id=c.id\n"
                    + "join perfil p_doc on p_doc.curso_id=p_dis.curso_id and p_doc.tipoperfil = :tipoPerfil\n"
                    + "join usuario doc on p_doc.usuario_id=doc.id\n"
                    + "where r.tiporequerimento = :tipoRequerimento and c.id = :cursoId and r.status = :status");
    query.setString("tipoRequerimento", TipoRequerimentoEnum.DOCUMENTO_DE_ESTAGIO.name());
    query.setString("tipoPerfil", PerfilEnum.COORDENADOR_DE_ESTAGIO.name());
    query.setLong("cursoId", curso.getId());
    query.setString("status", RequerimentoStatusEnum.EM_ANDAMENTO.name());
    query.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
    return query.list();
}

From source file:br.ufg.reqweb.dao.ReportDao.java

@Transactional(readOnly = true)
public List<Map<String, ?>> listDocumentoDeEstagioMap(RequerimentoStatusEnum status) {
    Query query = this.sessionFactory.getCurrentSession().createSQLQuery(
            "select dis.nome as discente, dis.matricula, doc.email, doc.nome as docente, i.tipodedocumento, c.nome as curso\n"
                    + "from requerimento r\n" + "join itemrequerimento i on i.requerimento_id=r.id\n"
                    + "join usuario dis on r.usuario_id=dis.id\n"
                    + "join perfil p_dis on p_dis.usuario_id=dis.id\n" + "join curso c on p_dis.curso_id=c.id\n"
                    + "join perfil p_doc on p_doc.curso_id=p_dis.curso_id and p_doc.tipoperfil=:tipoPerfil\n"
                    + "join usuario doc on p_doc.usuario_id=doc.id\n"
                    + "where r.tiporequerimento = :tipoRequerimento and r.status = :status");
    query.setString("tipoRequerimento", TipoRequerimentoEnum.DOCUMENTO_DE_ESTAGIO.name());
    query.setString("tipoPerfil", PerfilEnum.COORDENADOR_DE_ESTAGIO.name());
    query.setString("status", status.name());
    query.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
    return query.list();
}

From source file:br.ufg.reqweb.dao.ReportDao.java

@Transactional(readOnly = true)
public List<Map<String, ?>> listSegundaChamadaDeProvaMap(RequerimentoStatusEnum status, Curso curso) {
    Query query = this.sessionFactory.getCurrentSession().createSQLQuery(
            "select dis.nome as discente, dis.matricula, doc.nome as docente, doc.email, d.nome as disciplina, t.nome as turma, c.nome as curso, i.dataprovaa as data_prova, r.datacriacao as data_requerimento\n"
                    + "from requerimento r\n" + "join itemrequerimento i on i.requerimento_id=r.id\n"
                    + "join turma t on i.turma_id=t.id\n" + "join disciplina d on t.disciplina_id=d.id\n"
                    + "join usuario dis on r.usuario_id=dis.id\n" + "join perfil p on p.usuario_id=dis.id\n"
                    + "join curso c on p.curso_id=c.id\n" + "join usuario doc on t.docente_id=doc.id\n"
                    + "where r.tiporequerimento = :tipoRequerimento and r.status = :status\n"
                    + (curso == null ? "" : "and c.id = :cursoId"));
    if (curso != null) {
        query.setLong("cursoId", curso.getId());
    }//from   ww w. ja va  2  s  .co  m
    query.setString("tipoRequerimento", TipoRequerimentoEnum.SEGUNDA_CHAMADA_DE_PROVA.name());
    query.setString("status", status.name());
    query.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
    return query.list();
}

From source file:br.ufg.reqweb.dao.ReportDao.java

@Transactional(readOnly = true)
public List<Map<String, ?>> listSegundaChamadaDeProvaMap(RequerimentoStatusEnum status, Usuario usuario) {
    Query query = this.sessionFactory.getCurrentSession().createSQLQuery(
            "select dis.nome as discente, dis.matricula, doc.nome as docente, doc.email, d.nome as disciplina, t.nome as turma, c.nome as curso, i.dataprovaa as data_prova, r.datacriacao as data_requerimento\n"
                    + "from requerimento r\n" + "join itemrequerimento i on i.requerimento_id=r.id\n"
                    + "join turma t on i.turma_id=t.id\n" + "join disciplina d on t.disciplina_id=d.id\n"
                    + "join usuario dis on r.usuario_id=dis.id\n" + "join perfil p on p.usuario_id=dis.id\n"
                    + "join curso c on p.curso_id=c.id\n" + "join usuario doc on t.docente_id=doc.id\n"
                    + "where r.tiporequerimento = :tipoRequerimento and doc.id = :usuarioId and r.status = :status");
    query.setString("tipoRequerimento", TipoRequerimentoEnum.SEGUNDA_CHAMADA_DE_PROVA.name());
    query.setString("status", status.name());
    query.setLong("usuarioId", usuario.getId());
    query.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
    return query.list();
}

From source file:br.ufg.reqweb.dao.ReportDao.java

@Transactional(readOnly = true)
public List<Map<String, ?>> listRequerimentoByStatusMap(RequerimentoStatusEnum status) {
    Query query = this.sessionFactory.getCurrentSession()
            .createSQLQuery("select u.email, r.tiporequerimento as requerimento, r.status from requerimento r\n"
                    + "join usuario u on u.id=r.usuario_id\n" + "where status = :status");
    query.setString("status", status.name());
    query.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
    return query.list();
}

From source file:br.ufg.reqweb.dao.ReportDao.java

@Transactional(readOnly = true)
public List<Map<String, ?>> listUsuarioMap(PerfilEnum tipoPerfil, Curso curso) {
    Query query = this.sessionFactory.getCurrentSession()
            .createSQLQuery("select u.matricula, u.nome, c.nome as curso, u.email, p.tipoperfil\n"
                    + "from usuario u\n" + "join perfil p on p.usuario_id=u.id\n"
                    + "full outer join curso c on p.curso_id=c.id\n" + "where p.tipoperfil = :tipoPerfil\n"
                    + (curso == null ? "" : "and c.id = :cursoId\n") + "order by c.nome asc, u.nome asc;");
    if (curso != null) {
        query.setLong("cursoId", curso.getId());
    }/*  w w  w  . j ava2s .  co  m*/
    query.setString("tipoPerfil", tipoPerfil.name());
    query.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
    return query.list();
}

From source file:ca.myewb.controllers.home.Search.java

License:Open Source License

private List matchingSearchables(HashMap<String, String> terms, int pageStart, int pagesize) {
    String sql = "select parentPost, parentEvent, parentWhiteboard " + getCommonQueryPart(terms)
            + " limit :start, :limit";

    Query query = hibernateSession.createSQLQuery(sql).addScalar("parentPost", Hibernate.INTEGER)
            .addScalar("parentEvent", Hibernate.INTEGER).addScalar("parentWhiteboard", Hibernate.INTEGER)
            .setString("terms", terms.get("Body")).setInteger("start", pageStart).setInteger("limit", pagesize);

    if (!terms.get("Since").equals(""))
        query.setString("since", terms.get("Since"));

    List searchableIDs = query.list();

    Vector<Object> searchables = new Vector<Object>();
    for (Object temp : searchableIDs) {
        Object[] idArray = (Object[]) temp;
        Integer parentPostId = (Integer) idArray[0];
        Integer parentEventId = (Integer) idArray[1];
        Integer parentWhiteboardId = (Integer) idArray[2];
        if (parentPostId != null) {
            searchables.add(hibernateSession.load(PostModel.class, parentPostId));
        } else if (parentEventId != null) {
            searchables.add(hibernateSession.load(EventModel.class, parentEventId));
        } else if (parentWhiteboardId != null) {
            searchables.add(hibernateSession.load(WhiteboardModel.class, parentWhiteboardId));
        }//from  w w  w.  j  ava 2s  .c om
    }

    return searchables;
}

From source file:ca.myewb.controllers.home.Search.java

License:Open Source License

private int numMatchingSearchables(HashMap<String, String> terms) {
    String sql = "select count(*) " + getCommonQueryPart(terms);

    Query query = hibernateSession.createSQLQuery(sql).setString("terms", terms.get("Body"));

    if (!terms.get("Since").equals(""))
        query.setString("since", terms.get("Since"));

    return ((BigInteger) query.uniqueResult()).intValue();
}

From source file:cd_modelos_dao.EmpleadosDAO.java

public void eliminarEmpleado(String cedula) {
    List<Empleados> lista = new LinkedList<>();
    SessionFactory sf = HibernateUtil.getSessionFactory();
    Session s = sf.openSession();/*from   www .  j a  va 2 s.  c o m*/
    Query q = s.createQuery("delete from Empleados where cedula = :cedula");
    q.setString("cedula", cedula);
    q.executeUpdate();
    s.close();

    //        SessionFactory sf = HibernateUtil.getSessionFactory();
    //        Session s = sf.openSession();
    //        Servicios ser = consultarServicioPorId(id);
    //        System.out.println("el servicio es " + ser.getNombre());
    //        System.out.println("el servicio es " + ser.getId());
    //        s.delete(ser);
    //        s.close();
}

From source file:cd_modelos_dao.ProveedoresDAO.java

public void eliminarproveedor(String cedula) {
    List<Proveedores> lista = new LinkedList<>();
    SessionFactory sf = HibernateUtil.getSessionFactory();
    Session s = sf.openSession();/*from  ww w . j a v a 2 s. c  om*/
    Query q = s.createQuery("delete from Proveedores where cedula = :cedula");
    q.setString("cedula", cedula);
    q.executeUpdate();
    s.close();

    //        SessionFactory sf = HibernateUtil.getSessionFactory();
    //        Session s = sf.openSession();
    //        Servicios ser = consultarServicioPorId(id);
    //        System.out.println("el servicio es " + ser.getNombre());
    //        System.out.println("el servicio es " + ser.getId());
    //        s.delete(ser);
    //        s.close();
}