You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xindice-users@xml.apache.org by Simon Farrow <S....@umist.ac.uk> on 2003/03/20 00:51:13 UTC

Re: Creating collections with embedded Xindice

I've been trying to use the code below to create collections. It works but in a
slightly odd way. The first time I use it I get an exception thrown "Unable to
create collection". However, the next time it is used it's fine, why is this and
can I fix it?

The first time I'm using it is also the first time that the db directory is
created. I want to do all of the start of day stuff at once. Look for a
container if you get a null go and create it, job done.

At the moment I'm in the situation that you have to assume that the code is
going to fail the first test. Not ideal.

The guilty line is: service.createCollection(collectionName);

Thanks,

Simon

On Mon, 2003-02-24 at 15:34, David J. Thomson wrote:
Here's how you create an embedded collection:
> 
> 
> Collection col = null;
>       try {
>          String driver =
> "org.apache.xindice.client.xmldb.embed.DatabaseImpl";
> 
>          Class c = Class.forName(driver);
> 
>          Database database = (Database) c.newInstance();
>          DatabaseManager.registerDatabase(database);
> 
> 	    col =
> DatabaseManager.getCollection("xmldb:xindice-embed:///db/");
> 
>          String collectionName = "suprasphere";
>          CollectionManagementService service =
>             (CollectionManagementService)
> col.getService("CollectionManagementService", "1.0");
> 
>          // Build up the Collection XML configuration.
> 
> 	 service.createCollection(collectionName);
> 
>          System.out.println("Collection " + collectionName + " created.");
>       }
>       catch (XMLDBException e) {
>          System.err.println("XML:DB Exception occured " + e.errorCode);
>       }
>       catch (ClassNotFoundException cnfe) {
> 	      System.err.println("cnfe");
>       }
>       catch (InstantiationException ie) {
> 	      System.err.println("ie");
>       }
>       catch (IllegalAccessException iae) {
> 	      System.err.println("iae");
>       }
>       finally {
> 
>          if (col != null) {
> 		 try {
>             col.close();
> 	    }
>       catch (XMLDBException e) {
>          System.err.println("XML:DB Exception occured in closing" +
> e.errorCode);
>       }
>          }
>       }
> 
> 

Re: Creating collections with embedded Xindice

Posted by "David J. Thomson" <dt...@eecs.tufts.edu>.
Yes, I always get this exception too. It's not ideal, but it's also not a
significant problem. It's more confusing than anything, as sometimes I
forget that it's going to happen, and wonder what's going on. :)

Dave