On Tuesday, January 29, 2002, at 07:51 AM, Joel Rosi-Schwartz wrote:

Well, I finally realized that the creation code I was using is copied directly from the dbXML Developers Guide 0.5 and that the API for theCollectionManager has a simpler createCollection()� method that takes only a name as the parameter and then creates a default collection. Using this method clears all of my problems.

I am still wondering about the original problem, however.� Is the Guide wrong, is the release broken or am I applying this wrongly? Is there more information on the usage of the collection configuration facility? Is this useful to pursue or is it best in general to stay with the default collection creation mechanism?


There are two services you can use to create collections, CollectionManager which is Xindice specific and CollectionManagementService that is part of the XML:DB API. They're both actually implemented by the same class and the simpler method that you're calling is part of CollectionManagementService.


CollectionManagementService just allows creation and deletion of collections, but not indexes or XMLObjects. In theory it should work for more then one database though. If you can get away with the limitations you should use this service.

CollectionManager is specific to Xindice and exposes all the other management functionality, plus different methods for creating and deleting collections. If you need more advanced functionality this is the only way to get it.

Thanks,
Joel
�

Joel Rosi-Schwartz wrote:

Hi,

I am moving from xmldb beta 4 to the current cvs Xindice 1.0rc1 and am having some problems with the creation of collections that I did not see previously. I am wondering whether something I am not aware of has changed or if there is now a bug in the system.

I am creating the new collections thus:

�private boolean createCollection(String name, String path) {
� System.err.println("createCollection " + name + " " + path);
� Collection col = myServer.getCollection(path);

�� if (col == null) return false;

�� try {
��� CollectionManager service = (CollectionManager) col.getService("CollectionManager", "1.0");


��� // Build up the Collection XML configuration.
��� String collectionConfig =
���� "<collection compressed=\"true\" name=\""
����� + name
����� + "\">"
����� + "�� <filer class=\"org.dbxml.core.filer.BTreeFiler\" gzip=\"true\
"/>"
����� + "</collection>";

��� service.createCollection(name, DOMParser.toDocument(collectionConfig)
);
��� service.createIndexer(name);

��� System.err.println("Collection " + name + " created.");
�� }
�� catch (XMLDBException e) {
��� System.err.println("XML:DB Exception occured " + e.errorCode);
��� return false;
�� }
�� catch (XindiceException e) {
��� System.err.println("XML:DB Exception occured " + e.getMessage());
��� return false;
�� }
� }
� finally {
�� myServer.closeCollection(col);
� }

� return true;
�}

When I try to add a new an exception if thrown:

XML:DB Exception occured 1
org.xmldb.api.base.XMLDBException: Collection No IndexManager
�at org.apache.xindice.core.FaultCodes.createXMLDBException(Unknown Source)
�at org.apache.xindice.client.xmldb.CollectionImpl.storeResource(Unknown Source)
�at com.xindice.proto.internal.core.internuncio.Mediator.addDocument(Mediator.
java:134)
�at com.xindice.proto.internal.core.internuncio.Mediator.addDocument(Mediator.
java:98)
�at com.xindice.proto.internal.core.internuncio.Mediator.main(Mediator.java:301)


I am using the following code to add the document:

�public boolean addDocument(DocumentDescriptor descriptor, boolean overwrite) {

� Collection col = myServer.getCollection(descriptor.getCollectionPath())
;

� if (col == null) {
�� String error =
��� "Collection \""
���� + descriptor.getCollectionPath()
���� + "\" not found, document \""
���� + descriptor.getName()
���� + "\" skipped";

�� System.out.println(error);
�� descriptor.setError(error);
�� return false;
� }

� try {
�� if (!overwrite) {
��� // This code also throws an exception, but I believe
��� // that it should simply return null
��� try {
���� Resource res = col.getResource(descriptor.getName());

���� if (res == null) {
����� System.out.println("Document \"" + descriptor.getName() + "\" skipped");
����� return true;
���� }
��� }
��� catch (XMLDBException ignore) {
��� }
�� }


�� XMLResource document = (XMLResource) col.createResource(descriptor.getName(), "XMLResource");
�� document.setContent(descriptor.getDocument());
�� // throws exception here
�� col.storeResource(document);
�� System.out.println("Document " + descriptor.getName() + " inserted");
� }
� catch (XMLDBException e) {
�� System.err.println("XML:DB Exception occured " + e.errorCode);
�� e.printStackTrace();
�� descriptor.setError("XML:DB Exception occured " + e.errorCode);
�� return false;
� }
� finally {
�� myServer.closeCollection(col);
� }


� return true;
�}


Any insights would be very appreciated.

Tia,
Joel
�
�


Kimbro Staken
XML Database Software, Consulting and Writing
http://www.xmldatabases.org/



Reply via email to