I'm having a question about how to improve perfomance
when generating a table on a page using components JSF
and Primefaces
.
I am generating a table, after doing a SQL query and mapping the object using Hibernate
, more specifically, creating a list of objects using ResultTransformer
interface.
I realize that this is OK, doing TDD, when calling the data the processing is fast.
But it has locked the page when it will generate it.
The page code looks like this:
<c:if test="#{bean.pojo.relatorioExtratoLojista != null}">
<c:forEach var="loja" items="#{bean.buscarLojas()}">
<c:forEach var="filial" items="#{bean.buscarFilial(loja)}">
<c:forEach var="atendente" items="#{bean.buscarAtendente(filial)}">
<c:forEach var="propostaStatus" items="#{bean.buscarPropostaStatus(atendente)}">
<p:panelGrid
styleClass="panelGridCenter gridNoBackground"
style="width: 100%; white-space:nowrap;">
<f:facet name="header">
// colunas do cabeçalho
</f:facet>
<c:forEach var="propostaCartao" items="#{bean.buscarPropostasCartao(atendente, propostaStatus)}" varStatus="propostaCartaoVarStatus">
// dados da tabela
</c:forEach>
</p:panelGrid>
<br/>
</c:forEach>
</c:forEach>
</c:forEach>
</c:forEach>
Where I put // colunas do cabeçalho
the table header is generated, and the comment // dados da tabela
has the table data.
The structure is this:
Map<Loja, Map<Filial, Map<Atendente, Map<PropostaStatus, List<PropostaCartao>>>>> mapLoja
Some of the methods of the bean are:
public List<Loja> buscarLojas() {
return new ArrayList<Loja>(this.getPojo().getRelatorioExtratoLojista().keySet());
}
public List<Filial> buscarFilial(Loja loja) {
Map<Filial, Map<Atendente, Map<PropostaStatus, List<PropostaCartao>>>> mapFilial = this.getPojo().getRelatorioExtratoLojista().get(loja);
return new ArrayList<Filial>(mapFilial.keySet());
}
public List<Atendente> buscarAtendente(Filial filial) {
Map<Atendente, Map<PropostaStatus, List<PropostaCartao>>> mapAtendente = this.getPojo().getRelatorioExtratoLojista().
get(filial.getLoja()).get(filial);
return new ArrayList<Atendente>(mapAtendente.keySet());
}
public List<PropostaStatus> buscarPropostaStatus(Atendente atendente) {
Map<Filial, Map<Atendente, Map<PropostaStatus, List<PropostaCartao>>>> mapFilial = this.getPojo().getRelatorioExtratoLojista().get(atendente.getLoja());
Map<Atendente, Map<PropostaStatus, List<PropostaCartao>>> mapAtendente = mapFilial.get(atendente.getFilial());
Map<PropostaStatus, List<PropostaCartao>> mapPropostaStatus = mapAtendente.get(atendente);
if (NullUtil.isNull(mapPropostaStatus.keySet())) {
toString();
}
return new ArrayList<PropostaStatus>(mapPropostaStatus.keySet());
}
public List<PropostaCartao> buscarPropostasCartao(Atendente atendente, PropostaStatus propostaStatus) {
Map<Filial, Map<Atendente, Map<PropostaStatus, List<PropostaCartao>>>> mapFilial = this.getPojo().getRelatorioExtratoLojista().get(atendente.getLoja());
Map<Atendente, Map<PropostaStatus, List<PropostaCartao>>> mapAtendente = mapFilial.get(atendente.getFilial());
Map<PropostaStatus, List<PropostaCartao>> mapPropostaStatus = mapAtendente.get(atendente);
return new ArrayList<PropostaCartao>(mapPropostaStatus.get(propostaStatus));
}
When I put it to debugar
in bean
, I realized that the buscarLojas()
method is called many times, apparently more than it should.
I'd like to know what I can do to improve performance, since I've re-set query
to just decrease the amount of data.