I'm trying to use index, but it takes the same time with the index than without it.
Here are some methods that I'm using:
It creates the index file, but it isn't working.
index file (codCli_idx.idx): 6mb table file (Testando.tbl): 1.4mb . I think it's strange.
I'm using only one xml file.
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;
}
//method that creates the index
public void criaIndice(Collection collec, String nome, String pattern){
CollectionManager colman = null;
String[] idx = null;
try {
colman = (CollectionManager) collec.getService("CollectionManager", "1.0");
idx = colman.listIndexers();
} catch (XMLDBException e1) {
e1.printStackTrace();
}
boolean id = false;
for(int i = 0; i < idx.length; i++){
if (nome.equals(idx[i])){
id = true;
}
}System.out.println(idx.length); System.out.println(id);
if ((idx.length < 1) || (id == false)) {
System.out.println("initializeXMLDB - Creating indexer");
String document = "<index class='org.apache.xindice.core.indexer.ValueIndexer' name='" + nome + "' pattern='" + pattern + "' />";
try {
colman.createIndexer(DOMParser.toDocument(document));
} catch (XMLDBException e2) {
e2.printStackTrace();
} catch (XindiceException e2) {
e2.printStackTrace();
}
}
else{
System.out.println("initializeXMLDB - Indexes:\n");
for (int i = 0; i < idx.length; i++) {
System.out.println("initializeXMLDB - " + i + " - " + idx[i]);
}
System.out.println("initializeXMLDB - Total Indexes: " + idx.length);
}
}
public static void main(String args[]){
ClienteXML c = new ClienteXML();
c.criaIndice(c.col, "codCli_idx", "codCli"); //creating index
EntidadeCliente ent = new EntidadeCliente();
Entidade ent1; long lg1, lg2;
lg1 = System.currentTimeMillis();
System.out.println(lg1 + "\n");
/************************************************************************/
ent.setCodCli(6000); //setting the codCli (that will be used to index)
ent1 = c.consulta(ent);
/************************************************************************/
lg2 = System.currentTimeMillis();
System.out.println("\n" + lg2);
System.out.println("\n Time: " + (lg2 - lg1) + " ms");
System.out.println("\n Time: " + ((lg2 - lg1)/1000) + " s");
}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? Please, help me.
Thanks.
_________________________________________________________________ MSN Hotmail, o maior webmail do Brasil. http://www.hotmail.com
