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.com.siam.dao.UsuarioDAOHibernate.java

License:Creative Commons License

public Usuario buscarPorLogin(String login) {
    String hql = "select u from Usuario u where u.login = :login";
    Query consulta = this.session.createQuery(hql);
    consulta.setString("login", login);

    //TODO mostrar primeiramente com o list e depois apresentar o uniqueResult
    return (Usuario) consulta.uniqueResult();
}

From source file:br.com.sicva.dao.BairroDao.java

public Bairro PesquisarPorNome(String nome) {
    try {/*www  .  ja va2s .  c om*/
        session = new FabricaDeConexao().getSessionFactory().openSession();
        Query query = session.createSQLQuery("select * from bairro where BAIRRO_NOME = :nome")
                .addEntity(Bairro.class);
        query.setString("nome", nome);
        listaBairro = query.list();
        session.close();
        if (listaBairro.isEmpty()) {
            return null;
        } else {
            return listaBairro.get(0);
        }
    } catch (Exception e) {
        System.out.println("" + e.getCause().getMessage());
        return null;
    }
}

From source file:br.com.sicva.dao.EnfermeiroDao.java

public Enfermeiro PesquisarEnfermeiro(String coren) {
    try {/*from  ww  w.  j  av  a  2 s  .co m*/
        session = new FabricaDeConexao().getSessionFactory().openSession();
        Query query = session.createSQLQuery("select * from enfermeiro where ENFERMEIRO_COREN = :coren")
                .addEntity(Enfermeiro.class);
        query.setString("coren", coren);
        listarEnfermeiro = query.list();
        session.close();
        if (listarEnfermeiro.isEmpty()) {
            return null;
        } else {
            return listarEnfermeiro.get(0);
        }
    } catch (Exception e) {
        System.out.println("" + e.getCause().getMessage());
        return null;
    }
}

From source file:br.com.sicva.dao.FuncaoDao.java

public Funcao PesquisarPorDescricao(String descricao) {
    try {//from  ww w  .ja v  a 2  s .co  m
        session = new HibernateUtil().getSessionFactory().openSession();
        Query query = session.createSQLQuery("select * from funcao where funcao_descricao = :descricao")
                .addEntity(Funcao.class);
        query.setString("descricao", descricao);
        listarFuncao = query.list();
        session.close();
        return listarFuncao.get(0);
    } catch (Exception e) {
        return null;
    }
}

From source file:br.com.sicva.dao.PacienteDao.java

public Paciente PesquisarPaciente(String cpf) {
    try {/*from   w w  w.  j a  va 2 s  .co  m*/
        session = new FabricaDeConexao().getSessionFactory().openSession();
        Query query = session.createSQLQuery("select * from paciente where PAC_CPF = :cpf")
                .addEntity(Paciente.class);
        query.setString("cpf", cpf);
        listarPaciente = query.list();
        session.close();
        if (listarPaciente.isEmpty()) {
            return null;
        } else {
            return listarPaciente.get(0);
        }
    } catch (Exception e) {
        System.out.println("" + e.getCause().getMessage());
        return null;
    }
}

From source file:br.com.sicva.dao.UsuarioDao.java

public Usuario PesquisarUsuario(String cpf) {
    try {//from  ww  w  . j  a va2  s. co m
        session = new FabricaDeConexao().getSessionFactory().openSession();
        Query query = session.createSQLQuery("select * from usuario where USUARIO_CPF = :cpf")
                .addEntity(Usuario.class);
        query.setString("cpf", cpf);
        listarUsuario = query.list();
        session.close();
        if (listarUsuario.isEmpty()) {
            return null;
        } else {
            return listarUsuario.get(0);
        }
    } catch (Exception e) {
        System.out.println("" + e.getCause().getMessage());
        return null;
    }
}

From source file:br.com.sicva.dao.UsuarioDao.java

public Usuario PesquisarPorEnfermeiro(String coren) {
    try {// ww  w.j av  a 2 s.co  m
        session = new FabricaDeConexao().getSessionFactory().openSession();
        Query query = session
                .createSQLQuery("select * from usuario inner join enfermeiro\n"
                        + "on USUARIO_ENFERMEIRO = ENFERMEIRO_COREN " + "where ENFERMEIRO_COREN = :coren")
                .addEntity(Usuario.class);
        query.setString("coren", coren);
        listarUsuario = query.list();
        session.close();
        if (listarUsuario.isEmpty()) {
            return null;
        } else {
            return listarUsuario.get(0);
        }
    } catch (Exception e) {
        System.out.println("" + e.getCause().getMessage());
        return null;
    }
}

From source file:br.com.sicva.dao.UsuariosDao.java

public Usuarios PesquisarUsuario(String cpf) {
    try {/* w w w  .j  a va  2s.  com*/
        session = new HibernateUtil().getSessionFactory().openSession();
        Query query = session.createSQLQuery("select * from usuarios where USUARIOS_CPF = :cpf")
                .addEntity(Usuarios.class);
        query.setString("cpf", cpf);
        listarUsuarios = query.list();
        for (Usuarios u : listarUsuarios) {
            Hibernate.initialize(u.getFuncao());
        }
        session.close();
        if (listarUsuarios.isEmpty()) {
            return null;
        } else {
            return listarUsuarios.get(0);
        }
    } catch (Exception e) {
        System.out.println("" + e.getCause().getMessage());
        return null;
    }

}

From source file:br.com.sicva.dao.VacinacaoDao.java

public List<Vacinacao> buscarVacinacao(String cpf) {
    session = new FabricaDeConexao().getSessionFactory().openSession();
    Query query = session
            .createSQLQuery("select*from vacinacao\n" + "inner join vacina on vacina_id = vacinacao_vacina_id\n"
                    + "inner join paciente on PAC_ID = VACINACAO_PAC_ID "
                    + "left join enfermeiro on VACINACAO_ENFERM_COREN = ENFERMEIRO_COREN "
                    + "where PAC_CPF = :cpf \n" + "order by VACINACAO_ID")
            .addEntity(Vacinacao.class);
    query.setString("cpf", cpf);
    listaVacinacao = query.list();/*from w  w w  .  j a  v  a 2 s  .  c o m*/
    for (Vacinacao vaci : listaVacinacao) {
        Hibernate.initialize(vaci.getEnfermeiro());
        Hibernate.initialize(vaci.getVacina());
        Hibernate.initialize(vaci.getUbs());
        Hibernate.initialize(vaci.getPaciente());
    }
    session.close();
    if (listaVacinacao.isEmpty()) {
        return null;
    } else {
        return listaVacinacao;
    }
}

From source file:br.com.sicva.dao.VacinaDao.java

public Vacina consultarPorNome(String nome) {
    session = new FabricaDeConexao().getSessionFactory().openSession();
    Query query = session.createSQLQuery("SELECT * FROM vacina" + " WHERE vacina_nome = :nome")
            .addEntity(Vacina.class);
    query.setString("nome", nome);
    listaVacina = query.list();/*from ww  w. j  av  a 2 s . c  o m*/
    session.close();
    if (listaVacina.isEmpty()) {
        return null;
    } else {
        return listaVacina.get(0);
    }
}