Пример #1
0
  @SuppressWarnings({"rawtypes", "unchecked"})
  public Collection limiteMaximoFiltroPesquisa(Filtro filtro, String pacoteNomeObjeto, int limite)
      throws ErroRepositorioException {
    Session session = HibernateUtil.getSession();

    Collection resultado = null;

    try {

      resultado =
          new ArrayList(
              new CopyOnWriteArraySet(
                  GeradorHQLCondicional.gerarCondicionalQuery(
                          filtro, "objeto", "from " + pacoteNomeObjeto + " as objeto", session)
                      .setMaxResults(limite)
                      .list()));

    } catch (HibernateException e) {
      e.printStackTrace();
      throw new ErroRepositorioException(e, "Erro no Hibernate");
    } finally {
      HibernateUtil.closeSession(session);
    }

    return resultado;
  }
Пример #2
0
  @SuppressWarnings({"rawtypes", "unchecked"})
  public Collection pesquisar(Filtro filtro, int pageOffset, String pacoteNomeObjeto)
      throws ErroRepositorioException {

    Collection retorno = null;

    Session session = HibernateUtil.getSession();

    try {

      retorno =
          new ArrayList(
              new CopyOnWriteArraySet(
                  GeradorHQLCondicional.gerarCondicionalQuery(
                          filtro, "objeto", "from " + pacoteNomeObjeto + " as objeto", session)
                      .setFirstResult(10 * pageOffset)
                      .setMaxResults(10)
                      .list()));

      if (!filtro.getColecaoCaminhosParaCarregamentoEntidades().isEmpty()) {
        PersistenciaUtil.processaObjetosParaCarregamento(
            filtro.getColecaoCaminhosParaCarregamentoEntidades(), retorno);
      }
      if (filtro.isInitializeLazy()) {
        inicializarPropriedadesLazies(retorno);
      }
    } catch (HibernateException e) {
      throw new ErroRepositorioException(e, "Erro no Hibernate");
    } finally {
      HibernateUtil.closeSession(session);
    }
    return retorno;
  }
Пример #3
0
  @SuppressWarnings({"rawtypes", "unchecked"})
  public Collection pesquisarGerencial(Filtro filtro, String pacoteNomeObjeto)
      throws ErroRepositorioException {
    Collection retorno = null;

    Session session = HibernateUtil.getSessionGerencial();

    try {
      retorno =
          new ArrayList(
              new CopyOnWriteArraySet(
                  GeradorHQLCondicional.gerarCondicionalQuery(
                          filtro, "objeto", "from " + pacoteNomeObjeto + " as objeto", session)
                      .list()));

      if (filtro.isInitializeLazy()) {
        inicializarPropriedadesLazies(retorno);
      }

    } catch (HibernateException e) {
      throw new ErroRepositorioException(e, "Erro no Hibernate");
    } finally {
      HibernateUtil.closeSession(session);
    }
    return retorno;
  }
Пример #4
0
  @SuppressWarnings({"rawtypes", "unchecked"})
  public int totalRegistrosPesquisa(Filtro filtro, String pacoteNomeObjeto)
      throws ErroRepositorioException {
    int retorno = 0;
    Session session = HibernateUtil.getSession();

    try {

      List camposOrderBy = new ArrayList();

      Collection caminhosParaCarregamentoEntidades = new TreeSet();

      camposOrderBy = filtro.getCamposOrderBy();

      caminhosParaCarregamentoEntidades = filtro.getColecaoCaminhosParaCarregamentoEntidades();

      filtro.limparCamposOrderBy();
      filtro.limparColecaoCaminhosParaCarregamentoEntidades();

      retorno =
          (Integer)
              GeradorHQLCondicional.gerarCondicionalQuery(
                      filtro,
                      "objeto",
                      "select count(distinct objeto.id) from " + pacoteNomeObjeto + " as objeto",
                      session)
                  .uniqueResult();

      filtro.setCampoOrderBy((String[]) camposOrderBy.toArray(new String[camposOrderBy.size()]));

      filtro.setColecaoCaminhosParaCarregamentoEntidades(caminhosParaCarregamentoEntidades);

    } catch (HibernateException e) {
      throw new ErroRepositorioException(e, "Erro no Hibernate");
    } finally {
      HibernateUtil.closeSession(session);
    }
    return retorno;
  }