コード例 #1
0
ファイル: EntityConverter.java プロジェクト: huds8n/clinica
  @Override
  public Object getAsObject(FacesContext facesContext, UIComponent component, String string) {
    if (string == null || string.isEmpty()) return null;

    try {
      session = HibernateUtil.getSessionFactory().openSession();
      String[] values = string.split("-");
      return session.get(Class.forName(values[0]), Long.valueOf(values[1]));
    } catch (Exception e) {
      logger.error("Erro ao converter String em entidade", e);
      return null;
    } finally {
      session.close();
    }
  }
コード例 #2
0
  public void excluir(Linha lin) throws Exception, SQLException {
    Session sessao = null;
    try {
      sessao = dao.HibernateUtil.getSessionFactory().openSession();
      sessao.beginTransaction();

      sessao.delete(lin);

      sessao.getTransaction().commit();
    } catch (HibernateException he) {
      sessao.getTransaction().rollback();
    } finally {
      if (sessao != null) {
        sessao.close();
      }
    }
  }
コード例 #3
0
  public List listarLinhas() throws Exception, SQLException {
    Session sessao = null;
    List<Linha> lista = null;
    try {
      sessao = dao.HibernateUtil.getSessionFactory().openSession();
      sessao.beginTransaction();

      // Usando HQL
      Query consulta = sessao.createQuery("from Linha");
      lista = consulta.list();

      sessao.getTransaction().commit();

    } catch (HibernateException he) {
      sessao.getTransaction().rollback();
    } finally {
      if (sessao != null) {
        sessao.close();
      }
      return lista;
    }
  }
コード例 #4
0
  public List pesquisar(String pesqNome) throws Exception, SQLException {
    Session sessao = null;
    List lista = null;
    try {
      sessao = dao.HibernateUtil.getSessionFactory().openSession();
      sessao.beginTransaction();

      // Usando HQL
      Query consulta =
          sessao.createQuery("from Linha lin where lin.nome LIKE '%" + pesqNome + "%' ");
      lista = consulta.list();

      sessao.getTransaction().commit();

    } catch (HibernateException he) {
      sessao.getTransaction().rollback();
    } finally {
      if (sessao != null) {
        sessao.close();
      }
      return lista;
    }
  }