Example usage for org.hibernate Query setParameter

List of usage examples for org.hibernate Query setParameter

Introduction

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

Prototype

@SuppressWarnings("unchecked")
Query<R> setParameter(int position, Object val);

Source Link

Document

Bind a positional query parameter using its inferred Type.

Usage

From source file:br.com.hslife.orcamento.repository.ModeloDocumentoRepository.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<ModeloDocumento> findDescricaoOrAtivoByUsuario(String descricao, Boolean ativo, Usuario usuario) {
    StringBuilder hql = new StringBuilder();
    hql.append("FROM ModeloDocumento modelo WHERE ");

    if (descricao != null && !descricao.isEmpty()) {
        hql.append("modelo.descricao LIKE '%");
        hql.append(descricao);//  ww  w . j av  a  2s .co m
        hql.append("%' AND ");
    }
    if (ativo != null) {
        hql.append("modelo.ativo = :ativo AND ");
    }

    hql.append("modelo.usuario.id = :idUsuario ORDER BY modelo.descricao ASC");

    Query hqlQuery = getQuery(hql.toString());

    if (ativo != null) {
        hqlQuery.setParameter("ativo", ativo);
    }

    hqlQuery.setParameter("idUsuario", usuario.getId());

    return hqlQuery.list();
}

From source file:br.com.hslife.orcamento.repository.RelatorioCustomizadoRepository.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<RelatorioCustomizado> findNomeByUsuario(String nome, Usuario usuario) {
    StringBuilder hql = new StringBuilder();
    hql.append("FROM RelatorioCustomizado relatorio WHERE ");
    if (nome != null && !nome.isEmpty()) {
        hql.append("relatorio.nome LIKE '%");
        hql.append(nome);//from  w  w  w  .ja  v a 2  s  .c  om
        hql.append("%' AND ");
    }

    hql.append("relatorio.usuario.id = :idUsuario ORDER BY relatorio.nome ASC");

    Query hqlQuery = getQuery(hql.toString());

    hqlQuery.setParameter("idUsuario", usuario.getId());

    return hqlQuery.list();
}

From source file:br.com.moises.suport.EmbarqueSuport.java

public List<Embarque> getEmbarquesAbertoByQuery() {
    Session s = Dao().getSession();/*from w  w  w.  jav  a  2 s  .  com*/
    Dao().begin(s);
    try {
        Query query = s.createQuery("SELECT E FROM Embarque E WHERE E.status =:STATUS");
        query.setParameter("status", StatusEmbarque.VAZIO);
        query.setParameter("status", StatusEmbarque.CARREGANDO);
        List<Embarque> embarques = query.list();
        embarques.size();
        return embarques;
    } catch (Exception e) {
        return null;
    } finally {
        Dao().commit(s);

    }

}

From source file:br.com.muranodesign.dao.impl.AlunoVariavelDAOImpl.java

License:Creative Commons License

public void update(int id, int grupo) {
    Query query = getSession().getNamedQuery("AlunoVariavel.UPDATE");

    query.setParameter("id", grupo);
    query.setParameter("idalunoVariavel", id);

    query.executeUpdate();/* w  w w .j  av a 2s  .  c o m*/
}

From source file:br.com.muranodesign.dao.impl.GrupoDAOImpl.java

License:Creative Commons License

public void update(int id, String nome, int lider) {
    Query query = getSession().getNamedQuery("Grupo.UPDATE");
    query.setParameter("nome", nome);
    query.setParameter("lider", lider);
    query.setParameter("idgrupo", id);

    query.executeUpdate();//  ww w  .java2s.  c om
}

From source file:br.com.muranodesign.dao.impl.UsuarioDAOImpl.java

License:Creative Commons License

public void updateUser(String senha, int id) {
    Query query = getSession().getNamedQuery("Usuario.UPDATE");
    query.setParameter("senha", senha);
    query.setParameter("idusuario", id);

    query.executeUpdate();//from   ww w .  j ava  2  s .  c  o m
}

From source file:br.com.proj.tasker.dao.impl.AtivMembrosDAO.java

@Override
public Integer buscaAut(Integer idGru, Integer idPes) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    Query query = session.createSQLQuery(
            "Select id_perfil From ativmembros WHERE id_membro = :idpes AND id_grupo = :idgrupo");
    query.setParameter("idpes", idPes);
    query.setParameter("idgrupo", idGru);
    Integer aut = (Integer) query.uniqueResult();
    session.close();//from   w  w  w .java2 s. c  o m
    return aut;
}

From source file:br.com.proj.tasker.dao.impl.AtivMembrosDAO.java

@Override
public Integer buscaCargo(Integer idGru, Integer idPes) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    Query query = session.createSQLQuery(
            "Select id_cargo From ativmembros WHERE id_membro = :idpes AND id_grupo = :idgrupo");
    query.setParameter("idpes", idPes);
    query.setParameter("idgrupo", idGru);
    Integer cargo = (Integer) query.uniqueResult();
    if (cargo == null) {
        cargo = 0;/* w w w .j  a v a2 s .c  o m*/
    }
    session.close();
    return cargo;
}

From source file:br.com.proj.tasker.dao.impl.CargoDAO.java

@Override
public List<Cargo> getCargoUser(Integer id, Integer id2) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    Query query = session.createQuery("from Cargo where id_admin = :id AND id_grupo = :id2");
    query.setParameter("id", id);
    query.setParameter("id2", id2);
    List<Cargo> cargos = query.list();
    return cargos;
}

From source file:br.com.proj.tasker.dao.impl.CargoDAO.java

@Override
public List<Cargo> buscaCargosGru(Integer id) {
    Session session = HibernateUtil.createSessionFactory().openSession();
    Query query = session.createQuery("from Cargo where id_grupo = :id");
    query.setParameter("id", id);
    List<Cargo> cargos = query.list();
    return cargos;
}