xml-xindice-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From christophe reiss <christophe.re...@free.fr>
Subject problem with collection creation and index creation in the same run (embed)
Date Fri, 30 Apr 2004 07:30:06 GMT
Hi all (sorry if you receive this message for the second time, it is still not 
in archives ???!!!), 

I have an issue regarding collection creation and index creation within a same 
run, using 
embedded mode. I provide the code of a simple app that points the issue.

I use build 1.1b4, and the issue is present both on Linux and Windows XP with 
java 1.4.2_03

The application opens an embedded database, then creates a collection at root 
level, then 
creates an indexer in this newly created collection, then exits.

The first time I launch the app (run 0), traces are :

...
 xindice logs
...
xmldb:xindice-embed:///db/exampleColl is not defined, creating it !!!
...
 xindice logs
...
creating indexer toto
...
 xindice logs
...

After execution, in . db is present, as well as db/exampleColl, and toto.idx 
is actually created in db/exampleColl

When I restart the application (run 1), traces are : 

...
 xindice logs
...
creating indexer toto
...
 xindice logs
...

Thus, in run 1, indexer has been re-created... Is this expected ??????

When I restart application (run 2), traces are :

...
 xindice logs
...
indexer toto is already present
...
 xindice logs
...

which is correct.

Thus, in this case I need 2 runs to ensure that indexer is actually created... 
What worries me is that I'm not sure that, if in run0 I add documents in 
collection and index them with the index, those information will be actually 
recorded in database.

Note that, if I comment the index creation in run 0, I only create the 
collection.
If I remove the comment for run 1, the indexer is created, and in run 2 the 
application detects the newly created index correctly. 
There seems to be something with index creation flush, or am I missing 
something ?

thanks for your support,

Christophe.





package xindicex;

import org.xmldb.api.*;
import org.xmldb.api.base.*;
import org.xmldb.common.*;
import org.xmldb.xupdate.*;
import org.apache.xindice.client.xmldb.embed.DatabaseImpl;
import org.apache.xindice.client.xmldb.services.CollectionManager;
import org.apache.xindice.xml.dom.DOMParser;
import org.apache.xindice.util.*;

import org.apache.xindice.xml.dom.DocumentImpl;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

import java.util.Hashtable;
import java.util.Enumeration;

public class example {

  public  static void main(String[] argv) {

    // Simple app : creates an embedded database or retrieves it, creates
    // a "exampleColl" collection at root level or retrieves it if it is 
already present,
    // creates an indexer "toto" in "exampleColl" or retrieves it if it is 
already present.
    Collection colroot = null;
    Collection coll = null;
    Database db;
    try {
      String driver = "org.apache.xindice.client.xmldb.embed.DatabaseImpl";
      Class c = null;

      c = Class.forName(driver);

      db = (Database) c.newInstance();
      //use default system.xml...

      DatabaseManager.registerDatabase(db);

      String uri = "xmldb:xindice-embed:///db/";
      colroot = DatabaseManager.getCollection(uri);

      // create or retrieve exampleColl
      String curr = uri + "exampleColl" + "/";
      coll = DatabaseManager.getCollection(curr);
      if (coll == null) {
        System.out.println(curr + " is not defined, creating it !!!");
        CollectionManager service =
            (CollectionManager) colroot.getService("CollectionManager", "1.0");
        // Build up the Collection XML configuration.
        String collectionConfig =
            "<collection compressed=\"true\" " +
            "            name=\"" + "exampleColl" + "\">" +
            "   <filer class=\"org.apache.xindice.core.filer.BTreeFiler\"/>" +
            "</collection>";

        coll = service.createCollection("exampleColl",
                                        DOMParser.toDocument(
            collectionConfig));
      }
      // create or retrieve indexer toto

      CollectionManager cm = (CollectionManager) coll.getService(
          "CollectionManager", "1.0");
      // check if indexer exists
      String[] idxrs = cm.listIndexers();
      for (int i = 0; i < idxrs.length; i++) {
        if (idxrs[i].equals("toto")) {
          System.out.println("indexer toto already present ");
          return;
        }
      }
      System.out.println("creating indexer toto ");
      Document doc = new DocumentImpl();
      Element elt = doc.createElement("index");
      elt.setAttribute("class", "org.apache.xindice.core.indexer.NameIndexer");
      elt.setAttribute("name", "toto");
      elt.setAttribute("pattern", "titi");
      doc.appendChild(elt);
      cm.createIndexer(doc);
    }
    catch (XindiceException ex) {
      System.out.println("init error : " + ex.getMessage());
    }
    catch (IllegalAccessException ex) {
      System.out.println("init error : " + ex.getMessage());
    }
    catch (InstantiationException ex) {
      System.out.println("init error : " + ex.getMessage());
    }
    catch (XMLDBException ex) {
      System.out.println("init error : " + ex.getMessage());
    }
    catch (ClassNotFoundException ex) {
      System.out.println("init error : " + ex.getMessage());
    }

    finally {

      if (coll != null) {
        try {
          coll.close();
        }
        catch (XMLDBException ex1) {
        }
      }
      if (colroot != null) {
        try {
          colroot.close();
        }
        catch (XMLDBException ex2) {
        }
      }
    }
  }

}


Mime
View raw message