Jonathan Melhuish wrote:

Vadim Gritsenko wrote:

public void connect() throws RepositoryException {
try {
Class driver = Class.forName("org.apache.xindice.client.xmldb.embed.DatabaseImpl");



You are using embedded driver. This means, *database will be running within the JVM of this java program*.


Okay. I have xindice installed as a webapp under Tomcat. From the logs, it looks like Xindice is loading successfully with Tomcat. Does this mean that Xindice is "running in the same JVM"? So the embedded driver should work?


Not necessarily! If you have several webapps, one with Xindice, and one yours, they will be loaded using different ClassLoaders. This would make it impossible for embedded driver in managed mode in one webapp to access database mounted by XindiceServlet in another webapp.

It is possible to overcome this, you can move xindice and xmldb jars from the WEB-INF/lib to the tomcat's shared libraries. Then, all jar files will be loaded by same classloader, and embedded driver will work (I haven't tried, but it should work).



// initialize a new database, then register it globally
Database db = (Database) driver.newInstance();
db.setProperty("db-home","/home/jon/tomcat/webapps/xindice/WEB-INF");




Database, running within this JVM, will mount database files from the specified location.
IMPORTANT: You HAVE TO guarantee that no other process (no other JVM) accesses this database.


Am I right in thinking that the db-home that I have set is actually the default anyway? It's also not massively clear from the documentation I have read what this path is relative to (if it were not absolute).


IIRC, yes, it defaults to WEB-INF. You can simply remove this line.



db.setProperty("managed","true");



This means that driver will NOT start database automatically. You have to manually start the database, and manually manage database instance.


I'm not sure I actually want managed mode in that case, so I set it to false.


If you want your database started by XindiceServlet, you *do* want either managed driver (provided that you moved all jars as described above), or xmlrpc driver.


Presumably I can still use DatabaseManager if my database is not managed? (you can see why I get confused!)


Yes, you can always use DatabaseManager.


Also, could you just confirm that this property name is correct? It is copied from the UpgradeTo11EmbedNotes <http://wiki.apache.org/xindice/UpgradeTo11EmbedNotes?action=fullsearch&value=UpgradeTo11EmbedNotes&literal=1&case=1&context=40> Wiki page, but you refer to "PROP_XINDICE_MANAGED" in another post. I've been reading lots of the Javadocs today, but can't find a reference to the property names.


All property names are here (public static final String PROP_* and public static final String SYSPROP_*):
http://cvs.apache.org/viewcvs.cgi/xml-xindice/java/src/org/apache/xindice/client/xmldb/embed/DatabaseImpl.java?rev=1.26&view=auto
and here:
http://xml.apache.org/xindice/api/org/apache/xindice/client/xmldb/embed/DatabaseImpl.html




DatabaseManager.registerDatabase(db);
col = DatabaseManager.getCollection("xmldb:xindice-embed:///db/sne/");




Because you asked for managed mode, and you have not started the database, this method will return null.


Even with managed set to false, DatabaseManager.getCollection still returns null.


I think I understood your config now; and explained this situation above.

Vadim



Reply via email to