Example usage for org.hibernate Session getNamedQuery

List of usage examples for org.hibernate Session getNamedQuery

Introduction

In this page you can find the example usage for org.hibernate Session getNamedQuery.

Prototype

org.hibernate.Query getNamedQuery(String queryName);

Source Link

Document

Create a Query instance for the named query.

Usage

From source file:br.com.bibliotecasj.DAO.UsuarioDAO.java

@Override
public List<Usuario> listarTodos() {
    Session sessao = HibernateUtil.getSessionFactory().openSession();
    List<Usuario> usu = null;
    try {/*from   w w  w.j  av  a2 s  . c o  m*/
        sessao.beginTransaction();
        Query consulta = sessao.getNamedQuery("Usuario.listar");
        usu = consulta.list();
    } catch (RuntimeException ex) {
        sessao.getTransaction().commit();

    } finally {
        sessao.close();
    }
    return usu;
}

From source file:br.com.dasa.sqdasa.alvaro.SqDasaDaoLabor.java

public List<Informacao> infoSqDasaRemarcacao(List<Informacao> listInformacao, String strDbName) {

    Session session = null;
    Transaction tx;//  w w  w .  j a  v a 2s .  com

    try {
        session = SessionFactoriByDBName.getCurrentSession4FacesByDbName(strDbName);
        tx = session.beginTransaction();

        Query q = session.getNamedQuery("LogOsRemarcacao.RemarcacaoSqDasa");
        //            q.setString("dataInicio", dataInicial);
        //            q.setString("dataFinal", dataFinal);

        List result = q.list();
        tx.commit();

        if (result != null && !result.isEmpty()) {
            for (int i = 0; i < result.size(); i++) {

                Informacao remarcacao = new Informacao();
                Object[] tupla = (Object[]) result.get(i);
                if (tupla[0] != null) {
                    remarcacao.setRequisicao(((Integer) tupla[0]).toString());
                }
                remarcacao.setMotivo((String) tupla[1]);
                remarcacao.setDtEntrega((Date) tupla[2]);
                remarcacao.setNomeFuncionario((String) tupla[3]);
                remarcacao.setCpfFuncionario((String) tupla[4]);
                remarcacao.setNomeCliente((String) tupla[5]);
                if (tupla[6] != null) {
                    remarcacao.setDtNascimento((Date) tupla[6]);
                }
                remarcacao.setFato((String) tupla[7]);
                remarcacao.setTelefone((String) tupla[8]);
                remarcacao.setOrigemEmenda((String) tupla[9]);
                remarcacao.setLocal((String) tupla[10]);
                remarcacao.setTipoEmenda((String) tupla[11]);
                remarcacao.setCentroCusto((String) tupla[12]);
                remarcacao.setFatoNivel1((String) tupla[13]);
                remarcacao.setFatoNivel2((String) tupla[14]);
                remarcacao.setFatoNivel3((String) tupla[15]);
                remarcacao.setExame((String) tupla[17]);
                listInformacao.add(remarcacao);
            }
        }

    } finally {
        if (session != null && session.isOpen()) {
            session.close();
        }
    }

    return listInformacao;
}

From source file:br.com.dasa.sqdasa.alvaro.SqDasaDaoLabor.java

public List<Informacao> infoSqDasaRecoleta(List<Informacao> listInfoRecoleta, String strDbName) {

    Session session = null;
    Transaction tx;/*  ww  w. j a  v  a2  s  .co  m*/

    try {
        session = SessionFactoriByDBName.getCurrentSession4FacesByDbName(strDbName);
        tx = session.beginTransaction();

        Query q = session.getNamedQuery("NaRequisicao.Recoleta");

        List result = q.list();
        tx.commit();

        if (result != null && !result.isEmpty()) {
            for (int i = 0; i < result.size(); i++) {

                Informacao recoleta = new Informacao();
                Object[] tupla = (Object[]) result.get(i);

                if (tupla[0] != null) {
                    recoleta.setRequisicao(((Integer) tupla[0]).toString());
                }

                if (tupla[1] != null) {
                    recoleta.setMotivo(IOUtils.convertRTF_to_String(new String((byte[]) tupla[1])));
                }

                recoleta.setDtEntrega((Date) tupla[2]);
                recoleta.setNomeFuncionario((String) tupla[3]);
                recoleta.setCpfFuncionario((String) tupla[4]);
                recoleta.setNomeCliente((String) tupla[5]);

                if (tupla[6] != null && !tupla[6].equals("")) {
                    recoleta.setDtNascimento(
                            DateManipulador.formatDateToPattern("yyyy-MM-dd", (String) tupla[6]));
                }
                recoleta.setFato((String) tupla[7]);
                recoleta.setTelefone((String) tupla[8]);
                recoleta.setOrigemEmenda((String) tupla[9]);
                recoleta.setLocal((String) tupla[10]);
                recoleta.setTipoEmenda((String) tupla[11]);
                recoleta.setCentroCusto((String) tupla[12]);
                recoleta.setFatoNivel1((String) tupla[13]);
                recoleta.setFatoNivel2((String) tupla[14]);
                recoleta.setFatoNivel3((String) tupla[15]);

                recoleta.setExame((String) tupla[17]);

                listInfoRecoleta.add(recoleta);
            }
        }

    } finally {
        if (session != null && session.isOpen()) {
            session.close();
        }
    }

    return listInfoRecoleta;
}

From source file:br.com.livraria.dao.AutorDAO.java

public List<Autor> listar() {
    Session sessao = HibernateUtil.getSessionFactory().openSession();
    List<Autor> autores = null;

    try {//ww  w .  j a  v a  2 s . c  om
        Query consulta = sessao.getNamedQuery("Autor.listar");
        autores = consulta.list();

    } catch (RuntimeException ex) {
        throw ex;
    } finally {
        sessao.close();
    }
    return autores;

}

From source file:br.com.livraria.dao.AutorDAO.java

public Autor buscarPorCodigo(Long codigo) {
    Session sessao = HibernateUtil.getSessionFactory().openSession();
    Autor autor = null;/* w w w  .j  a v  a  2 s  . c  o m*/

    try {
        Query consulta = sessao.getNamedQuery("Autor.buscarPorCodigo");
        consulta.setLong("codigo", codigo);

        autor = (Autor) consulta.uniqueResult();
    } catch (RuntimeException ex) {
        throw ex;
    } finally {
        sessao.close();
    }
    return autor;
}

From source file:br.com.livraria.dao.FuncionarioDAO.java

public List<Funcionario> listar() {
    Session sessao = HibernateUtil.getSessionFactory().openSession();
    List<Funcionario> funcionarios = null;

    try {//from  ww w . j a v a  2  s. c  om
        Query consulta = sessao.getNamedQuery("Funcionario.listar");
        funcionarios = consulta.list();
    } catch (RuntimeException ex) {
        throw ex;
    } finally {
        sessao.close();
    }
    return funcionarios;
}

From source file:br.com.livraria.dao.FuncionarioDAO.java

public Funcionario buscarPorCodigo(Long codigo) {
    Session sessao = HibernateUtil.getSessionFactory().openSession();
    Funcionario funcionario = null;/* w  w  w  .j  av  a 2  s  . co  m*/

    try {
        Query consulta = sessao.getNamedQuery("Funcionario.buscarPorCodigo");
        consulta.setLong("codigo", codigo);

        funcionario = (Funcionario) consulta.uniqueResult();
    } catch (RuntimeException ex) {
        throw ex;
    } finally {
        sessao.close();
    }
    return funcionario;
}

From source file:br.com.livraria.dao.FuncionarioDAO.java

public Funcionario autenticar(String cpf, String senha) {
    Session sessao = HibernateUtil.getSessionFactory().openSession();
    Funcionario funcionario = null;/*from   w w  w.  j  av  a 2 s  .co m*/

    try {
        Query consulta = sessao.getNamedQuery("Funcionario.autenticar");
        consulta.setString("CPF", cpf);
        consulta.setString("Senha", senha);
    } catch (RuntimeException ex) {
        throw ex;
    } finally {
        sessao.close();
    }
    return funcionario;

}

From source file:br.com.livraria.dao.ItemDAO.java

public List<Item> listar() {
    Session sessao = HibernateUtil.getSessionFactory().openSession();
    List<Item> itens = null;

    try {/*from  w w w.  jav  a  2 s.com*/
        Query consulta = sessao.getNamedQuery("Item.listar");
        itens = consulta.list();
    } catch (RuntimeException ex) {
        throw ex;
    } finally {
        sessao.close();
    }
    return itens;
}

From source file:br.com.livraria.dao.ItemDAO.java

public Item buscarPorCodigo(Long codigo) {
    Session sessao = HibernateUtil.getSessionFactory().openSession();
    Item item = null;/* w  w w . ja v a  2s  . co  m*/

    try {

        Query consulta = sessao.getNamedQuery("Item.buscarPorCodigo");
        consulta.setLong("codigo", codigo);
        item = (Item) consulta.uniqueResult();
    } catch (RuntimeException ex) {
        throw ex;
    } finally {
        sessao.close();
    }
    return item;
}