Fernando Eug�nio wrote:
Hi.
I'm trying to use index, but it takes the same time with the index than without it.
..
public Entidade consulta(Entidade e){
EntidadeCliente c = (EntidadeCliente)e; //EntidadeCliente is an entity
EntidadeCliente ent = new EntidadeCliente();
ent.setNome(consulta("//clientes/cliente[codCli = '" + c.getCodCli() + "']/nome/text()"));
ent.setCpf(consulta("//clientes/cliente[codCli = '" + c.getCodCli() + "']/cpf/text()"));
ent.setEndereco(consulta("//clientes/cliente[codCli = '" + c.getCodCli() + "']/endereco/text()"));
ent.setBairro(consulta("//clientes/cliente[codCli = '" + c.getCodCli() + "']/bairro/text()"));
ent.setCidade(consulta("//clientes/cliente[codCli = '" + c.getCodCli() + "']/cidade/text()"));
ent.setEstado(consulta("//clientes/cliente[codCli = '" + c.getCodCli() + "']/estado/text()"));
ent.setCodCli(Integer.parseInt((consulta("//clientes/cliente[codCli = '" + c.getCodCli() + "']/codCli/text()"))));
return ent;
}
Are those "//..." expressions the XPath queries you run? I'll assume that yes...
This is a sample of the xml file:
<clientes> <cliente> <nome>TESTE2</nome> <cpf>541844333</cpf> <endereco>Rua Fulano de Tal, 54</endereco> <bairro>Bauxita</bairro> <cidade>Ouro Preto</cidade> <estado>MG</estado> <codCli>325</codCli> </cliente> </clientes>
Am I doing something wrong?
I see several issues:
1. You use "//clientes/cliente" instead of "/clientes/cliente".
2. How many <cliente/> you have in a single <clientes/> file?
3. I see multiple repetitions of "//clientes/cliente[codCli = '" + c.getCodCli() + "']". It might be more efficient to query once and get result as DOM and obtain the rest of information from the DOM - depending on answer on question 2.
4. You should have Value index with pattern "codCli" - seems that you already have it. Usefulness of the index also depends on question 2.
Vadim
