Deleting XML resource from eXist new eXist libraries.

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Deleting XML resource from eXist new eXist libraries.

Claudio Delgado
Deleting XML resource from eXist new eXist libraries.

All,

We are testing eXist with OPS and we had problems deleting XML Resources from eXists with the eXists new libraries (distributed as product-build=20060316), we have realized that the eXists libraries provided with OPS have a different behavior that the new eXists libraries having an inconsistent in this OPS code:

XMLDBProcessor.java

  protected void delete(PipelineContext pipelineContext, Datasource datasource, String collectionName, boolean createCollection, String resourceId, String query, Map namespaceContext) {

        ensureDriverRegistered(pipelineContext, datasource);

        try {

            // Execute query

            ResourceSet result = executeQuery(pipelineContext, datasource, collectionName, createCollection, resourceId, query, namespaceContext);

            // Delete resources based on query result

            for (ResourceIterator i = result.getIterator(); i.hasMoreResources();) {

                Resource resource = i.nextResource();

                resource.getParentCollection().removeResource(resource); //************************ This line has problems

            }

        } catch (XMLDBException e) {

            throw new OXFException(e);

        }

    }

The problem occurs when a collection is nested within another collection for example:  A/B/someXML.xml; collection B is in Collection A and B has an XML (someXML.xml, the resource).

The method: resource.getParentCollection() works ok with the older library (distributed with OPS), it returns the collection B, but with the eXists new libraries it returns the Root collection, in this case A producing the undesired result when this line is called:

resource.getParentCollection().removeResource(resource);  //The resource is not deleted because the resource for deletion is A/someXML.xml instead A/B/someXML.xml.


This inconsistence could be cached well (We think J ), doing the following modification to the OPS source code:

 

protected void delete(PipelineContext pipelineContext, Datasource datasource, String collectionName, boolean createCollection, String resourceId, String query, Map namespaceContext) {

        ensureDriverRegistered(pipelineContext, datasource);

        try {

            // Execute query

            ResourceSet result = executeQuery(pipelineContext, datasource, collectionName, createCollection, resourceId, query, namespaceContext);

            Collection collection = getCollection(pipelineContext, datasource, collectionName); //Get the declared collection

           

            // Delete resources based on query result

            for (ResourceIterator i = result.getIterator(); i.hasMoreResources();) {

                Resource resource = i.nextResource();

                collection.removeResource(resource); // removes the Resource from the declared Collection.               

                //resource.getParentCollection().removeResource(resource);

            }

        } catch (XMLDBException e) {

            throw new OXFException(e);

        }

    }



Regards,

Claudio



--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: Deleting XML resource from eXist new eXist libraries.

Erik Bruchez
Administrator
Claudio,

Thanks for investigating this. Have you tried your change with the
version of eXist that comes with OPS, or does it work only with the
latest eXist but not older versions?

-Erik

Claudio Delgado wrote:

> All,
>
> We are testing eXist with OPS and we had problems deleting XML Resources
> from eXists with the eXist’s new libraries (distributed as
> product-build=20060316), we have realized that the eXist’s libraries
> provided with OPS have a different behavior that the new eXist’s
> libraries having an inconsistent in this OPS’ code:
>
> XMLDBProcessor.java
>
>   protected void delete(PipelineContext pipelineContext, Datasource
> datasource, String collectionName, boolean createCollection, String
> resourceId, String query, Map namespaceContext) {
>
>         ensureDriverRegistered(pipelineContext, datasource);
>
>         try {
>
>             // Execute query
>
>             ResourceSet result = executeQuery(pipelineContext,
> datasource, collectionName, createCollection, resourceId, query,
> namespaceContext);
>
>             // Delete resources based on query result
>
>             for (ResourceIterator i = result.getIterator();
> i.hasMoreResources();) {
>
>                 Resource resource = i.nextResource();
>
>                 resource.getParentCollection().removeResource(resource);
> //************************ This line has problems
>
>             }
>
>         } catch (XMLDBException e) {
>
>             throw new OXFException(e);
>
>         }
>
>     }
>
> The problem occurs when a collection is nested within another collection
> for example:  A/B/someXML.xml; collection B is in Collection A and B has
> an XML (someXML.xml, the resource).
>
> The method: resource.getParentCollection() works ok with the older
> library (distributed with OPS), it returns the collection “B”, but with
> the eXist’s new libraries it returns the Root collection, in this case
> “A” producing the undesired result when this line is called:
>
> resource.getParentCollection().removeResource(resource);  //The resource
> is not deleted because the resource for deletion is A/someXML.xml
> instead A/B/someXML.xml.
>
>
> This inconsistence could be cached well (We think J ), doing the
> following modification to the OPS’ source code:
>
>  
>
> protected void delete(PipelineContext pipelineContext, Datasource
> datasource, String collectionName, boolean createCollection, String
> resourceId, String query, Map namespaceContext) {
>
>         ensureDriverRegistered(pipelineContext, datasource);
>
>         try {
>
>             // Execute query
>
>             ResourceSet result = executeQuery(pipelineContext,
> datasource, collectionName, createCollection, resourceId, query,
> namespaceContext);
>
>             Collection collection = getCollection(pipelineContext,
> datasource, collectionName); //Get the declared collection
>
>            
>
>             // Delete resources based on query result
>
>             for (ResourceIterator i = result.getIterator();
> i.hasMoreResources();) {
>
>                 Resource resource = i.nextResource();
>
>                 collection.removeResource(resource); // removes the
> Resource from the declared Collection.              
>
>                 //resource.getParentCollection().removeResource(resource);
>
>             }
>
>         } catch (XMLDBException e) {
>
>             throw new OXFException(e);
>
>         }
>
>     }
>
>
>
> Regards,
>
> Claudio
>
>
> ------------------------------------------------------------------------
>
>
> --
> You receive this message as a subscriber of the [hidden email] mailing list.
> To unsubscribe: mailto:[hidden email]
> For general help: mailto:[hidden email]?subject=help
> ObjectWeb mailing lists service home page: http://www.objectweb.org/wws

--
Orbeon - XForms Everywhere:
http://www.orbeon.com/blog/



--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws