xml-xindice-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simon Farrow <S.Far...@umist.ac.uk>
Subject Re: Creating collections with embedded Xindice
Date Wed, 19 Mar 2003 23:51:13 GMT
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);
>       }
>          }
>       }
> 
> 

Mime
View raw message