Paging with large amount of data

7

Thinking about performance, what is the best way to page a large amount of data?

I'm currently using a List<Produtos> , saving around 500 products in it, and using subList(min,max) , returns what I need. However, I think this is not the best solution and I would like to know other alternatives to this problem.

Edit

The idea is to maximize performance between unnecessary queries in the database, because the maximum pool of the database is 4.

    
asked by anonymous 27.04.2016 / 16:28

1 answer

8

I've had this problem, I've solved the algaworks tip:

public List<Produto> filtrados(FiltroProduto filtro) {
    Criteria criteria = criarCriteriaParaFiltro(filtro);

    criteria.setFirstResult(filtro.getPrimeiroRegistro());
    criteria.setMaxResults(filtro.getQuantidadeRegistros());

    if (filtro.isAscendente() && filtro.getPropriedadeOrdenacao() != null) {
        criteria.addOrder(Order.asc(filtro.getPropriedadeOrdenacao()));
    } else if (filtro.getPropriedadeOrdenacao() != null) {
        criteria.addOrder(Order.desc(filtro.getPropriedadeOrdenacao()));
    }

    return criteria.list();
}

Of course you can improve the filter.

link

    
03.05.2016 / 09:55