コード例 #1
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;
  }
コード例 #2
0
  @SuppressWarnings({"rawtypes", "unchecked"})
  public Collection pesquisar(Collection ids, Filtro filtro, String pacoteNomeObjeto)
      throws ErroRepositorioException {
    Collection retorno = null;
    Session session = HibernateUtil.getSession();

    try {
      retorno =
          new ArrayList(
              new CopyOnWriteArraySet(
                  session
                      .createQuery("from " + pacoteNomeObjeto + " where id IN (:ids)")
                      .setParameterList("ids", ids)
                      .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;
  }